-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
71 lines (45 loc) · 1.94 KB
/
tests.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import inject
from string_search_base import StringSearchBase
from naive_search import NaiveSearch
from rabin_karp_search import RabinKarpSearch
from knuth_morris_pratt_search import KMPSearch
from boyer_moore_search import BoyerMooreSearch
# inject search class realization
def config(binder):
binder.bind_to_constructor(StringSearchBase, lambda: BoyerMooreSearch())
inject.configure(config)
@inject.params(searcher=StringSearchBase)
def test_simple_not_found(searcher: StringSearchBase = None):
string = 'abcedf'
pattern = 'hjk'
assert searcher.search_pattern(string, pattern) == []
@inject.params(searcher=StringSearchBase)
def test_pattern_equal_string(searcher: StringSearchBase = None):
string = 'string'
pattern = 'string'
assert searcher.search_pattern(string, pattern) == [0]
@inject.params(searcher=StringSearchBase)
def test_string_consist_of_patterns(searcher: StringSearchBase = None):
string = 'aaaaaaa'
pattern = 'a'
assert searcher.search_pattern(string, pattern) == [0, 1, 2, 3, 4, 5, 6]
@inject.params(searcher=StringSearchBase)
def test_string_consist_of_double_pattern(searcher: StringSearchBase = None):
string = 'python python '
pattern = 'python '
assert searcher.search_pattern(string, pattern) == [0, 7]
@inject.params(searcher=StringSearchBase)
def test_many_random_positions(searcher: StringSearchBase = None):
string = '123567829230123042598238923'
pattern = '23'
assert searcher.search_pattern(string, pattern) == [1, 9, 13, 21, 25]
@inject.params(searcher=StringSearchBase)
def test_minimal_equal_pattern_and_string(searcher: StringSearchBase = None):
string = '@'
pattern = '@'
assert searcher.search_pattern(string, pattern) == [0]
@inject.params(searcher=StringSearchBase)
def test_minimal_not_equal_pattern_and_string(searcher: StringSearchBase = None):
string = '#'
pattern = '@'
assert searcher.search_pattern(string, pattern) == []