use of org.sonar.duplications.block.Block in project sonarqube by SonarSource.
the class PackedMemoryCloneIndexTest method should_construct_blocks_with_normalized_hash.
/**
* When: query by a hash value.
* Expected: all blocks should have same hash, which presented in the form of the same object.
*/
@Test
public void should_construct_blocks_with_normalized_hash() {
index.insert(newBlock("a", 1));
index.insert(newBlock("b", 1));
index.insert(newBlock("c", 1));
ByteArray requestedHash = new ByteArray(1L);
Collection<Block> blocks = index.getBySequenceHash(requestedHash);
assertThat(blocks.size(), is(3));
for (Block block : blocks) {
assertThat(block.getBlockHash(), sameInstance(requestedHash));
}
}
use of org.sonar.duplications.block.Block in project sonarqube by SonarSource.
the class SuffixTreeCloneDetectionAlgorithmTest method myTest.
/**
* 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)));
}
use of org.sonar.duplications.block.Block in project sonarqube by SonarSource.
the class SuffixTreeCloneDetectionAlgorithmTest method myTest3.
/**
* This test and associated with it suffix-tree demonstrates that without check of origin in {@link Search}
* possible to construct {@link CloneGroup} with a wrong origin.
*
* Given:
* <pre>
* a: 1 2 3 4
* b: 4 3 2
* c: 4 3 1
* </pre>
* Expected:
* <pre>
* a-c (1)
* a-b (2)
* a-b-c (3)
* a-b-c (4)
* <pre>
*/
@Test
public void myTest3() {
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());
assertThat(result, hasCloneGroup(1, newClonePart("a", 0, 1), newClonePart("c", 2, 1)));
assertThat(result, hasCloneGroup(1, newClonePart("a", 1, 1), newClonePart("b", 2, 1)));
assertThat(result, hasCloneGroup(1, newClonePart("a", 2, 1), newClonePart("b", 1, 1), newClonePart("c", 1, 1)));
assertThat(result, hasCloneGroup(1, newClonePart("a", 3, 1), newClonePart("b", 0, 1), newClonePart("c", 0, 1)));
}
use of org.sonar.duplications.block.Block in project sonarqube by SonarSource.
the class PmdBlockChunkerTest method shouldBuildBlocks.
@Test
public void shouldBuildBlocks() {
TokensLine line1 = new TokensLine(0, 9, 1, Character.toString((char) 1));
TokensLine line2 = new TokensLine(10, 19, 2, Character.toString((char) 2));
TokensLine line3 = new TokensLine(20, 29, 3, Character.toString((char) 3));
List<Block> blocks = new PmdBlockChunker(2).chunk("resourceId", Arrays.asList(line1, line2, line3));
assertThat(blocks.size(), is(2));
Block block = blocks.get(0);
// assertThat(block.getLengthInUnits(), is(11));
assertThat(block.getStartLine(), is(1));
assertThat(block.getEndLine(), is(2));
assertThat(block.getBlockHash(), is(new ByteArray(1L * 31 + 2)));
block = blocks.get(1);
// assertThat(block.getLengthInUnits(), is(33));
assertThat(block.getStartLine(), is(2));
assertThat(block.getEndLine(), is(3));
assertThat(block.getBlockHash(), is(new ByteArray(2L * 31 + 3)));
}
use of org.sonar.duplications.block.Block in project sonarqube by SonarSource.
the class DetectorTestCase method exampleFromPaperWithModifiedResourceIds.
/**
* Given:
* <pre>
* a: 2 3 4 5
* b: 3 4
* c: 1 2 3 4 5 6
* </pre>
* Expected:
* <pre>
* c-a (2 3 4 5)
* c-a-b (3 4)
* </pre>
*/
@Test
public void exampleFromPaperWithModifiedResourceIds() {
CloneIndex cloneIndex = createIndex(newBlocks("a", "2 3 4 5"), newBlocks("b", "3 4"));
Block[] fileBlocks = newBlocks("c", "1 2 3 4 5 6");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
assertThat(clones.size(), is(2));
assertThat(clones, hasCloneGroup(4, newClonePart("c", 1, 4), newClonePart("a", 0, 4)));
assertThat(clones, hasCloneGroup(2, newClonePart("c", 2, 2), newClonePart("a", 1, 2), newClonePart("b", 0, 2)));
}
Aggregations