revision 910 by gross, Fri Nov 24 10:04:09 2006 UTC revision 912 by gross, Wed Dec 6 03:29:49 2006 UTC
# Line 28  def _cross(x, y): Line 28  def _cross(x, y):
28      return numarray.array([x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]])      return numarray.array([x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]])
29
30
32     ABS_TOL=1.e-8     ABS_TOL=1.e-8
33     def __distance(self,x,y):     def __distance(self,x,y):
34         return math.sqrt(numarray.dot(x-y,x-y))         return math.sqrt(numarray.dot(x-y,x-y))
593          s3=t([1,1,1])          s3=t([1,1,1])
594          self.failUnless(isinstance(s3,numarray.NumArray),"s3 is not a numarray object.")          self.failUnless(isinstance(s3,numarray.NumArray),"s3 is not a numarray object.")
595          self.failUnless(self.__distance(s3,numarray.array([1.,1,1.]))<self.ABS_TOL,"s3 is wrong.")          self.failUnless(self.__distance(s3,numarray.array([1.,1,1.]))<self.ABS_TOL,"s3 is wrong.")
596
598       def setUp(self):
599             global global_primitive_id_counter
600             self.id0=global_primitive_id_counter
601
602       def test_baseclass(self):
603             p=Primitive()
604
605             id=p.getID()
606             print id
607             self.failUnless(isinstance(id,int),"id number is not an integer")
608             self.failUnless(id==self.id0,"id number is expected to be %s."%self.id0)
609
610             self.failUnless(not p.isPoint(),"generic primitive is not a point.")
611             self.failUnless(not p.isCurve(),"generic primitive is not a curve.")
612             self.failUnless(not p.isCurveLoop(),"generic primitive is not a curve loop.")
613             self.failUnless(not p.isSurface(),"generic primitive is not a surface.")
614             self.failUnless(not p.isSurfaceLoop(),"generic primitive is not a surface loop.")
615
616             hs=p.getHistory()
617             self.failUnless(isinstance(hs,set),"history must be a set")
618             self.failUnless(len(hs)==0,"history should be empty.")
619
620             ps=p.getPoints()
621             self.failUnless(isinstance(ps,set),"point set must be a set")
622             self.failUnless(len(ps)==0,"point set should be empty.")
623
624             p.setLocalScale(1.23)
625
626       def test_point(self):
627           p=Point(1.,2.,3.,local_scale=9.)
628
629           id=p.getID()
630           self.failUnless(isinstance(id,int),"id number is not an integer")
631           self.failUnless(id==self.id0,"id number is expected to be %s"%self.id0)
632
633           hs=p.getHistory()
634           self.failUnless(isinstance(hs,set),"history must be a set")
635           self.failUnless(len(hs)==1,"history must have length 1.")
636           self.failUnless(p in hs,"history must contain point p")
637
638           ps=p.getPoints()
639           self.failUnless(isinstance(ps,set),"point set must be a set")
640           self.failUnless(len(ps)==1,"point set must have length 1.")
641           self.failUnless(p in ps,"point set must contain point p")
642
643           c=p.getCoordinates()
644           self.failUnless(isinstance(c,numarray.NumArray),"coordinates are not a numarray object.")
645           self.failUnless(c[0]==1.,"x coordinate is not 1.")
646           self.failUnless(c[1]==2.,"y coordinate is not 2.")
647           self.failUnless(c[2]==3.,"z coordinate is not 3.")
648
649           p.setCoordinates(-1.,-2.,-3.)
650           c=p.getCoordinates()
651           self.failUnless(isinstance(c,numarray.NumArray),"new coordinates are not a numarray object.")
652           self.failUnless(c[0]==-1.,"new x coordinate is not -1.")
653           self.failUnless(c[1]==-2.,"new y coordinate is not -2.")
654           self.failUnless(c[2]==-3.,"new z coordinate is not -3.")
655
656           self.failUnless(p.isColocated(Point(-1.,-2.,-3.)),"colocation not detected.")
657           self.failUnless(p.isColocated(numarray.array([-1.,-2.,-3.])),"colocation with numarray representation not detected.")
658           self.failUnless(not p.isColocated(numarray.array([1.,-2.,-3.])),"false colocation detected.")
659           self.failUnless(not p.isColocated(numarray.array([0.,0.,0.])),"false colocation with origin detected.")
660
661           l=p.getLocalScale()
662           self.failUnless(l==9.,"refinement scale is not 9.")
663
664           p.setLocalScale(3.)
665           l=p.getLocalScale()
666           self.failUnless(l==3.,"new refinement scale is not 3.")
667           self.UnlessRaises(ValueError,p.setLocalScale,-3.)
668
669  if __name__ == '__main__':  if __name__ == '__main__':
670     suite = unittest.TestSuite()     suite = unittest.TestSuite()