summaryrefslogtreecommitdiff
path: root/tests/hash_substringTest.py
blob: 4c8fd5c87795135015a375dc981ec6a4dfa60fe0 (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
import unittest

from sources.hash_substring import get_occurrences, rabin_karp


class MyTestCase(unittest.TestCase):

    def test1(self):
        result = get_occurrences('aba', 'abacaba')
        result = rabin_karp('aba', 'abacaba')
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0], 0)
        self.assertEqual(result[1], 4)

    def test2(self):
        result = get_occurrences('Test', 'testTesttesT')
        result = rabin_karp('Test', 'testTesttesT')
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0], 4)

    def test3(self):
        result = get_occurrences('aaaaa', 'baaaaaaa')
        result = rabin_karp('aaaaa', 'baaaaaaa')
        self.assertEqual(len(result), 3)
        self.assertEqual(result[0], 1)
        self.assertEqual(result[1], 2)
        self.assertEqual(result[2], 3)


if __name__ == '__main__':
    unittest.main()