anchor.diff:  
   value_test() ->
       Val1 = "the rain in spain falls mainly on the plane",
  -    LWWREG1 = [{Val1, riak_dt_vclock:fresh()}],
  -    LWWREG2 = new(),
  -    ?assertEqual([Val1], value(LWWREG1)),
  -    ?assertEqual([<<>>], value(LWWREG2)).
  +    MVREG1 = [{Val1, riak_dt_vclock:fresh()}],
  +    MVREG2 = new(),
  +    ?assertEqual([Val1], value(MVREG1)),
  +    ?assertEqual([<<>>], value(MVREG2)).
  +
  +%% Check if the merge_to function is working
  +merge_to_test() ->
  +    VC = riak_dt_vclock:fresh(),
  +    VCA0 = riak_dt_vclock:increment(actor0, VC),
  +    VCA1 = riak_dt_vclock:increment(actor1, VC),
  +    MVR = merge_to([{value0, VCA0}], [{value1, VCA1}]),
  +    io:format("IOFORMAT ~w ~n", [MVR]),
  +    ?assert(equal([{value1, VCA1}, {value0,VCA0}] , MVR)).
   
   basic_assign_test() ->
       MVR0 = new(),
  
positive.code:     NewVC = riak_dt_vclock:increment(Actor, MaxVC),
      NewVC.
  
  dominate_ts(_TS, _Actor, []) ->
      true;
  dominate_ts(TS, Actor, [H|T]) ->
  
