anchor.diff:  %%      Ops: The list of operations to apply in causal order
   %%      TxId: The Id of the transaction requesting the snapshot
   %%      Output: A tuple. The first element is ok, the seond is the CRDT after appliying the operations,
  -%%      the third element is the smallest vectorclock that describes this snapshot,
  -%%      the fourth element is a boolean, it it is true it means that the returned snapshot contains
  +%%      the third element 1 minus the number of the operation with the smallest id not included in the snapshot,
  +%%      the fourth element is the smallest vectorclock that describes this snapshot,
  +%%      the fifth element is a boolean, it it is true it means that the returned snapshot contains
   %%      more operations than the one given as input, false otherwise.
  --spec materialize(type(), snapshot(),
  +-spec materialize(type(),
  +		  snapshot(),
   		  integer(),
   		  snapshot_time() | ignore,
   		  snapshot_time(),
  -		  [clocksi_payload()], txid() | ignore) -> {ok, snapshot(), integer(),
  -							    snapshot_time() | ignore, boolean()} | {error, reason()}.
  +		  [{integer(),clocksi_payload()}],
  +		  txid() | ignore) ->
  +			 {ok, snapshot(), integer(), snapshot_time() | ignore, boolean()} | {error, reason()}.
   materialize(Type, Snapshot, LastOp, SnapshotCommitTime, MinSnapshotTime, Ops, TxId) ->
       FirstId = case Ops of
   		  [] ->
  
positive.code: %%      Type: The type of the CRDT
  %%      OpList: Should be given initially as an empty list, this will accumulate
  %%      the operations to apply.
  %%      SnapshotCommitTime: The time used to describe the intitial state of the CRDT given in Snapshot
  %%      MinSnapshotTime: The threshold time given by the reading transaction
  %%      Ops: The list of operations to apply in causal order
  
negative.code:                                    vectorclock:from_list([{1,7}]), Ops, ignore),
      ?assertEqual({6, vectorclock:from_list([{1,4}])}, {crdt_pncounter:value(PNcounter4), CommitTime4}).
  
  %% This test tests when a a snapshot is generated that does not include all of the updates in the
  %% list of operations, precisely in the case where an operation is not taken, but the operations to
  %% the left and right of it in the list are taken.  When this snapshot is then used for a future
  %% read with a different timestamp, this missing value must be checked.
  materializer_missing_op_test() ->
      PNCounter = new(crdt_pncounter),
      ?assertEqual(0,crdt_pncounter:value(PNCounter)),
      Op1 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor1}},
                             commit_time = {1, 1}, txid = 1, snapshot_time=vectorclock:from_list([{1,1},{2,1}])},
      Op2 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor2}},
                             commit_time = {1, 2}, txid = 2, snapshot_time=vectorclock:from_list([{1,2},{2,1}])},
      Op3 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor3}},
                             commit_time = {2, 2}, txid = 3, snapshot_time=vectorclock:from_list([{1,1},{2,1}])},
      Op4 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor4}},
                             commit_time = {1, 3}, txid = 2, snapshot_time=vectorclock:from_list([{1,2},{2,1}])},
      Ops = [{4,Op4},{3,Op3},{2,Op2},{1,Op1}],
      {ok, PNCounter2, LastOp, CommitTime2, _SsSave} = materialize(crdt_pncounter,
  							    PNCounter, 0, ignore, vectorclock:from_list([{1,3},{2,1}]),
  							    Ops, ignore),
      ?assertEqual({3, vectorclock:from_list([{1,3},{2,1}])}, {crdt_pncounter:value(PNCounter2), CommitTime2}),
      {ok, PNCounter3, 4, CommitTime3, _SsSave} = materialize(crdt_pncounter,
  							    PNCounter2, LastOp, CommitTime2, vectorclock:from_list([{1,3},{2,2}]),
  							    Ops, ignore),
      ?assertEqual({4, vectorclock:from_list([{1,3},{2,2}])}, {crdt_pncounter:value(PNCounter3), CommitTime3}).
  
  %% This test tests the case when there are updates that only snapshots that contain entries from one of the DCs.
  %% This can happen for example if an update is commited before the DCs have been connected.
  %% It ensures that when we read using a snapshot with and without all the DCs we still include the correct updates.
  materializer_missing_dc_test() ->
      PNCounter = new(crdt_pncounter),
      ?assertEqual(0,crdt_pncounter:value(PNCounter)),
      Op1 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor1}},
                             commit_time = {1, 1}, txid = 1, snapshot_time=vectorclock:from_list([{1,1}])},
      Op2 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor2}},
                             commit_time = {1, 2}, txid = 2, snapshot_time=vectorclock:from_list([{1,2}])},
      Op3 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor3}},
                             commit_time = {2, 2}, txid = 3, snapshot_time=vectorclock:from_list([{2,1}])},
      Op4 = #clocksi_payload{key = abc, type = crdt_pncounter,
                             op_param = {update, {{increment,1}, actor4}},
                             commit_time = {1, 3}, txid = 2, snapshot_time=vectorclock:from_list([{1,2}])},
      Ops = [{4,Op4},{3,Op3},{2,Op2},{1,Op1}],
      
      {ok, PNCounterA, LastOpA, CommitTimeA, _SsSave} = materialize(crdt_pncounter,
  								  PNCounter, 0, ignore, vectorclock:from_list([{1,3}]),
  								  Ops, ignore),
      ?assertEqual({3, vectorclock:from_list([{1,3}])}, {crdt_pncounter:value(PNCounterA), CommitTimeA}),
      {ok, PNCounterB, 4, CommitTimeB, _SsSave} = materialize(crdt_pncounter,
  							    PNCounterA, LastOpA, CommitTimeA, vectorclock:from_list([{1,3},{2,2}]),
  							    Ops, ignore),
      ?assertEqual({4, vectorclock:from_list([{1,3},{2,2}])}, {crdt_pncounter:value(PNCounterB), CommitTimeB}),
      
      {ok, PNCounter2, LastOp, CommitTime2, _SsSave} = materialize(crdt_pncounter,
  								 PNCounter, 0, ignore, vectorclock:from_list([{1,3},{2,1}]),
  								 Ops, ignore),
      ?assertEqual({3, vectorclock:from_list([{1,3}])}, {crdt_pncounter:value(PNCounter2), CommitTime2}),
      {ok, PNCounter3, 4, CommitTime3, _SsSave} = materialize(crdt_pncounter,
  							    PNCounter2, LastOp, CommitTime2, vectorclock:from_list([{1,3},{2,2}]),
  							    Ops, ignore),
      ?assertEqual({4, vectorclock:from_list([{1,3},{2,2}])}, {crdt_pncounter:value(PNCounter3), CommitTime3}).
      
  materializer_clocksi_concurrent_test() ->
      PNCounter = new(crdt_pncounter),
      ?assertEqual(0,crdt_pncounter:value(PNCounter)),
  