@Test public void testGenerateLocalDeleteString() throws IncorrectTraceException { int siteId = 0; TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId); merger.localInsert(insert(0, "abcd")); // remove "abcd" List<Operation> ops = merger.localDelete(delete(0, 4)); assertEquals(4, 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())); opg = ((TTFSequenceMessage) ops.get(1)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(1, opg.getOperation().getPosition()); assertEquals("[<0,6>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(2)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(2, opg.getOperation().getPosition()); assertEquals("[<0,7>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(3)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(3, 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()); }
@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()); }