summaryrefslogtreecommitdiff
path: root/src/test/HashSubstringTest.java
blob: 854b329611b7627d9a98c5240f5a22b755cdf444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class HashSubstringTest {
    @Test
    void test() {
        HashSubstring.Data data = new HashSubstring.Data("aba", "abacaba");
        assertEquals(2, HashSubstring.getOccurrences(data).size());
        assertEquals(0, HashSubstring.getOccurrences(data).get(0));
        assertEquals(4, HashSubstring.getOccurrences(data).get(1));

        List<Integer> postions = HashSubstring.rabinKarp("a", "ab");
        assertEquals(1, postions.size());
        assertEquals(0, postions.get(0));

        postions = HashSubstring.rabinKarp("a", "ba");
        assertEquals(1, postions.size());
        assertEquals(1, postions.get(0));

        postions = HashSubstring.rabinKarp("aba", "abacaba");
        assertEquals(2, postions.size());
        assertEquals(0, postions.get(0));
        assertEquals(4, postions.get(1));
    }

    @Test
    void test1() {
        HashSubstring.Data data = new HashSubstring.Data("Test", "testTesttesT");
        assertEquals(1, HashSubstring.getOccurrences(data).size());
        assertEquals(4, HashSubstring.getOccurrences(data).get(0));
        List<Integer> postions = HashSubstring.rabinKarp("Test", "testTesttesT");
        assertEquals(1, postions.size());
        assertEquals(4, postions.get(0));
    }

    @Test
    void test2() {
        HashSubstring.Data data = new HashSubstring.Data("aaaaa", "baaaaaaa");
        assertEquals(3, HashSubstring.getOccurrences(data).size());
        assertEquals(1, HashSubstring.getOccurrences(data).get(0));
        assertEquals(2, HashSubstring.getOccurrences(data).get(1));
        assertEquals(3, HashSubstring.getOccurrences(data).get(2));
        List<Integer> positions = HashSubstring.rabinKarp("aaaaa", "baaaaaaa");
        assertEquals(3, positions.size());
        assertEquals(1, positions.get(0));
        assertEquals(2, positions.get(1));
        assertEquals(3, positions.get(2));
    }
}