Package org.sonar.duplications.index

Examples of org.sonar.duplications.index.CloneGroup


    print(clones);
    assertThat(clones.size(), is(1));
    Iterator<CloneGroup> clonesIterator = clones.iterator();

    CloneGroup clone = clonesIterator.next();
    assertThat(clone.getCloneUnitLength(), is(1));
    assertThat(clone.getCloneParts().size(), is(2));
    assertThat(clone.getOriginPart(), is(new ClonePart("a", 0, 0, 1)));
    assertThat(clone.getCloneParts(), hasItem(new ClonePart("a", 0, 0, 1)));
    assertThat(clone.getCloneParts(), hasItem(new ClonePart("a", 2, 0, 1)));
  }
View Full Code Here


    addToIndex(file);

    List<CloneGroup> duplications = detect(file);
    assertThat(duplications.size()).isEqualTo(1);

    CloneGroup duplication = duplications.get(0);
    assertThat(duplication.getOriginPart().getResourceId()).isEqualTo(file.getAbsolutePath());
    assertThat(duplication.getCloneParts().size()).isEqualTo(2);
    assertThat(duplication.getLengthInUnits()).as("length in tokens").isEqualTo(157);

    ClonePart part = duplication.getCloneParts().get(0);
    assertThat(part.getResourceId()).isEqualTo(file.getAbsolutePath());
    assertThat(part.getStartLine()).isEqualTo(30);
    assertThat(part.getEndLine()).isEqualTo(44);
  }
View Full Code Here

    addToIndex(file2);

    List<CloneGroup> duplications = detect(file1);
    assertThat(duplications.size()).isEqualTo(1);

    CloneGroup duplication = duplications.get(0);
    assertThat(duplication.getOriginPart().getResourceId()).isEqualTo(file1.getAbsolutePath());
    ClonePart part1 = new ClonePart(file1.getAbsolutePath(), 1, 18, 41);
    ClonePart part2 = new ClonePart(file2.getAbsolutePath(), 1, 18, 41);
    assertThat(duplication.getCloneParts()).containsOnly(part1, part2);
    assertThat(duplication.getLengthInUnits()).as("length in tokens").isEqualTo(115);
  }
View Full Code Here

   * reflexive - c1 in c1,
   * antisymmetric - c1 in c2, c2 in c1, because c1 = c2
   */
  @Test
  public void reflexive_and_antisymmetric() {
    CloneGroup c1 = newCloneGroup(1,
        newClonePart("a", 1));
    CloneGroup c2 = newCloneGroup(1,
        newClonePart("a", 1));

    assertThat(Filter.containsIn(c1, c1), is(true));
    assertThat(Filter.containsIn(c1, c2), is(true));
    assertThat(Filter.containsIn(c2, c1), is(true));
View Full Code Here

   * </pre>
   * Expected: c1 not in c2, c2 not in c1
   */
  @Test
  public void start_index_in_C1_less_than_in_C2() {
    CloneGroup c1 = newCloneGroup(1,
        newClonePart("a", 1));
    CloneGroup c2 = newCloneGroup(1,
        newClonePart("a", 2));

    assertThat(Filter.containsIn(c1, c2), is(false));
  }
View Full Code Here

   * </pre>
   */
  @Test
  public void one_part_of_C2_covers_two_parts_of_C1() {
    // Note that line numbers don't matter for method which we test.
    CloneGroup c1 = newCloneGroup(1,
        newClonePart("a", 0),
        newClonePart("a", 2),
        newClonePart("b", 0),
        newClonePart("b", 2));
    CloneGroup c2 = newCloneGroup(3,
        newClonePart("a", 0),
        newClonePart("b", 0));

    assertThat(Filter.containsIn(c1, c2), is(true));
    assertThat(Filter.containsIn(c2, c1), is(false));
View Full Code Here

   * c2 not in c1 (not all parts of c2 covered by parts of c1 and different resources)
   * </pre>
   */
  @Test
  public void different_resources() {
    CloneGroup c1 = newCloneGroup(1,
        newClonePart("a", 0),
        newClonePart("a", 2));
    CloneGroup c2 = newCloneGroup(3,
        newClonePart("a", 0),
        newClonePart("b", 0));

    assertThat(Filter.containsIn(c1, c2), is(false));
    assertThat(Filter.containsIn(c2, c1), is(false));
View Full Code Here

   * c2 not in c1
   * </pre>
   */
  @Test
  public void second_part_of_C2_covers_first_part_of_C1() {
    CloneGroup c1 = newCloneGroup(1,
        newClonePart("a", 2));
    CloneGroup c2 = newCloneGroup(2,
        newClonePart("a", 0),
        newClonePart("a", 2));

    assertThat(Filter.containsIn(c1, c2), is(true));
    assertThat(Filter.containsIn(c2, c1), is(false));
View Full Code Here

   * c1 not in c2
   * </pre>
   */
  @Test
  public void length_of_C1_bigger_than_length_of_C2() {
    CloneGroup c1 = spy(newCloneGroup(3,
        newClonePart("a", 0)));
    CloneGroup c2 = spy(newCloneGroup(1,
        newClonePart("a", 0)));

    assertThat(Filter.containsIn(c1, c2), is(false));
    // containsIn method should check only origin and length - no need to compare all parts
    verify(c1).getCloneUnitLength();
View Full Code Here

   * Running time - O(N*2*C), where N - number of clones, which was found earlier and C - time of {@link #containsIn(CloneGroup, CloneGroup)}.
   */
  public void add(CloneGroup current) {
    Iterator<CloneGroup> i = filtered.iterator();
    while (i.hasNext()) {
      CloneGroup earlier = i.next();
      // Note that following two conditions cannot be true together - proof by contradiction:
      // let C be the current clone and A and B were found earlier
      // then since relation is transitive - (A in C) and (C in B) => (A in B)
      // so A should be filtered earlier
      if (Filter.containsIn(current, earlier)) {
View Full Code Here

TOP

Related Classes of org.sonar.duplications.index.CloneGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.