[Scipy-svn] r5070 - trunk/scipy/spatial/tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Nov 12 19:03:11 EST 2008
Author: damian.eads
Date: 2008-11-12 18:03:06 -0600 (Wed, 12 Nov 2008)
New Revision: 5070
Modified:
trunk/scipy/spatial/tests/test_distance.py
Log:
Added tests for scipy.spatial.distance.is_valid_y.
Modified: trunk/scipy/spatial/tests/test_distance.py
===================================================================
--- trunk/scipy/spatial/tests/test_distance.py 2008-11-12 23:48:03 UTC (rev 5069)
+++ trunk/scipy/spatial/tests/test_distance.py 2008-11-13 00:03:06 UTC (rev 5070)
@@ -41,7 +41,7 @@
from scipy.spatial.distance import squareform, pdist, cdist, matching, \
jaccard, dice, sokalsneath, rogerstanimoto, \
russellrao, yule, numobs_y, numobs_dm, \
- is_valid_dm
+ is_valid_dm, is_valid_y
_filenames = ["iris.txt",
"cdist-X1.txt",
@@ -1511,37 +1511,37 @@
class TestIsValidDM(TestCase):
def test_is_valid_dm_int16_array_E(self):
- "Tests is_valid_dm on an int16 array. Exception expected."
+ "Tests is_valid_dm(*) on an int16 array. Exception expected."
D = np.zeros((5, 5), dtype='i')
self.failUnlessRaises(TypeError, is_valid_dm_throw, (D))
def test_is_valid_dm_int16_array_F(self):
- "Tests is_valid_dm on an int16 array. False expected."
+ "Tests is_valid_dm(*) on an int16 array. False expected."
D = np.zeros((5, 5), dtype='i')
self.failUnless(is_valid_dm(D) == False)
def test_is_valid_dm_improper_shape_1D_E(self):
- "Tests is_valid_dm on a 1D array. Exception expected."
+ "Tests is_valid_dm(*) on a 1D array. Exception expected."
D = np.zeros((5,), dtype=np.double)
self.failUnlessRaises(ValueError, is_valid_dm_throw, (D))
def test_is_valid_dm_improper_shape_1D_F(self):
- "Tests is_valid_dm on a 1D array. False expected."
+ "Tests is_valid_dm(*) on a 1D array. False expected."
D = np.zeros((5,), dtype=np.double)
self.failUnless(is_valid_dm(D) == False)
def test_is_valid_dm_improper_shape_3D_E(self):
- "Tests is_valid_dm on a 3D array. Exception expected."
+ "Tests is_valid_dm(*) on a 3D array. Exception expected."
D = np.zeros((3,3,3), dtype=np.double)
self.failUnlessRaises(ValueError, is_valid_dm_throw, (D))
def test_is_valid_dm_improper_shape_3D_F(self):
- "Tests is_valid_dm on a 3D array. False expected."
+ "Tests is_valid_dm(*) on a 3D array. False expected."
D = np.zeros((3,3,3), dtype=np.double)
self.failUnless(is_valid_dm(D) == False)
def test_is_valid_dm_nonzero_diagonal_E(self):
- "Tests is_valid_dm on a distance matrix with a nonzero diagonal. Exception expected."
+ "Tests is_valid_dm(*) on a distance matrix with a nonzero diagonal. Exception expected."
y = np.random.rand(10)
D = squareform(y)
for i in xrange(0, 5):
@@ -1549,7 +1549,7 @@
self.failUnlessRaises(ValueError, is_valid_dm_throw, (D))
def test_is_valid_dm_nonzero_diagonal_F(self):
- "Tests is_valid_dm on a distance matrix with a nonzero diagonal. False expected."
+ "Tests is_valid_dm(*) on a distance matrix with a nonzero diagonal. False expected."
y = np.random.rand(10)
D = squareform(y)
for i in xrange(0, 5):
@@ -1557,45 +1557,117 @@
self.failUnless(is_valid_dm(D) == False)
def test_is_valid_dm_assymetric_E(self):
- "Tests is_valid_dm on an assymetric distance matrix. Exception expected."
+ "Tests is_valid_dm(*) on an assymetric distance matrix. Exception expected."
y = np.random.rand(10)
D = squareform(y)
D[1,3] = D[3,1] + 1
self.failUnlessRaises(ValueError, is_valid_dm_throw, (D))
def test_is_valid_dm_assymetric_F(self):
- "Tests is_valid_dm on an assymetric distance matrix. False expected."
+ "Tests is_valid_dm(*) on an assymetric distance matrix. False expected."
y = np.random.rand(10)
D = squareform(y)
D[1,3] = D[3,1] + 1
self.failUnless(is_valid_dm(D) == False)
def test_is_valid_dm_correct_1_by_1(self):
- "Tests is_valid_dm on a correct 1x1. True expected."
+ "Tests is_valid_dm(*) on a correct 1x1. True expected."
D = np.zeros((1,1), dtype=np.double)
self.failUnless(is_valid_dm(D) == True)
def test_is_valid_dm_correct_2_by_2(self):
- "Tests is_valid_dm on a correct 2x2. True expected."
+ "Tests is_valid_dm(*) on a correct 2x2. True expected."
y = np.random.rand(1)
D = squareform(y)
self.failUnless(is_valid_dm(D) == True)
def test_is_valid_dm_correct_3_by_3(self):
- "Tests is_valid_dm on a correct 3x3. True expected."
+ "Tests is_valid_dm(*) on a correct 3x3. True expected."
y = np.random.rand(3)
D = squareform(y)
self.failUnless(is_valid_dm(D) == True)
def test_is_valid_dm_correct_4_by_4(self):
- "Tests is_valid_dm on a correct 4x4. True expected."
+ "Tests is_valid_dm(*) on a correct 4x4. True expected."
y = np.random.rand(6)
D = squareform(y)
self.failUnless(is_valid_dm(D) == True)
def test_is_valid_dm_correct_5_by_5(self):
- "Tests is_valid_dm on a correct 5x5. True expected."
+ "Tests is_valid_dm(*) on a correct 5x5. True expected."
y = np.random.rand(10)
D = squareform(y)
self.failUnless(is_valid_dm(D) == True)
+def is_valid_y_throw(y):
+ return is_valid_y(y, throw=True)
+
+class TestIsValidY(TestCase):
+
+ def test_is_valid_y_int16_array_E(self):
+ "Tests is_valid_y(*) on an int16 array. Exception expected."
+ y = np.zeros((10,), dtype='i')
+ self.failUnlessRaises(TypeError, is_valid_y_throw, (y))
+
+ def test_is_valid_y_int16_array_F(self):
+ "Tests is_valid_y(*) on an int16 array. False expected."
+ y = np.zeros((10,), dtype='i')
+ self.failUnless(is_valid_y(y) == False)
+
+ def test_is_valid_y_improper_shape_2D_E(self):
+ "Tests is_valid_y(*) on a 2D array. Exception expected."
+ y = np.zeros((3,3,), dtype=np.double)
+ self.failUnlessRaises(ValueError, is_valid_y_throw, (y))
+
+ def test_is_valid_y_improper_shape_2D_F(self):
+ "Tests is_valid_y(*) on a 2D array. False expected."
+ y = np.zeros((3,3,), dtype=np.double)
+ self.failUnless(is_valid_y(y) == False)
+
+ def test_is_valid_y_improper_shape_3D_E(self):
+ "Tests is_valid_y(*) on a 3D array. Exception expected."
+ y = np.zeros((3,3,3), dtype=np.double)
+ self.failUnlessRaises(ValueError, is_valid_y_throw, (y))
+
+ def test_is_valid_y_improper_shape_3D_F(self):
+ "Tests is_valid_y(*) on a 3D array. False expected."
+ y = np.zeros((3,3,3), dtype=np.double)
+ self.failUnless(is_valid_y(y) == False)
+
+ def test_is_valid_y_correct_2_by_2(self):
+ "Tests is_valid_y(*) on a correct 2x2 condensed. True expected."
+ y = self.correct_n_by_n(2)
+ self.failUnless(is_valid_y(y) == True)
+
+ def test_is_valid_y_correct_3_by_3(self):
+ "Tests is_valid_y(*) on a correct 3x3 condensed. True expected."
+ y = self.correct_n_by_n(3)
+ self.failUnless(is_valid_y(y) == True)
+
+ def test_is_valid_y_correct_4_by_4(self):
+ "Tests is_valid_y(*) on a correct 4x4 condensed. True expected."
+ y = self.correct_n_by_n(4)
+ self.failUnless(is_valid_y(y) == True)
+
+ def test_is_valid_y_correct_5_by_5(self):
+ "Tests is_valid_y(*) on a correct 5x5 condensed. True expected."
+ y = self.correct_n_by_n(5)
+ self.failUnless(is_valid_y(y) == True)
+
+ def test_is_valid_y_2_100(self):
+ "Tests is_valid_y(*) on 100 improper condensed distance matrices. Expecting exception."
+ a = set([])
+ for n in xrange(2, 16):
+ a.add(n*(n-1)/2)
+ print a
+ for i in xrange(5, 105):
+ if i not in a:
+ self.failUnlessRaises(ValueError, self.bad_y, i)
+
+ def bad_y(self, n):
+ y = np.random.rand(n)
+ return is_valid_y(y, throw=True)
+
+ def correct_n_by_n(self, n):
+ y = np.random.rand(n*(n-1)/2)
+ return y
More information about the Scipy-svn
mailing list