Code Duplication    Length = 43-43 lines in 3 locations

tests/data_structures/commons/hashed_map_unit_test.py 3 locations

@@ 97-139 (lines=43) @@
94
            self.assertFalse(map.contains_key(str(i)))
95
96
97
class HashedMapWithLinearProbingUnitTest(unittest.TestCase):
98
    def test_hashedmap(self):
99
        map = HashedMapWithLinearProbing()
100
101
        map.put("one", 1)
102
        map.put("two", 2)
103
        map.put("three", 3)
104
        map.put("six", 6)
105
        map.put("ten", 10)
106
        map.put("ten", 10)
107
108
        self.assertEqual(1, map.get("one"))
109
        self.assertEqual(2, map.get("two"))
110
        self.assertEqual(3, map.get("three"))
111
112
        self.assertTrue(map.contains_key("one"))
113
        self.assertTrue(map.contains_key("two"))
114
115
        self.assertEqual(5, map.size())
116
        self.assertFalse(map.is_empty())
117
118
        map.delete("one")
119
        self.assertFalse(map.contains_key("one"))
120
        self.assertEqual(4, map.size())
121
122
        map.delete("ten")
123
        self.assertFalse(map.contains_key("ten"))
124
        self.assertEqual(3, map.size())
125
126
        map.delete("three")
127
        self.assertFalse(map.contains_key("three"))
128
        self.assertEqual(2, map.size())
129
130
        for i in range(100):
131
            map.put(str(i), i)
132
            self.assertEqual(i, map.get(str(i)))
133
134
        for key in map.keys():
135
            print(key)
136
137
        for i in range(100):
138
            map.delete(str(i))
139
            self.assertFalse(map.contains_key(str(i)))
140
141
142
if __name__ == '__main__':
@@ 52-94 (lines=43) @@
49
            self.assertFalse(map.contains_key(str(i)))
50
51
52
class HashedMapWithSeparateChainingUnitTest(unittest.TestCase):
53
    def test_binarySearchTree(self):
54
        map = HashedMapWithSeparateChaining()
55
56
        map.put("one", 1)
57
        map.put("two", 2)
58
        map.put("three", 3)
59
        map.put("six", 6)
60
        map.put("ten", 10)
61
        map.put("ten", 10)
62
63
        self.assertEqual(1, map.get("one"))
64
        self.assertEqual(2, map.get("two"))
65
        self.assertEqual(3, map.get("three"))
66
67
        self.assertTrue(map.contains_key("one"))
68
        self.assertTrue(map.contains_key("two"))
69
70
        self.assertEqual(5, map.size())
71
        self.assertFalse(map.is_empty())
72
73
        map.delete("one")
74
        self.assertFalse(map.contains_key("one"))
75
        self.assertEqual(4, map.size())
76
77
        map.delete("ten")
78
        self.assertFalse(map.contains_key("ten"))
79
        self.assertEqual(3, map.size())
80
81
        map.delete("three")
82
        self.assertFalse(map.contains_key("three"))
83
        self.assertEqual(2, map.size())
84
85
        for i in range(100):
86
            map.put(str(i), i)
87
            self.assertEqual(i, map.get(str(i)))
88
89
        for key in map.keys():
90
            print(key)
91
92
        for i in range(100):
93
            map.delete(str(i))
94
            self.assertFalse(map.contains_key(str(i)))
95
96
97
class HashedMapWithLinearProbingUnitTest(unittest.TestCase):
@@ 7-49 (lines=43) @@
4
    HashedMapWithLinearProbing
5
6
7
class HashedMapUnitTest(unittest.TestCase):
8
    def test_binarySearchTree(self):
9
        map = HashedMap.create()
10
11
        map.put("one", 1)
12
        map.put("two", 2)
13
        map.put("three", 3)
14
        map.put("six", 6)
15
        map.put("ten", 10)
16
        map.put("ten", 10)
17
18
        self.assertEqual(1, map.get("one"))
19
        self.assertEqual(2, map.get("two"))
20
        self.assertEqual(3, map.get("three"))
21
22
        self.assertTrue(map.contains_key("one"))
23
        self.assertTrue(map.contains_key("two"))
24
25
        self.assertEqual(5, map.size())
26
        self.assertFalse(map.is_empty())
27
28
        map.delete("one")
29
        self.assertFalse(map.contains_key("one"))
30
        self.assertEqual(4, map.size())
31
32
        map.delete("ten")
33
        self.assertFalse(map.contains_key("ten"))
34
        self.assertEqual(3, map.size())
35
36
        map.delete("three")
37
        self.assertFalse(map.contains_key("three"))
38
        self.assertEqual(2, map.size())
39
40
        for i in range(100):
41
            map.put(str(i), i)
42
            self.assertEqual(i, map.get(str(i)))
43
44
        for key in map.keys():
45
            print(key)
46
47
        for i in range(100):
48
            map.delete(str(i))
49
            self.assertFalse(map.contains_key(str(i)))
50
51
52
class HashedMapWithSeparateChainingUnitTest(unittest.TestCase):