-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsngl_prd.py
101 lines (88 loc) · 2.51 KB
/
sngl_prd.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
'''
Test single period changes
'''
import unittest
import tx_place
def both_starts(a_txt, b_txt, common_txt):
result = 0
if a_txt.startswith(common_txt) and b_txt.startswith(common_txt):
result = 1
return result
class MultiReplacer(object):
def __init__(self, good_ls=None):
'''
MultiReplacer:
'''
if good_ls is None:
self.good_ls = [
tx_place.sta_8_tement,
tx_place.sta_7_tement,
]
else:
self.good_ls = good_ls
def process_replace(self, fa, fb, As, Ae, Bs, Be):
'''
MultiReplacer:
'''
needs_work = 1
delta_a = Ae - As
if delta_a == Be - Bs:
diff_cnt = 0
suspicious_change = 0
for i in range(delta_a):
part_a = fa[As + i]
part_b = fb[Bs + i]
if part_a != part_b:
diff_cnt += 1
if not any(map(lambda x: both_starts(part_a, part_b, x), self.good_ls)):
suspicious_change = 1
if diff_cnt <= 2 and not suspicious_change:
needs_work = 0
return needs_work
class TestSinglePeriod(unittest.TestCase):
def test_equal_length(self):
'''
TestSinglePeriod:
'''
multi_replacer = MultiReplacer()
fa = []
fb = []
As = 0
Ae = 0
Bs = 0
Be = 0
self.assertEqual(multi_replacer.process_replace(fa, fb, As, Ae, Bs, Be), 0)
def test_too_many_differences(self):
'''
TestSinglePeriod:
'''
multi_replacer = MultiReplacer()
fa = ['a', 'b']
fb = ['c', 'd']
As = 0
Ae = 2
Bs = 0
Be = 2
self.assertEqual(multi_replacer.process_replace(fa, fb, As, Ae, Bs, Be), 1)
def test_wrong_change(self):
'''
TestSinglePeriod:
'''
multi_replacer = MultiReplacer()
fa = ['a', 'b']
fb = ['c', 'b']
As = 0
Ae = 2
Bs = 0
Be = 2
self.assertEqual(multi_replacer.process_replace(fa, fb, As, Ae, Bs, Be), 1)
def test_common_prefix(self):
'''
TestSinglePeriod:
'''
self.assertEqual(both_starts('', '', ''), 1)
self.assertEqual(both_starts('', '', 'a'), 0)
self.assertEqual(both_starts('x', 'x', 'a'), 0)
self.assertEqual(both_starts('a', 'a', 'a'), 1)