@@ -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
9298class 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
130142class 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
197219class KClusterSFBugs (unittest .TestCase ):
198220
0 commit comments