negative.code:     VC2 = riak_dt_vclock:increment(actor0, VC1),
      {ok, MVR1} = update({assign, value0}, actor0, MVR0),
      ?assertEqual([{value0, VC1}], MVR1),
      {ok, MVR2} = update({assign, value1}, actor0, MVR1),
      ?assertEqual([{value1, VC2}], MVR2).
  
  %% Test if update with timestamp works
  update_assign_withts_test() ->
      MVR0 = new(),
      VC0 = riak_dt_vclock:fresh(),
      VC1 = riak_dt_vclock:increment(actor1, VC0),
      VC2 = riak_dt_vclock:increment(actor1, VC1),
      VC3 = riak_dt_vclock:increment(actor1, VC2),
      VC4 = riak_dt_vclock:increment(actor1, VC3),
      VC5 = riak_dt_vclock:increment(actor2, VC4),
      VC6 = riak_dt_vclock:increment(actor2, VC5),
      %% Update a MVR with a given timestamp will change its timestmap to that value.
      {ok, MVR1} = update({assign, value1, 2}, actor1, MVR0),
      ?assertEqual([{value1, VC2}], MVR1),
      %% Update a MVR with a timestamp smaller than its current one has no effect
      {ok, MVR2} = update({assign, value0, 1}, actor1, MVR1),
      ?assertEqual([{value1, VC2}], MVR2),
      %% Test again with higher timestamp for actor1
      {ok, MVR3} = update({assign, value2, 4}, actor1, MVR2),
      ?assertEqual([{value2, VC4}], MVR3),
      %% Test with another actor
      {ok, MVR4} = update({assign, value3, 2}, actor2, MVR3),
      ?assertEqual([{value3, VC6}], MVR4).
  
  %% Test if getMax function is working.
  get_max_test() ->
      VC0 = riak_dt_vclock:fresh(),
      VC1_1 = riak_dt_vclock:increment(actor1, VC0),
      VC1_2 = riak_dt_vclock:increment(actor1, VC1_1),
      VC1_3 = riak_dt_vclock:increment(actor2, VC1_2),
      VC2_2 = riak_dt_vclock:increment(actor2, VC1_1),
      VC2_3 = riak_dt_vclock:increment(actor2, VC2_2),
      FinalVC = riak_dt_vclock:increment(actor1, VC2_3),
      NewVC = getMax([VC1_3, VC2_3], []),
      ?assert(riak_dt_vclock:equal(NewVC, FinalVC)).
  
  %% Update a MVReg with two different actors. Check if both actors are kept in the vector clock. 
  update_diff_actor_test() ->
      MVR0 = new(),
      VC0 = riak_dt_vclock:fresh(),
      VC1 = riak_dt_vclock:increment(actor1, VC0),
      VC2 = riak_dt_vclock:increment(actor2, VC1),
      {ok, MVR1} = update({assign, value0}, actor0, MVR0),
      {ok, MVR2} = update({assign, value1}, actor1, MVR1),
      Value = value(MVR2),
      TS = value(timestamp, MVR2),
      ?assert(equal([value1], Value)),
      ?assert(equal([VC2], TS)).
  
  %% Test if propagate is properly working. Three cases are described below.
  propagate_test() ->
      MVRA1_0 = new(),
      VC0 = riak_dt_vclock:fresh(),
      VCA1 = riak_dt_vclock:increment(actor1, VC0),
      VCA2 = riak_dt_vclock:increment(actor2, VC0),
      {ok, MVRA1_1} = update({assign, value1}, actor1, MVRA1_0),
      %% Propagate a timestamp that is not compatible with the current ones
      {ok, MVRMerge1} = update({propagate, value2, VCA2}, nothing, MVRA1_1),
      ?assert(equal([value1, value2], value(MVRMerge1))),
      ?assert(equal([VCA1, VCA2], value(timestamp, MVRMerge1))),
      VCA12 = riak_dt_vclock:increment(actor2, VCA1),
      %% Propagate a timestamp that dominates all current ones
      {ok, MVRMerge2} = update({propagate, value2, VCA12}, nothing, MVRMerge1),
      ?assert(equal([value2], value(MVRMerge2))),
      ?assert(equal([VCA12], value(timestamp, MVRMerge2))),
      %% Propagate a timestamp that is dominated by the current one
      {ok, MVRMerge3} = update({propagate, value3, VCA1}, nothing, MVRMerge2),
      ?assert(equal([value2], value(MVRMerge3))),
      ?assert(equal([VCA12], value(timestamp, MVRMerge3))).
      
  %% Test if a diverged MVReg merges all timestamp after being updated.
  update_assign_diverge_test() ->
      VC0 = riak_dt_vclock:fresh(),
      VC1 = riak_dt_vclock:increment(actor1, VC0),
      VC2 = riak_dt_vclock:increment(actor2, VC1),
      %% This represents a MVReg that have two concurrent assignment (one propagated).
      MVR0 = [{value1, VC1}, {value2, VC2}],
      {ok, MVR1} = update({assign, value3}, actor1, MVR0),
      VC1_2 = riak_dt_vclock:increment(actor2, VC1),
      VC1_3 = riak_dt_vclock:increment(actor1, VC1_2),
      %% After updating, the MVReg should only have one vector clock, having the maximum count of actors from each vector clock.
      ?assert(equal([{value3, VC1_3}], MVR1)),
      {ok, MVR2} = update({assign, value3}, actor3, MVR0),
      VC1_4 = riak_dt_vclock:increment(actor3, VC1_2),
      [VC_MVR2|_] = value(timestamp, MVR2), 
      ?assert(riak_dt_vclock:equal(VC1_4, VC_MVR2)).
      
  
  %merge_test() ->
  %    LWW1 = {old_value, 3},
  %    LWW2 = {new_value, 4},
  %    ?assertEqual({<<>>, 0}, merge(new(), new())),
  %    ?assertEqual({new_value, 4}, merge(LWW1, LWW2)),
  %    ?assertEqual({new_value, 4}, merge(LWW2, LWW1)).
  
  equal_test() ->
      VC0 = riak_dt_vclock:fresh(),
      VC1 = riak_dt_vclock:increment(actor0, VC0),
      VC2 = riak_dt_vclock:increment(actor0, VC1),
      MVR1 = [{value1, VC1}],
      MVR2 = [{value1, VC1}],
      MVR3 = [{value1, VC2}],
      MVR4 = [{value2, VC1}],
      ?assertNot(equal(MVR1, MVR3)),
      ?assert(equal(MVR1, MVR2)),
      ?assertNot(equal(MVR4, MVR1)).
  
  roundtrip_bin_test() ->
  %    LWW = new(),
  %    {ok, LWW1} = update({assign, 2}, a1, LWW),
  %    {ok, LWW2} = update({assign, 4}, a2, LWW1),
  %    {ok, LWW3} = update({assign, 89}, a3, LWW2),
  %    {ok, LWW4} = update({assign, <<"this is a binary">>}, a4, LWW3),
  %    Bin = to_binary(LWW4),
  %    Decoded = from_binary(Bin),
  %    ?assert(equal(LWW4, Decoded)).
      ok.
  
  query_test() ->
      MVR = new(),
      VC0 = riak_dt_vclock:fresh(),
      VC1 = riak_dt_vclock:increment(actor0, VC0),
      {ok, MVR1} = update({assign, value}, actor0, MVR),
      ?assertEqual([VC1], value(timestamp, MVR1)).
  
  
  stat_test() ->
      LWW = new(),
      {ok, LWW1} = update({assign, <<"abcd">>}, 1, LWW),
      ?assertEqual([{value_size, 25}], stats(LWW)),
      ?assertEqual([{value_size, 40}], stats(LWW1)),
      ?assertEqual(40, stat(value_size, LWW1)),
      ?assertEqual(undefined, stat(actor_count, LWW1)).
  -endif.
  