Skip to content

Commit 6d8beff

Browse files
committed
Added unit-test for complete linkage.
1 parent b56254e commit 6d8beff

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

test.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def setUp(self):
7373
self.__data = [791, 956, 676, 124, 564, 84, 24, 365, 594, 940, 398,
7474
971, 131, 365, 542, 336, 518, 835, 134, 391]
7575

76-
def testCluster(self):
76+
def testSingleLinkage(self):
7777
"Basic Hierarchical Clustering test with integers"
7878
cl = HierarchicalClustering(self.__data, lambda x, y: abs(x - y))
7979
cl.cluster()
@@ -88,6 +88,33 @@ def testCluster(self):
8888
[835],
8989
], cl.getlevel(40))
9090

91+
def testCompleteLinkage(self):
92+
"Basic Hierarchical Clustering test with integers"
93+
cl = HierarchicalClustering(self.__data,
94+
lambda x, y: abs(x - y),
95+
linkage='complete')
96+
result = cl.getlevel(40)
97+
98+
# sort the values to make the tests less prone to algorithm changes
99+
result = sorted([sorted(_) for _ in result])
100+
101+
expected = [
102+
[24],
103+
[84],
104+
[124, 131, 134],
105+
[336, 365, 365],
106+
[391, 398],
107+
[518],
108+
[542, 564],
109+
[594],
110+
[676],
111+
[791],
112+
[835],
113+
[940, 956, 971],
114+
]
115+
self.assertEqual(result, expected)
116+
117+
91118
def testUnmodifiedData(self):
92119
cl = HierarchicalClustering(self.__data, lambda x, y: abs(x - y))
93120
new_data = []

0 commit comments

Comments
 (0)