[Scipy-svn] r5086 - trunk/scipy/cluster/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Nov 12 23:14:40 EST 2008


Author: damian.eads
Date: 2008-11-12 22:14:38 -0600 (Wed, 12 Nov 2008)
New Revision: 5086

Modified:
   trunk/scipy/cluster/tests/test_hierarchy.py
Log:
Wrote more tests for hierarchy.correspond. Removed some unnecessary imports from test_hierarchy.

Modified: trunk/scipy/cluster/tests/test_hierarchy.py
===================================================================
--- trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-13 04:12:47 UTC (rev 5085)
+++ trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-13 04:14:38 UTC (rev 5086)
@@ -39,7 +39,7 @@
 from numpy.testing import *
 
 from scipy.cluster.hierarchy import linkage, from_mlab_linkage, to_mlab_linkage, num_obs_linkage, inconsistent, cophenet, from_mlab_linkage, fclusterdata, fcluster, is_isomorphic, single, complete, average, weighted, centroid, median, ward, leaders, correspond
-from scipy.spatial.distance import squareform, pdist, numobs_dm, numobs_y
+from scipy.spatial.distance import squareform, pdist
 
 _tdist = np.array([[0,    662,  877,  255,  412,  996],
                    [662,  0,    295,  468,  268,  400],
@@ -102,18 +102,6 @@
 
 load_testing_files()
 
-class TestNumObs(TestCase):
-
-    def test_num_obs_linkage_multi_matrix(self):
-        "Tests num_obs_linkage with observation matrices of multiple sizes."
-        for n in xrange(2, 10):
-            X = np.random.rand(n, 4)
-            Y = pdist(X)
-            Z = linkage(Y)
-            #print Z
-            #print A.shape, Y.shape, Yr.shape
-            self.failUnless(num_obs_linkage(Z) == n)
-
 class TestLinkage(TestCase):
 
     def test_linkage_empty_distance_matrix(self):
@@ -598,7 +586,7 @@
             self.failUnless(correspond(Z, y))
 
     def test_correspond_4_and_up(self):
-        "Tests correspond(Z, y) on linkage and CDMs over observation sets between sizes 4 and 15 (step size 3)."
+        "Tests correspond(Z, y) on linkage and CDMs over observation sets of different sizes. Correspondance should be false."
         for (i, j) in zip(range(2, 4), range(3, 5)) + zip(range(3, 5), range(2, 4)):
             y = np.random.rand(i*(i-1)/2)
             y2 = np.random.rand(j*(j-1)/2)
@@ -607,6 +595,26 @@
             self.failUnless(correspond(Z, y2) == False)
             self.failUnless(correspond(Z2, y) == False)
 
+    def test_correspond_4_and_up_2(self):
+        "Tests correspond(Z, y) on linkage and CDMs over observation sets of different sizes. Correspondance should be false."
+        for (i, j) in zip(range(2, 7), range(16, 21)) + zip(range(2, 7), range(16, 21)):
+            y = np.random.rand(i*(i-1)/2)
+            y2 = np.random.rand(j*(j-1)/2)
+            Z = linkage(y)
+            Z2 = linkage(y2)
+            self.failUnless(correspond(Z, y2) == False)
+            self.failUnless(correspond(Z2, y) == False)
+
+    def test_num_obs_linkage_multi_matrix(self):
+        "Tests num_obs_linkage with observation matrices of multiple sizes."
+        for n in xrange(2, 10):
+            X = np.random.rand(n, 4)
+            Y = pdist(X)
+            Z = linkage(Y)
+            #print Z
+            #print A.shape, Y.shape, Yr.shape
+            self.failUnless(num_obs_linkage(Z) == n)
+
 def help_single_inconsistent_depth(self, i):
     Y = squareform(_tdist)
     Z = linkage(Y, 'single')




More information about the Scipy-svn mailing list