Package mglutil :: Package math :: Module ncoordstest
[hide private]
[frames] | no frames]

Source Code for Module mglutil.math.ncoordstest

  1  # 
  2  # Last modified on Tue Sep  4 17:02:59 PDT 2001 by lindy 
  3  # 
  4  # $Header: /opt/cvs/python/packages/share1.5/mglutil/math/ncoordstest.py,v 1.1 2001/09/06 19:11:48 lindy Exp $ 
  5  # 
  6   
  7  """Unit test for ncoords.py 
  8   
  9  Requirements for ncoords.py: 
 10      A. __init__: 
 11          1. make Numeric, homogenious coordinates out of refCoords 
 12          2. raise ValueError if refCoords is bad 
 13      B. reset(): 
 14          3. nx3 slice of resultCoords must be equal to refCoords 
 15      C. getResultCoords: 
 16          4. return nx3 (not nx4) coordinates 
 17          5. return as Numeric.array or ListType accorinding to self.tolist 
 18  """ 
 19   
 20  from mglutil.math.ncoords import Ncoords 
 21  import unittest, math 
 22  import Numeric, RandomArray 
 23   
 24   
 25   
 26   
27 -class NcoordsTest(unittest.TestCase):
28 - def setUp(self):
29 """Called for every test.""" 30 31 npts = 500 32 dim = 3 33 self.max = 9999999. 34 self.min = -self.max 35 self.random_points = RandomArray.uniform(self.min, 36 self.max, (npts,dim)).tolist()
37 38
39 - def tearDown(self):
40 pass
41 42 43
44 -class InputOutputValues(NcoordsTest):
45 46
47 - def test_constructor_shape(self):
48 """__init__ -- make refCoords and resultCoords homogeneous""" 49 n = len(self.random_points) 50 ncoords = Ncoords( self.random_points) ### tested call ### 51 # confirm shape to be nx4 52 self.assertEqual( (n, 4), Numeric.shape(ncoords.resultCoords)) 53 self.assertEqual( (n, 4), Numeric.shape(ncoords.refCoords)) 54 # cofirm that the last column is all ones 55 self.assertEqual(Numeric.ones(n).tolist(), 56 ncoords.resultCoords[:,3].tolist()) 57 self.assertEqual(Numeric.ones(n).tolist(), 58 ncoords.refCoords[:,3].tolist())
59 60
61 - def test_input_error(self):
62 """__init__ -- ValueError on bad input""" 63 self.assertRaises(ValueError, Ncoords, range(10)) 64 self.assertRaises(ValueError, Ncoords, [(1,1,1),(1,1)] )
65 66
67 - def test_reset_values(self):
68 """reset -- points equal input values after reset""" 69 nc = Ncoords( self.random_points, tolist=1) 70 nc.reset() ### tested call ### 71 result = nc.getResultCoords() 72 # compare input and output point lists 73 self.assertEqual( self.random_points, result)
74 75
77 """getResultCoords -- if tolist: return nx3 ListType""" 78 n = len(self.random_points) 79 nc = Ncoords(self.random_points, tolist=0) 80 nc.tolist=1 81 result = nc.getResultCoords() ### tested call ### 82 # confirm shape 83 self.assertEqual((n, 3), Numeric.shape(result)) 84 # confirm type 85 self.assertEqual(type([]), type(result))
86 87
89 """getResultCoords -- if not tolist: return nx4 Numeric.array""" 90 n = len(self.random_points) 91 nc = Ncoords(self.random_points, tolist=1) 92 nc.tolist=0 93 result = nc.getResultCoords() ### tested call ### 94 # confirm shape 95 self.assertEqual((n, 4), Numeric.shape(result)) 96 # confirm type 97 self.assertEqual(type(Numeric.array([])), type(result))
98 99 100 101 if __name__ == '__main__': 102 unittest.main() 103 104 # for example: 105 # py mglutil/math/ncoordstest.py -v 106 # or, to redirect output to a file: 107 # py ncoordstest.py -v > & ! /tmp/nct.out 108