forked from laurentluce/python-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_string.py
More file actions
67 lines (52 loc) · 1.99 KB
/
Copy pathtest_string.py
File metadata and controls
67 lines (52 loc) · 1.99 KB
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
import unittest
import algorithms.string as string
class StringTest(unittest.TestCase):
def test_atoi(self):
self.assertEqual(string.atoi('123'), 123)
def test_atoi_neg(self):
self.assertEqual(string.atoi('-123'), -123)
def test_atoi_empty_string(self):
self.assertRaises(ValueError, string.atoi, '')
def test_reverse_string_words(self):
s = 'word1 word2 word3'
s = string.reverse_string_words(s)
self.assertEqual(s, 'word3 word2 word1')
def test_reverse_string_word(self):
s = 'word1'
s = string.reverse_string_words(s)
self.assertEqual(s, 'word1')
def test_string_matching_naive(self):
t = 'ababbababa'
s = 'aba'
self.assertEqual(string.string_matching_naive(t, s), [0, 5, 7])
t = 'ababbababa'
s = 'abbb'
self.assertEqual(string.string_matching_naive(t, s), [])
def test_string_matching_rabin_karp(self):
t = 'ababbababa'
s = 'aba'
self.assertEqual(string.string_matching_rabin_karp(t, s), [0, 5, 7])
t = 'ababbababa'
s = 'abbb'
self.assertEqual(string.string_matching_rabin_karp(t, s), [])
def test_string_matching_knuth_morris_pratt(self):
t = 'ababbababa'
s = 'aba'
self.assertEqual(string.string_matching_knuth_morris_pratt(t, s),
[0, 5, 7])
t = 'ababbababa'
s = 'abbb'
self.assertEqual(string.string_matching_knuth_morris_pratt(t, s), [])
def test_string_matching_boyer_moore_horspool(self):
t = 'ababbababa'
s = 'aba'
self.assertEqual(string.string_matching_boyer_moore_horspool(t, s),
[0, 5, 7])
t = 'ababbababa'
s = 'abbb'
self.assertEqual(string.string_matching_boyer_moore_horspool(t, s), [])
s = 'ababbababa'
t = 'abbb'
self.assertEqual(string.string_matching_boyer_moore_horspool(t, s), [])
if __name__ == '__main__':
unittest.main()