コード例 #1
0
  @Test
  public void test_equals() {
    StringTextComparator baseCmp = StringTextComparator.IGNORE_WHITESPACE;
    RollingHashSequence<StringText> a =
        RollingHashSequence.wrap(new StringText("line0 \n line1 \n line2"), baseCmp, 1);
    RollingHashSequence<StringText> b =
        RollingHashSequence.wrap(new StringText("line0 \n line1 \n line2 \n line3"), baseCmp, 1);
    RollingHashSequenceComparator<StringText> cmp =
        new RollingHashSequenceComparator<StringText>(baseCmp);

    assertThat(cmp.equals(a, 0, b, 0)).isTrue();
    assertThat(cmp.equals(a, 1, b, 1)).isTrue();
    assertThat(cmp.equals(a, 2, b, 2)).isFalse();
  }
コード例 #2
0
  @Test
  public void test_hash() {
    StringText seq = new StringText("line0 \n line1 \n line2");
    StringTextComparator cmp = StringTextComparator.IGNORE_WHITESPACE;
    RollingHashSequence<StringText> seq2 = RollingHashSequence.wrap(seq, cmp, 1);
    RollingHashSequenceComparator<StringText> cmp2 =
        new RollingHashSequenceComparator<StringText>(cmp);

    assertThat(seq2.length()).isEqualTo(3);
    assertThat(cmp2.hash(seq2, 0)).isEqualTo(cmp.hash(seq, 0) * 31 + cmp.hash(seq, 1));
    assertThat(cmp2.hash(seq2, 1))
        .isEqualTo((cmp.hash(seq, 0) * 31 + cmp.hash(seq, 1)) * 31 + cmp.hash(seq, 2));
    assertThat(cmp2.hash(seq2, 2)).isEqualTo((cmp.hash(seq, 1) * 31 + cmp.hash(seq, 2)) * 31);
  }