-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
65 lines (57 loc) · 2.04 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
import unittest
import text_helpers
class TestTextHelpersMethods(unittest.TestCase):
def test_distance(self):
test_cases = [
("test_string", "test string", 1),
("test_string", "teststring", 1),
("test_strings", "teststring", 2),
("test_string", "test_string", 0)
]
for t in test_cases:
res = text_helpers.minimum_edit_distance(t[0], t[1])
self.assertEqual(res, t[-1])
def test_in_range(self):
test_cases = [
(15, (0, 10), False),
(15, (0, 15), False),
(15, (0, 16), True),
(-15, (-20, 10), True),
(-22, (-20, 10), False)
]
for t in test_cases:
res = text_helpers.is_val_in_range(t[0], t[1])
self.assertEqual(res, t[-1])
def test_distance_replace(self):
test_cases = [
("test_string", "test string", 1, "test_string"),
("test_string", "teststring", 1, "test_string"),
("test_strings", "teststring", 1, "teststring"),
("test_string", "test_string", 1, "test_string"),
("test_string", "node_string", 1, "node_string"),
("test_string", "node_string", 4, "test_string")
]
for t in test_cases:
res = text_helpers.check_distance(t[1], t[0], t[2])
self.assertEqual(res, t[-1])
def test_simple_replace(self):
REPLACE_RULES = {
"1,-1": ["i", "[", "]", "l", "7", "?", "t"],
"0,-1": ["o"],
"q,-2": ["g"],
"0,": ["0o", "o0", "00", "oo"],
"q,": ["qg","qq","gg","gq"]
}
test_cases = [
("sinri", "sinr1"),
("sInrl", "sinr1"),
("rsrqo", "rsrq0"),
("rSrqO", "rsrq0"),
("rsrg0", "rsrq0"),
("rsrgg0", "rsrq0")
]
for t in test_cases:
res = text_helpers.check_replace(t[0], REPLACE_RULES)
self.assertEqual(res, t[-1])
if __name__ == '__main__':
unittest.main()