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

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Nov 12 17:27:17 EST 2008


Author: damian.eads
Date: 2008-11-12 16:27:16 -0600 (Wed, 12 Nov 2008)
New Revision: 5065

Modified:
   trunk/scipy/cluster/tests/test_hierarchy.py
Log:
Wrote more tests for hierarchy.is_isomorphic.

Modified: trunk/scipy/cluster/tests/test_hierarchy.py
===================================================================
--- trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-12 22:20:34 UTC (rev 5064)
+++ trunk/scipy/cluster/tests/test_hierarchy.py	2008-11-12 22:27:16 UTC (rev 5065)
@@ -537,14 +537,35 @@
         for k in xrange(0, 3):
             self.help_is_isomorphic_randperm(1000, 5)
 
-    def help_is_isomorphic_randperm(self, nobs, nclusters):
+
+    def test_is_isomorphic_6A(self):
+        "Tests is_isomorphic on test case #5A (1000 observations, 2 random clusters, random permutation of the labeling, slightly nonisomorphic.) Run 3 times."
+        for k in xrange(0, 3):
+            self.help_is_isomorphic_randperm(1000, 2, True, 5)
+
+    def test_is_isomorphic_6B(self):
+        "Tests is_isomorphic on test case #5B (1000 observations, 3 random clusters, random permutation of the labeling, slightly nonisomorphic.) Run 3 times."
+        for k in xrange(0, 3):
+            self.help_is_isomorphic_randperm(1000, 3, True, 5)
+
+    def test_is_isomorphic_6C(self):
+        "Tests is_isomorphic on test case #5C (1000 observations, 5 random clusters, random permutation of the labeling, slightly non-isomorphic.) Run 3 times."
+        for k in xrange(0, 3):
+            self.help_is_isomorphic_randperm(1000, 5, True, 5)
+
+    def help_is_isomorphic_randperm(self, nobs, nclusters, noniso=False, nerrors=0):
         a = np.int_(np.random.rand(nobs) * nclusters)
         b = np.zeros(a.size, dtype=np.int_)
         q = {}        
         P = np.random.permutation(nclusters)
         for i in xrange(0, a.shape[0]):
             b[i] = P[a[i]]
-        self.failUnless(is_isomorphic(a, b) == True)
+        if noniso:
+            Q = np.random.permutation(nobs)
+            b[Q[0:nerrors]] += 1
+            b[Q[0:nerrors]] %= nclusters
+        self.failUnless(is_isomorphic(a, b) == (not noniso))
+        self.failUnless(is_isomorphic(b, a) == (not noniso))
 
 def help_single_inconsistent_depth(self, i):
     Y = squareform(_tdist)




More information about the Scipy-svn mailing list