Skip to content

Commit 651d354

Browse files
committed
Added tests for gihub issue #11
See #11
1 parent fae41b3 commit 651d354

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def testCluster(self):
8888
[518, 564, 542]],
8989
cl.getlevel(40))
9090

91+
def testUnmodifiedData(self):
92+
cl = HierarchicalClustering(self.__data, lambda x, y: abs(x - y))
93+
new_data = []
94+
[new_data.extend(_) for _ in cl.getlevel(40)]
95+
self.assertEqual(sorted(new_data), sorted(self.__data))
96+
9197

9298
class HClusterStringTestCase(unittest.TestCase):
9399

@@ -126,6 +132,12 @@ def testCluster(self):
126132
],
127133
cl.getlevel(0.5))
128134

135+
def testUnmodifiedData(self):
136+
cl = HierarchicalClustering(self.__data, self.sim)
137+
new_data = []
138+
[new_data.extend(_) for _ in cl.getlevel(0.5)]
139+
self.assertEqual(sorted(new_data), sorted(self.__data))
140+
129141

130142
class KClusterSmallListTestCase(unittest.TestCase):
131143

@@ -193,6 +205,16 @@ def testClustering(self):
193205
[[(8, 2), (8, 1), (8, 3), (7, 3), (9, 2), (9, 3)],
194206
[(3, 5), (1, 5), (3, 4), (2, 6), (2, 5), (3, 6)]])
195207

208+
def testUnmodifiedData(self):
209+
"Basic clustering test"
210+
data = [(8, 2), (7, 3), (2, 6), (3, 5), (3, 6), (1, 5), (8, 1), (3,
211+
4), (8, 3), (9, 2), (2, 5), (9, 3)]
212+
cl = KMeansClustering(data)
213+
214+
new_data = []
215+
[new_data.extend(_) for _ in cl.getclusters(2)]
216+
self.assertEqual(sorted(new_data), sorted(data))
217+
196218

197219
class KClusterSFBugs(unittest.TestCase):
198220

0 commit comments

Comments
 (0)