25 lines
1.4 KiB
Python
25 lines
1.4 KiB
Python
|
from unittest import TestCase
|
||
|
from benchmark.rabin_karp import rabin_karp_search
|
||
|
|
||
|
|
||
|
class Test_rabin_karp_search(TestCase):
|
||
|
# distances_true = {1: [0, 70, 54, 65, 28, 51, 66], 3: [1], 4: [0, 0, 0, 0, 0, 0, 1], 5: [71, 55, 66, 29, 52, 67]}
|
||
|
# distances_false = {1: [1, 0, 0, 0, 0, 0, 0], 3: [0], 4: [6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0]}
|
||
|
def test_rabin_karp_search_1(self):
|
||
|
assert rabin_karp_search(pat='', txt=']vzK<k') == []
|
||
|
|
||
|
# distances_true = {1: [43, 0, 35, 7, 61], 4: [0, 0, 0, 0, 1], 5: [62, 27, 69, 1], 2: [0], 3: [2]}
|
||
|
# distances_false = {1: [0, 1, 0, 0, 0], 4: [4, 3, 2, 1, 0], 5: [0, 0, 0, 0], 2: [53], 3: [0]}
|
||
|
def test_rabin_karp_search_2(self):
|
||
|
assert rabin_karp_search(pat='z+e', txt=':EQBa9M') == []
|
||
|
|
||
|
# distances_true = {1: [50, 61, 64, 66, 16, 14, 66], 4: [0, 0, 0, 0, 0, 0, 1], 5: [16, 13, 11, 93, 63, 11]}
|
||
|
# distances_false = {1: [0, 0, 0, 0, 0, 0, 0], 4: [6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0]}
|
||
|
def test_rabin_karp_search_3(self):
|
||
|
assert rabin_karp_search(pat='f)', txt='^E}QhXq_') == []
|
||
|
|
||
|
# distances_true = {1: [14, 24, 0, 29, 5, 70, 55], 4: [0, 0, 0, 0, 0, 0, 1], 5: [65, 89, 60, 84, 19, 34], 2: [1], 3: [0]}
|
||
|
# distances_false = {1: [0, 0, 1, 0, 0, 0, 0], 4: [6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0], 2: [0], 3: [1]}
|
||
|
def test_rabin_karp_search_4(self):
|
||
|
assert rabin_karp_search(pat='X', txt='J@X;Sw!') == [2]
|