@Test
  public void testVectorClockEvolution() throws IncorrectTraceException {
    int siteId = 0;
    TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId);
    assertEquals(vc(0), merger.getClock());

    OTMessage op1 =
        ((TTFSequenceMessage) merger.localInsert(insert(0, "a")).get(0)).getSoct2Message();
    assertEquals(vc(1), merger.getClock());

    OTMessage op2 =
        ((TTFSequenceMessage) merger.localInsert(insert(1, "b")).get(0)).getSoct2Message();
    assertEquals(vc(2), merger.getClock());

    assertEquals(vc(1), op1.getClock());
    assertEquals(vc(2), op2.getClock());
  }
  @Test
  public void testGenerateLocalDeleteStringWhichContainsDeletedChars()
      throws IncorrectTraceException {
    int siteId = 0;
    TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId);
    merger.localInsert(insert(0, "abcdefg"));

    merger.localDelete(delete(2, 2));
    assertEquals("abefg", merger.lookup());

    // remove "bef"
    List<Operation> ops = merger.localDelete(delete(1, 3));

    assertEquals(3, ops.size());
    OTMessage<TTFOperation> opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(1, opg.getOperation().getPosition());

    opg = ((TTFSequenceMessage) ops.get(1)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(4, opg.getOperation().getPosition());

    opg = ((TTFSequenceMessage) ops.get(2)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(5, opg.getOperation().getPosition());

    assertEquals("ag", merger.lookup());
  }
  @Test
  public void testGenerateLocalDeleteCharByChar() throws IncorrectTraceException {
    int siteId = 0;
    TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId);
    merger.localInsert(insert(0, "abcd"));

    // remove 'a'
    List<Operation> ops = merger.localDelete(delete(0, 1));
    assertEquals(1, ops.size());
    OTMessage<TTFOperation> opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(0, opg.getOperation().getPosition());
    assertEquals("[<0,5>]", vcToString(opg.getClock()));
    assertEquals("bcd", merger.lookup());

    // remove 'd'
    ops = merger.localDelete(delete(2, 1));
    assertEquals(1, ops.size());
    opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(3, opg.getOperation().getPosition());
    assertEquals("[<0,6>]", vcToString(opg.getClock()));
    assertEquals("bc", merger.lookup());

    // remove 'c'
    ops = merger.localDelete(delete(1, 1));
    assertEquals(1, ops.size());
    opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(2, opg.getOperation().getPosition());
    assertEquals("[<0,7>]", vcToString(opg.getClock()));
    assertEquals("b", merger.lookup());

    // remove 'b'
    ops = merger.localDelete(delete(0, 1));
    assertEquals(1, ops.size());
    opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message();
    assertEquals(OpType.delete, opg.getOperation().getType());
    assertEquals(1, opg.getOperation().getPosition());
    assertEquals("[<0,8>]", vcToString(opg.getClock()));
    assertEquals("", merger.lookup());
  }
  @Test
  public void testGenerateLocalInsertString() throws IncorrectTraceException {
    int siteId = 0;
    TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId);

    List<Operation> ops = merger.localInsert(insert(0, "abc"));
    assertEquals(3, ops.size());

    OTMessage<TTFOperation> opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message();
    assertEquals(OpType.insert, opg.getOperation().getType());
    assertEquals('a', opg.getOperation().getContent());
    assertEquals(0, opg.getOperation().getPosition());
    assertEquals("[<0,1>]", vcToString(opg.getClock()));

    opg = ((TTFSequenceMessage) ops.get(1)).getSoct2Message();
    assertEquals('b', opg.getOperation().getContent());
    assertEquals(1, opg.getOperation().getPosition());
    assertEquals("[<0,2>]", vcToString(opg.getClock()));

    opg = ((TTFSequenceMessage) ops.get(2)).getSoct2Message();
    assertEquals('c', opg.getOperation().getContent());
    assertEquals("[<0,3>]", vcToString(opg.getClock()));
    assertEquals(2, opg.getOperation().getPosition());

    assertEquals("abc", merger.lookup());
  }