/** * Given: * <pre> * x: a 2 b 2 c 2 2 2 * </pre> * Expected: * <pre> * x-x (2 2) * x-x-x-x-x (2) * <pre> * TODO Godin: however would be better to receive only (2) */ @Test public void myTest() { CloneIndex index = createIndex(); Block[] fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2"); List<CloneGroup> result = detect(index, fileBlocks); print(result); assertEquals(2, result.size()); assertThat(result, hasCloneGroup(2, newClonePart("x", 5, 2), newClonePart("x", 6, 2))); assertThat(result, hasCloneGroup(1, newClonePart("x", 1, 1), newClonePart("x", 3, 1), newClonePart("x", 5, 1), newClonePart("x", 6, 1), newClonePart("x", 7, 1))); }
/** * Given: file without duplications * Expected: {@link Collections#EMPTY_LIST} (no need to construct suffix-tree) */ @Test public void noDuplications() { CloneIndex index = createIndex(); Block[] fileBlocks = newBlocks("a", "1 2 3"); List<CloneGroup> result = detect(index, fileBlocks); assertThat(result, sameInstance(Collections.EMPTY_LIST)); }
/** * See SONAR-3060 * <p> * In case when file contains a lot of duplicated blocks suffix-tree works better than original algorithm, * which works more than 5 minutes for this example. * </p><p> * However should be noted that current implementation with suffix-tree also is not optimal, * even if it works for this example couple of seconds, * because duplications should be filtered in order to remove fully-covered. * But such cases nearly never appear in real-world, so current implementation is acceptable for the moment. * </p> */ @Test public void huge() { CloneIndex index = createIndex(); Block[] fileBlocks = new Block[5000]; for (int i = 0; i < 5000; i++) { fileBlocks[i] = newBlock("x", new ByteArray("01"), i); } List<CloneGroup> result = detect(index, fileBlocks); assertEquals(1, result.size()); }
CloneIndex index = createIndex(); Block[] fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3"); List<CloneGroup> result = detect(index, fileBlocks); print(result); assertEquals(2, result.size()); newClonePart("x", 10, 4), newClonePart("x", 12, 4))); newClonePart("x", 1, 2), newClonePart("x", 4, 2), newClonePart("x", 7, 2), newClonePart("x", 10, 2), newClonePart("x", 12, 2), newClonePart("x", 14, 2)));
CloneIndex index = createIndex( newBlocks("b", "4 3 2"), newBlocks("c", "4 3 1") ); Block[] fileBlocks = newBlocks("a", "1 2 3 4"); List<CloneGroup> result = detect(index, fileBlocks); print(result); assertEquals(4, result.size()); newClonePart("a", 0, 1), newClonePart("c", 2, 1))); newClonePart("a", 1, 1), newClonePart("b", 2, 1))); newClonePart("a", 2, 1), newClonePart("b", 1, 1), newClonePart("c", 1, 1))); newClonePart("a", 3, 1), newClonePart("b", 0, 1), newClonePart("c", 0, 1)));