-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings_test.py
127 lines (114 loc) · 7.49 KB
/
strings_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!python
from strings import contains, find_index, find_all_indexes
import unittest
class StringsTest(unittest.TestCase):
def test_contains_with_matching_patterns(self):
# Positive test cases (examples) with matching patterns
assert contains('abc', '') is True # all strings contain empty string
assert contains('abc', 'a') is True # single letters are easy
assert contains('abc', 'b') is True
assert contains('abc', 'c') is True
assert contains('abc', 'ab') is True # multiple letters are harder
assert contains('abc', 'bc') is True
assert contains('abc', 'abc') is True # all strings contain themselves
assert contains('aaa', 'a') is True # multiple occurrences
assert contains('aaa', 'aa') is True # overlapping pattern
assert contains('sodalite', 'soda') is True
assert contains('hydroxylherderite', 'h') is True
assert contains('hemimorphite', 'ite') is True
def test_contains_with_non_matching_patterns(self):
# Negative test cases (counterexamples) with non-matching patterns
assert contains('abc', 'z') is False # remember to test other letters
assert contains('abc', 'ac') is False # important to test close cases
assert contains('abc', 'az') is False # first letter, but not last
assert contains('abc', 'abz') is False # first 2 letters, but not last
assert contains('orthoclase', 'cle') is False
assert contains('fluorite', 'kgjalda') is False
assert contains('uranyl ion', 'uranya') is False
def test_contains_with_complex_patterns(self):
# Difficult test cases (examples) with complex patterns
assert contains('ababc', 'ab') is True # multiple occurrences
assert contains('banana', 'na') is True # multiple occurrences
assert contains('ababc', 'abc') is True # overlapping prefix
assert contains('bananas', 'nas') is True # overlapping prefix
assert contains('benitoite', 'it') is True
assert contains('corundum', 'u') is True
assert contains('haüyne', 'ü') is True
def test_find_index_with_matching_patterns(self):
# Positive test cases (examples) with matching patterns
assert find_index('abc', '') == 0 # all strings contain empty string
assert find_index('abc', 'a') == 0 # single letters are easy
assert find_index('abc', 'b') == 1
assert find_index('abc', 'c') == 2
assert find_index('abc', 'ab') == 0 # multiple letters are harder
assert find_index('abc', 'bc') == 1
assert find_index('abc', 'abc') == 0 # all strings contain themselves
assert find_index('aaa', 'a') == 0 # multiple occurrences
assert find_index('aaa', 'aa') == 0 # overlapping pattern
assert find_index('hanksite', 'ite') == 5
assert find_index('polylithionite', 'poly') == 0
assert find_index('plumbogummite', 'gum') == 6
def test_find_index_with_non_matching_patterns(self):
# Negative test cases (counterexamples) with non-matching patterns
assert find_index('abc', 'z') is None # remember to test other letters
assert find_index('abc', 'ac') is None # important to test close cases
assert find_index('abc', 'az') is None # first letter, but not last
assert find_index('abc', 'abz') is None # first 2 letters, but not last
assert find_index('quartz', 'quartasfjk') is None
assert find_index('sphalerite', '⬆️') is None
assert find_index('zircon', 'zircön') is None
def test_find_index_with_complex_patterns(self):
# Difficult test cases (examples) with complex patterns
assert find_index('ababc', 'abc') == 2 # overlapping prefix
assert find_index('bananas', 'nas') == 4 # overlapping prefix
assert find_index('abcabcabc', 'abc') == 0 # multiple occurrences
assert find_index('abcabcab', 'abc') == 0 # multiple occurrences
assert find_index('abcabcdef', 'abcd') == 3 # overlapping prefix
assert find_index('abcabcdef', 'abcdef') == 3 # overlapping prefix
assert find_index('abcabcdabcde', 'abcde') == 7 # overlapping prefix
assert find_index('abcabcdabcde', 'abcd') == 3 # multiple occurrences, overlapping prefix
assert find_index('abra cadabra', 'abra') == 0 # multiple occurrences
assert find_index('abra cadabra', 'adab') == 6 # overlapping prefix
assert find_index('abra cadabra', 'a c') == 3
assert find_index('willemite', 'l') == 2
assert find_index('leucophaniteleucophanite', 'euco') == 1
def test_find_all_indexes_with_matching_patterns(self):
# Positive test cases (examples) with matching patterns
assert find_all_indexes('abc', '') == [0, 1, 2] # all strings contain empty string
assert find_all_indexes('abc', 'a') == [0] # single letters are easy
assert find_all_indexes('abc', 'b') == [1]
assert find_all_indexes('abc', 'c') == [2]
assert find_all_indexes('abc', 'ab') == [0] # multiple letters are harder
assert find_all_indexes('abc', 'bc') == [1]
assert find_all_indexes('abc', 'abc') == [0] # all strings contain themselves
assert find_all_indexes('aaa', 'a') == [0, 1, 2] # multiple occurrences
assert find_all_indexes('aaa', 'aa') == [0, 1] # overlapping pattern
assert find_all_indexes('calcite calcium carbonate', 'ca') == [0, 8, 16]
assert find_all_indexes('🎢🎢🎢🎢🎢🎢🎢', '🎢') == [0, 1, 2, 3, 4, 5, 6]
assert find_all_indexes('johnbaumite, afghanite, howlite', 'ite') == [8, 19, 28]
def test_find_all_indexes_with_non_matching_patterns(self):
# Negative test cases (counterexamples) with non-matching patterns
assert find_all_indexes('abc', 'z') == [] # remember to test other letters
assert find_all_indexes('abc', 'ac') == [] # important to test close cases
assert find_all_indexes('abc', 'az') == [] # first letter, but not last
assert find_all_indexes('abc', 'abz') == [] # first 2 letters, but not last
assert find_all_indexes('tugtupite', 'fajlkgsd') == []
assert find_all_indexes('lorenzenite', 'asd') == []
assert find_all_indexes('hornblende', 'blendy') == []
def test_find_all_indexes_with_complex_patterns(self):
# Difficult test cases (examples) with complex patterns
assert find_all_indexes('ababc', 'abc') == [2] # overlapping prefix
assert find_all_indexes('bananas', 'nas') == [4] # overlapping prefix
assert find_all_indexes('abcabcabc', 'abc') == [0, 3, 6] # multiple occurrences
assert find_all_indexes('abcabcab', 'abc') == [0, 3] # multiple occurrences
assert find_all_indexes('abcabcdef', 'abcd') == [3] # overlapping prefix
assert find_all_indexes('abcabcdef', 'abcdef') == [3] # overlapping prefix
assert find_all_indexes('abcabcdabcde', 'abcde') == [7] # overlapping prefix
assert find_all_indexes('abcabcdabcde', 'abcd') == [3, 7] # multiple occurrences, overlapping prefix
assert find_all_indexes('abra cadabra', 'abra') == [0, 8] # multiple occurrences
assert find_all_indexes('abra cadabra', 'adab') == [6] # overlapping prefix
assert find_all_indexes('marialiteꜯmeioniteꜯ', 'ꜯ') == [9, 18]
assert find_all_indexes('serpentineserpserpentine', 'serpentine') == [0, 14]
assert find_all_indexes('skorpioniteskorskorpioskorpio', 'skorpio') == [0, 15, 22]
if __name__ == '__main__':
unittest.main()