/[escript]/trunk/pycad/test/python/run_pycad_test.py
ViewVC logotype

Diff of /trunk/pycad/test/python/run_pycad_test.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 914 by gross, Wed Dec 6 03:29:49 2006 UTC revision 915 by gross, Thu Dec 14 06:12:53 2006 UTC
# Line 596  class Test_PyCAD_Transformations(unittes Line 596  class Test_PyCAD_Transformations(unittes
596    
597  class Test_PyCAD_Primitives(unittest.TestCase):  class Test_PyCAD_Primitives(unittest.TestCase):
598     def setUp(self):     def setUp(self):
599           global global_primitive_id_counter           resetGlobalPrimitiveIdCounter()
          self.id0=global_primitive_id_counter  
600    
601     def test_baseclass(self):     def test_baseclass(self):
602           p=Primitive()           p=Primitive()
603    
604           id=p.getID()           id=p.getID()
          print id  
605           self.failUnless(isinstance(id,int),"id number is not an integer")           self.failUnless(isinstance(id,int),"id number is not an integer")
606           self.failUnless(id==self.id0,"id number is expected to be %s."%self.id0)           self.failUnless(not id==Primitive().getID(),"id number is not unique")
607                        
608           self.failUnless(not p.isPoint(),"generic primitive is not a point.")           self.failUnless(not p.isPoint(),"generic primitive is not a point.")
609           self.failUnless(not p.isCurve(),"generic primitive is not a curve.")           self.failUnless(not p.isCurve(),"generic primitive is not a curve.")
# Line 628  class Test_PyCAD_Primitives(unittest.Tes Line 626  class Test_PyCAD_Primitives(unittest.Tes
626                
627         id=p.getID()         id=p.getID()
628         self.failUnless(isinstance(id,int),"id number is not an integer")         self.failUnless(isinstance(id,int),"id number is not an integer")
629         self.failUnless(id==self.id0,"id number is expected to be %s"%self.id0)         self.failUnless(not id==Primitive().getID(),"id number is not unique")
630                        
631           # check history:
632         hs=p.getHistory()         hs=p.getHistory()
633         self.failUnless(isinstance(hs,set),"history must be a set")         self.failUnless(isinstance(hs,set),"history must be a set")
634         self.failUnless(len(hs)==1,"history must have length 1.")         self.failUnless(len(hs)==1,"history must have length 1.")
635         self.failUnless(p in hs,"history must contain point p")         self.failUnless(p in hs,"history must contain point p")
636    
637           # check incolved points:
638         ps=p.getPoints()         ps=p.getPoints()
639         self.failUnless(isinstance(ps,set),"point set must be a set")         self.failUnless(isinstance(ps,set),"point set must be a set")
640         self.failUnless(len(ps)==1,"point set must have length 1.")         self.failUnless(len(ps)==1,"point set must have length 1.")
641         self.failUnless(p in ps,"point set must contain point p")         self.failUnless(p in ps,"point set must contain point p")
642    
643           # check coordinates:
644         c=p.getCoordinates()         c=p.getCoordinates()
645         self.failUnless(isinstance(c,numarray.NumArray),"coordinates are not a numarray object.")         self.failUnless(isinstance(c,numarray.NumArray),"coordinates are not a numarray object.")
646         self.failUnless(c[0]==1.,"x coordinate is not 1.")         self.failUnless(c[0]==1.,"x coordinate is not 1.")
647         self.failUnless(c[1]==2.,"y coordinate is not 2.")         self.failUnless(c[1]==2.,"y coordinate is not 2.")
648         self.failUnless(c[2]==3.,"z coordinate is not 3.")         self.failUnless(c[2]==3.,"z coordinate is not 3.")
649    
650         p.setCoordinates(-1.,-2.,-3.)         # reset coordinates:
651           p.setCoordinates([-1.,-2.,-3.])
652         c=p.getCoordinates()         c=p.getCoordinates()
653         self.failUnless(isinstance(c,numarray.NumArray),"new coordinates are not a numarray object.")         self.failUnless(isinstance(c,numarray.NumArray),"new coordinates are not a numarray object.")
654         self.failUnless(c[0]==-1.,"new x coordinate is not -1.")         self.failUnless(c[0]==-1.,"new x coordinate is not -1.")
655         self.failUnless(c[1]==-2.,"new y coordinate is not -2.")         self.failUnless(c[1]==-2.,"new y coordinate is not -2.")
656         self.failUnless(c[2]==-3.,"new z coordinate is not -3.")         self.failUnless(c[2]==-3.,"new z coordinate is not -3.")
657    
658           # check for a colocated point:
659         self.failUnless(p.isColocated(Point(-1.,-2.,-3.)),"colocation not detected.")         self.failUnless(p.isColocated(Point(-1.,-2.,-3.)),"colocation not detected.")
660         self.failUnless(p.isColocated(numarray.array([-1.,-2.,-3.])),"colocation with numarray representation not detected.")         self.failUnless(p.isColocated(numarray.array([-1.,-2.,-3.])),"colocation with numarray representation not detected.")
661         self.failUnless(not p.isColocated(numarray.array([1.,-2.,-3.])),"false colocation detected.")         self.failUnless(not p.isColocated(numarray.array([1.,-2.,-3.])),"false colocation detected.")
662         self.failUnless(not p.isColocated(numarray.array([0.,0.,0.])),"false colocation with origin detected.")         self.failUnless(not p.isColocated(numarray.array([0.,0.,0.])),"false colocation with origin detected.")
663    
664           # check for local length scale
665         l=p.getLocalScale()         l=p.getLocalScale()
666         self.failUnless(l==9.,"refinement scale is not 9.")         self.failUnless(l==9.,"refinement scale is not 9.")
667    
668           # check for new local length scale
669         p.setLocalScale(3.)         p.setLocalScale(3.)
670         l=p.getLocalScale()         l=p.getLocalScale()
671         self.failUnless(l==3.,"new refinement scale is not 3.")         self.failUnless(l==3.,"new refinement scale is not 3.")
672         self.UnlessRaises(ValueError,p.setLocalScale,-3.)  
673           # negative value shouldn't work.
674           self.failUnlessRaises(ValueError,p.setLocalScale,-3.)
675    
676           # copy:
677           an_other_p=p.copy()
678           self.failUnless(isinstance(an_other_p ,Point),"copy is not a point")
679           self.failUnless(not an_other_p.getID() == p.getID(),"copy has same Id")
680           self.failUnless(p.isColocated(an_other_p),"p is not colocated with its copy.")
681           self.failUnless(an_other_p.isColocated(p),"the copy is not colocated with p.")
682           self.failUnless(an_other_p.getLocalScale()==3.,"copy has wrong local scale.")
683          
684           # modify by Transformation:
685           p.modifyBy(Dilation(-1))
686           self.failUnless(p.isColocated(Point(1.,2.,3.)),"in-place transformation failed")
687          
688           # apply Transformation:
689           dil_p=p.apply(Dilation(4))
690           self.failUnless(dil_p.isColocated(Point(4.,8.,12.)),"applying transformation failed")
691           self.failUnless(not dil_p.getID() == p.getID(),"transformed point has same Id")
692           self.failUnless(dil_p.getLocalScale()==3.,"transformed point  has wrong local scale.")
693            
694           # overloaded add:
695           shift_p=p+[1,1,1]
696           self.failUnless(shift_p.isColocated(Point(2,3.,4)),"applying shift by list failed")
697           self.failUnless(not shift_p.getID() == p.getID(),"shift by list has same Id")
698           self.failUnless(shift_p.getLocalScale()==3.,"shift by list has wrong local scale.")
699    
700           shift_p=p+numarray.array([1,1,1])
701           self.failUnless(shift_p.isColocated(Point(2,3.,4)),"applying shift by numarray failed")
702           self.failUnless(not shift_p.getID() == p.getID(),"shift by numarray has same Id")
703           self.failUnless(shift_p.getLocalScale()==3.,"shift by numarray has wrong local scale.")
704           # overloaded minus
705           shift_p=p-[1,1,1]
706           self.failUnless(shift_p.isColocated(Point(0,1,2.)),"applying shift by -list failed")
707           self.failUnless(not shift_p.getID() == p.getID(),"shift by -list has same Id")
708           self.failUnless(shift_p.getLocalScale()==3.,"shift by -list has wrong local scale.")
709    
710           shift_p=p-numarray.array([1,1,1])
711           self.failUnless(shift_p.isColocated(Point(0,1,2.)),"applying shift by -numarray failed")
712           self.failUnless(not shift_p.getID() == p.getID(),"shift by -numarray has same Id")
713           self.failUnless(shift_p.getLocalScale()==3.,"shift by -numarray has wrong local scale.")
714           # overloaded inplace add:
715           p+=[1,1,1]
716           self.failUnless(p.isColocated(Point(2,3.,4)),"modification by list shift failed")
717    
718           p+=numarray.array([1,1,1])
719           self.failUnless(p.isColocated(Point(3,4,5)),"modification by numarray shift failed")
720    
721           # overloaded inplace add:
722           p-=[1,1,1]
723           self.failUnless(p.isColocated(Point(2,3,4)),"modification by -list shift failed")
724    
725           p-=numarray.array([1,1,1])
726           self.failUnless(p.isColocated(Point(1,2.,3)),"modification by -numarray shift failed")
727    
728           #overloaded multiplication:
729           mult_p=2*p
730           self.failUnless(mult_p.isColocated(Point(2,4,6)),"applying int factor failed")
731           self.failUnless(not mult_p.getID() == p.getID(),"shift by int factor has same Id")
732           self.failUnless(mult_p.getLocalScale()==3.,"shift by int factor has wrong local scale.")
733    
734           mult_p=2.*p
735           self.failUnless(mult_p.isColocated(Point(2,4,6)),"applying float factor failed")
736           self.failUnless(not mult_p.getID() == p.getID(),"shift by float factor has same Id")
737           self.failUnless(mult_p.getLocalScale()==3.,"shift by float factor has wrong local scale.")
738    
739           mult_p=Dilation(2)*p
740           self.failUnless(mult_p.isColocated(Point(2,4,6)),"applying Dilation factor failed")
741           self.failUnless(not mult_p.getID() == p.getID(),"shift by Dilation factor has same Id")
742           self.failUnless(mult_p.getLocalScale()==3.,"shift by Dilation factor has wrong local scale.")
743    
744           #overloaded inplace multiplication:
745           p*=2
746           self.failUnless(p.isColocated(Point(2,4,6)),"applying in-place int factor failed")
747    
748           p*=2.
749           self.failUnless(p.isColocated(Point(4,8,12)),"applying in-place float factor failed")
750    
751           p*=Dilation(2)
752           self.failUnless(p.isColocated(Point(8,16,24)),"applying in-place Dilation factor failed")
753    
754           # get gmsh code
755           code=p.getGmshCommand(2.)
756           self.failUnless("Point(1) = {8.0 , 16.0, 24.0 , 6.0 };"== code, "wrong gmsh code")
757    
758    
759  if __name__ == '__main__':  if __name__ == '__main__':
760     suite = unittest.TestSuite()     suite = unittest.TestSuite()

Legend:
Removed from v.914  
changed lines
  Added in v.915

  ViewVC Help
Powered by ViewVC 1.1.26