-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_duplicates_test.py
executable file
·82 lines (74 loc) · 4.18 KB
/
find_duplicates_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
#!/usr/bin/env python3
import numpy
import unittest
import find_duplicates
import tokenizer
import utils
class TestGetLengths(unittest.TestCase):
def setUp(self):
contents = 'print(hello(1, 2)) and print(hello("hi", 2))'
data = tokenizer.get_tokens(contents, "python")
self.matrix = utils.make_matrix(data.tokens, data.tokens)
@staticmethod
def debug_differences(expected, actual):
print("expected:")
print(expected)
print("actual:")
print(actual)
print("diff:")
print(expected - actual)
print("total", numpy.sum(expected - actual))
def test_compare_to_self(self):
expected = numpy.array([
#p ( h ( 1 , 2 ) ) a p ( h ( " , 2 ) )
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0], # print
[0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 1, 0, 0, 0, 0, 0], # (
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0], # hello
[0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0], # (
[0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], # 1
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0], # ,
[0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0], # 2
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 8, 1], # )
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8], # )
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], # and
[8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], # print
[0, 8, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0], # (
[0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], # hello
[0, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0], # (
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], # "hi"
[0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], # ,
[0, 0, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], # 2
[0, 0, 0, 0, 0, 0, 0, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], # )
[0, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], # )
])
actual = find_duplicates.get_lengths(self.matrix, True)
#self.debug_differences(expected, actual)
self.assertTrue((expected - actual == 0).all())
def test_compare_to_other(self):
expected = numpy.array([
# p ( h ( 1 , 2 ) ) a p ( h ( " , 2 ) )
[19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0], # print
[ 0,19, 0, 1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 1, 0, 0, 0, 0, 0], # (
[ 0, 0,19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0], # hello
[ 0, 1, 0,19, 0, 0, 0, 0, 0, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0], # (
[ 0, 0, 0, 0,19, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], # 1
[ 0, 0, 0, 0, 0,19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0], # ,
[ 0, 0, 0, 0, 1, 0,19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0], # 2
[ 0, 0, 0, 0, 0, 0, 0,19, 1, 0, 0, 0, 0, 0, 0, 0, 0, 8, 1], # )
[ 0, 0, 0, 0, 0, 0, 0, 1,19, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8], # )
[ 0, 0, 0, 0, 0, 0, 0, 0, 0,19, 0, 0, 0, 0, 0, 0, 0, 0, 0], # and
[ 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,19, 0, 0, 0, 0, 0, 0, 0, 0], # print
[ 0, 8, 0, 1, 0, 0, 0, 0, 0, 0, 0,19, 0, 1, 0, 0, 0, 0, 0], # (
[ 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,19, 0, 0, 0, 0, 0, 0], # hello
[ 0, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0,19, 0, 0, 0, 0, 0], # (
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,19, 0, 0, 0, 0], # "hi"
[ 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,19, 0, 0, 0], # ,
[ 0, 0, 0, 0, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,19, 0, 0], # 2
[ 0, 0, 0, 0, 0, 0, 0, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0,19, 1], # )
[ 0, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 1,19] # )
])
actual = find_duplicates.get_lengths(self.matrix, False)
#self.debug_differences(expected, actual)
self.assertTrue((expected - actual == 0).all())
if __name__ == '__main__':
unittest.main()