def testNumpyConversion(self):
     import numpy as np
     f = Field(400, length=42)
     n = f.toNumpy("nx", [("val", np.float64)])
     self.assertEqual(n["val"][23], 400.)
     f = Field(Vector(400, 200, 100), length=42)
     n = f.toNumpy("nx", [(c, np.float64) for c in "xyz"])
     self.assertEqual(n["x"][23], 400.)
     self.assertEqual(n["y"][13], 200.)
     self.assertEqual(n.size, 42)
Exemple #2
0
 def testAccess(self):
     v=Vector(3,2,1)
     self.assertEqual(v[1],2)
     self.assertEqual(v==None,False)
     v[0]=-3
     self.assertEqual(v,Vector(-3,2,1))
Exemple #3
0
 def testList(self):
     v=Vector(1,2,3)
     self.assertEqual([1,2,3],list(v))
Exemple #4
0
 def testString(self):
     v=Vector(1,2,3)
     self.assertEqual(str(v),'(1 2 3)')
Exemple #5
0
 def testPos(self):
     self.assertEqual(Vector(1,-1,0),+Vector(1,-1,0))
Exemple #6
0
 def testNeg(self):
     self.assertEqual(Vector(1,-1,0),-Vector(-1,1,0))
Exemple #7
0
 def testAbs(self):
     self.assertEqual(1,abs(Vector(1,0,0)))
     self.assertEqual(5,abs(Vector(3,4,0)))
     self.assertEqual(math.sqrt(3),abs(Vector(1,1,1)))
Exemple #8
0
 def testCross(self):
     self.assertEqual(Vector(0,0,1),Vector(1,0,0) ^ Vector(0,1,0))
     self.assertEqual(Vector(0,0,-1),Vector(0,1,0) ^ Vector(1,0,0))
     self.assertEqual(Vector(0,0,0),Vector(1,1,1) ^ Vector(1,1,1))
     self.assertEqual(Vector(-6,-3,4),Vector(1,2,3) ^ Vector(-1,2,0))
Exemple #9
0
 def testDiv(self):
     self.assertEqual(Vector(0.5,0.5,1),Vector(1,1,1)/Vector(2,2.,1))
     self.assertEqual(Vector(0.5,0,-0.5),Vector(1,0,-1)/2.)
Exemple #10
0
 def testMul(self):
     self.assertEqual(Vector(2,-1,0),Vector(1,1,1)*Vector(2,-1,0))
     self.assertEqual(Vector(0,2,-2),Vector(0,1,-1)*2)
     self.assertEqual(Vector(0,-2,2),-2*Vector(0,1,-1))
Exemple #11
0
 def testSub(self):
     self.assertEqual(Vector(1,1,0),Vector(1,0,0)-Vector(0,-1,0))
     self.assertEqual(Vector(-1,0,-2),Vector(0,1,-1)-1)
     self.assertEqual(Vector(1,0,2),1-Vector(0,1,-1))
Exemple #12
0
 def testAdd(self):
     self.assertEqual(Vector(1,-1,0),Vector(1,0,0)+Vector(0,-1,0))
     self.assertEqual(Vector(1,2,0),Vector(0,1,-1)+1)
     self.assertEqual(Vector(1,2,0),1+Vector(0,1,-1))