-
Notifications
You must be signed in to change notification settings - Fork 85
/
test.py
138 lines (129 loc) · 4.06 KB
/
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
128
129
130
131
132
133
134
135
136
137
from doctest import testmod, testfile
import unittest
import simplediff
TESTS = {
'insert': [
{
"old": [1, 3, 4],
"new": [1, 2, 3, 4],
"diff": [("=", [1]),
("+", [2]),
("=", [3, 4])]
},
{
"old": [1, 2, 3, 8, 9, 12, 13],
"new": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
"diff": [("=", [1, 2, 3]),
("+", [4, 5, 6, 7]),
("=", [8, 9]),
("+", [10, 11]),
("=", [12, 13]),
("+", [14, 15])]
},
{
"old": [1, 2, 3, 4, 5],
"new": [1, 2, 2, 3, 4, 5],
"diff": [("=", [1]),
("+", [2]),
("=", [2, 3, 4, 5])]
},
{
"old": [1, 2, 3, 4, 5],
"new": [1, 2, 2, 3, 4, 4, 5],
"diff": [("=", [1]),
("+", [2]),
("=", [2, 3, 4]),
("+", [4]),
("=", [5])]
},
{
"old": [1, 2, 3, 4, 5],
"new": [1, 2, 1, 2, 3, 3, 2, 1, 4, 5],
"diff": [("+", [1, 2]),
("=", [1, 2, 3]),
("+", [3, 2, 1]),
("=", [4, 5])]
}
],
'delete': [
{
"old": [1, 2, 3, 4, 5],
"new": [1, 2, 5],
"diff": [("=", [1, 2]),
("-", [3, 4]),
("=", [5])]
},
{
"old": [1, 2, 3, 4, 5, 6, 7, 8],
"new": [3, 6, 7],
"diff": [("-", [1, 2]),
("=", [3]),
("-", [4, 5]),
("=", [6, 7]),
("-", [8])]
},
{
"old": [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
"new": [1, 2, 3, 4, 5],
"diff": [("=", [1, 2, 3, 4, 5]),
("-", [1, 2, 3, 4, 5])]
}
],
'words': [
{
"old": ["The", "quick", "brown", "fox"],
"new": ["The", "slow", "green", "turtle"],
"diff": [("=", ["The"]),
("-", ["quick", "brown", "fox"]),
("+", ["slow", "green", "turtle"])]
},
{
"old": ["jumps", "over", "the", "lazy", "dog"],
"new": ["walks", "around", "the", "orange", "cat"],
"diff": [("-", ["jumps", "over"]),
("+", ["walks", "around"]),
("=", ["the"]),
("-", ["lazy", "dog"]),
("+", ["orange", "cat"])]
}
],
'character': [
{
"old": "The quick brown fox.",
"new": "The kuick brown fix.",
"diff": [("=", "The "),
("-", "q"),
("+", "k"),
("=", "uick brown f"),
("-", "o"),
("+", "i"),
("=", "x.")]
}
]
}
class DiffTests(unittest.TestCase):
def test_delete_diff(self):
strings = TESTS['delete']
for check in strings:
self.assertEqual(simplediff.diff(check['old'], check['new']),
check['diff'])
def test_insert_diff(self):
strings = TESTS['insert']
for check in strings:
self.assertEqual(simplediff.diff(check['old'], check['new']),
check['diff'])
def test_words_diff(self):
strings = TESTS['words']
for check in strings:
self.assertEqual(simplediff.diff(check['old'], check['new']),
check['diff'])
def test_character_diff(self):
strings = TESTS['character']
for check in strings:
self.assertEqual(simplediff.diff(check['old'], check['new']),
check['diff'])
def test_doctests(self):
testmod(simplediff)
testfile('README.md')
if __name__ == '__main__':
unittest.main()