/[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 927 by gross, Wed Jan 10 22:40:00 2007 UTC revision 928 by gross, Tue Jan 16 08:36:03 2007 UTC
# Line 1110  class Test_PyCAD_Primitives(unittest.Tes Line 1110  class Test_PyCAD_Primitives(unittest.Tes
1110          self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")          self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1111          self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")          self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1112    
1113    
1114          cc=c.getCurves()          cc=c.getCurves()
1115          self.failUnless(len(cc) == 3, "too many curves.")          self.failUnless(len(cc) == 3, "too many curves.")
1116          self.failUnless(l01 in cc, "l01 is missing")          self.failUnless(l01 in cc, "l01 is missing")
# Line 1130  class Test_PyCAD_Primitives(unittest.Tes Line 1131  class Test_PyCAD_Primitives(unittest.Tes
1131          cp=c.copy()          cp=c.copy()
1132          self.failUnless(isinstance(cp,CurveLoop), "copy returns is not an arc.")          self.failUnless(isinstance(cp,CurveLoop), "copy returns is not an arc.")
1133          self.failUnless(not cp == c, "copy equals source")          self.failUnless(not cp == c, "copy equals source")
1134            self.failUnless(cp.isColocated(c),"copy is not colocated with its source.")
1135          cc=cp.getCurves()          cc=cp.getCurves()
1136          self.failUnless(len(cc) == 3, "too many primitives in copy.")          self.failUnless(len(cc) == 3, "too many primitives in copy.")
1137          self.failUnless(not l01 in cc,"copy uses l01.")          self.failUnless(not l01 in cc,"copy uses l01.")
# Line 1162  class Test_PyCAD_Primitives(unittest.Tes Line 1164  class Test_PyCAD_Primitives(unittest.Tes
1164          self.failUnless(l12 in cc,"l12 missed in  modified object.")          self.failUnless(l12 in cc,"l12 missed in  modified object.")
1165          self.failUnless(l20 in cc,"l20 missed in  modified object.")          self.failUnless(l20 in cc,"l20 missed in  modified object.")
1166                
1167               def test_RuledSurface(self):
1168            p0=Point(0,0,0,0.1)
1169            p1=Point(1,1,1,0.2)
1170            p2=Point(2,2,2,0.3)
1171            p3=Point(3,3,3,0.4)
1172            p4=Point(1,2,3)
1173            p5=Point(10,20,3)
1174            p6=Point(1,2,30)
1175    
1176            l01=Line(p0,p1)
1177            l12_1=Arc(p3,p1,p2)
1178            l12_2_1=Spline(p1,p3,p4)
1179            l12_2_2=Spline(p4,p5,p2)
1180            l12_3=Line(p1,p2)
1181            l20=Spline(p2,p4,p0)
1182    
1183            cl1=CurveLoop(l01,l12_1,l20)
1184            cl2=CurveLoop(l01,l12_2_1,l12_2_2,l20)
1185            cl3=CurveLoop(l01,l12_3,l20)
1186    
1187            self.failUnlessRaises(TypeError,ValueError,RuledSurface,l01,msg="non CurveLoop argument accepted.")
1188    
1189            s=RuledSurface(cl1)
1190    
1191            cl=s.getBoundaryLoop()
1192            self.failUnless(cl == cl1, " wrong boundary loops")
1193    
1194            h=s.getHoles()
1195            self.failUnless(len(h) == 0, "too many holes.")
1196    
1197            crvs=s.getBoundary()
1198            self.failUnless(len(crvs) == 3, "too many boundary corves.")
1199            self.failUnless(l01 in crvs, "l01 is missing in boundary")
1200            self.failUnless(l12_1 in crvs, "l21 is missing in boundary")
1201            self.failUnless(l20 in crvs, "l20 is missing in boundary")
1202                  
1203    
1204            code=s.getGmshCommand()
1205            self.failUnless(code == "Ruled Surface(17) = {14};", "gmsh command wrong.")
1206    
1207            self.failUnless(not s.isColocated(p4),"RuledSurface is colocated with point.")
1208            self.failUnless(s.isColocated(s),"RuledSurface is not colocated with its self.")
1209            self.failUnless(s.isColocated(RuledSurface(cl1)),"RuledSurface is not colocated with its copy.")
1210            self.failUnless(not s.isColocated(RuledSurface(cl2)),"RuledSurface is colocated with different length")
1211            self.failUnless(not s.isColocated(RuledSurface(cl3)),"RuledSurface is colocated with same length.")
1212    
1213            s.setLocalScale(3.)
1214            self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1215            self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1216            self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1217            self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1218    
1219            p=s.getPrimitives()
1220            self.failUnless(len(p) == 10, "too many primitives.")
1221            self.failUnless(cl1 in p, "cl1 is missing")
1222            self.failUnless(l01 in p, "l01 is missing")
1223            self.failUnless(l12_1 in p, "l21 is missing")
1224            self.failUnless(l20 in p, "l20 is missing")
1225            self.failUnless(p0 in p, "p0 is missing")
1226            self.failUnless(p1 in p, "p1 is missing")
1227            self.failUnless(p2 in p, "p2 is missing")
1228            self.failUnless(p3 in p, "p3 is missing")
1229            self.failUnless(p4 in p, "p4 is missing")
1230    
1231            sp=s.copy()
1232            self.failUnless(isinstance(sp,RuledSurface), "copy returns is not a RuledSurface.")
1233            self.failUnless(not sp == s, "copy equals source")
1234            self.failUnless(sp.isColocated(s),"copy is not colocated with its source.")
1235            cbl=sp.getBoundaryLoop()
1236            self.failUnless(not cbl == cl1,"copy uses cl1.")
1237            cp=sp.getPrimitives()
1238            self.failUnless(len(cp) == 10, "copy as too many primitives.")
1239            self.failUnless(not cl1 in cp, "copy is using cl1")
1240            self.failUnless(not l01 in cp, "copy is using l01")
1241            self.failUnless(not l12_1 in cp, "copy is using l21")
1242            self.failUnless(not l20 in cp, "copy is using l20")
1243            self.failUnless(not p0 in cp, "copy is using p0")
1244            self.failUnless(not p1 in cp, "copy is using p1")
1245            self.failUnless(not p2 in cp, "copy is using p2")
1246            self.failUnless(not p3 in cp, "copy is using p3")
1247            self.failUnless(not p4 in cp, "copy is using p4")
1248            del cp
1249            
1250            p0_m=Point(0,0,0)
1251            p1_m=Point(-1,-1,-1)
1252            p2_m=Point(-2,-2,-2)
1253            p3_m=Point(-3,-3,-3)
1254            p4_m=Point(-1,-2,-3)
1255    
1256            l01_m=Line(p0_m,p1_m)
1257            l12_m=Arc(p3_m,p1_m,p2_m)
1258            l20_m=Spline(p2_m,p4_m,p0_m)
1259    
1260            ds=s.apply(Dilation(-1.))
1261            self.failUnless(ds.isColocated(RuledSurface(CurveLoop(l01_m,l12_m,l20_m))),"dilation is wrong.")
1262            cbl=ds.getBoundaryLoop()
1263            self.failUnless(not cbl == cl1,"dilation uses cl1.")
1264            cp=ds.getPrimitives()
1265            self.failUnless(len(cp) == 10, "dilation as too many primitives.")
1266            self.failUnless(not cl1 in cp, "dilation is using cl1")
1267            self.failUnless(not l01 in cp, "dilation is using l01")
1268            self.failUnless(not l12_1 in cp, "dilation is using l21")
1269            self.failUnless(not l20 in cp, "dilation is using l20")
1270            self.failUnless(not p0 in cp, "dilation is using p0")
1271            self.failUnless(not p1 in cp, "dilation is using p1")
1272            self.failUnless(not p2 in cp, "dilation is using p2")
1273            self.failUnless(not p3 in cp, "dilation is using p3")
1274            self.failUnless(not p4 in cp, "dilation is using p4")
1275    
1276            s.modifyBy(Dilation(-1.))
1277            self.failUnless(s.isColocated(RuledSurface(CurveLoop(l01_m,l12_m,l20_m))),"inplace dilation is wrong.")
1278    
1279            p=s.getPrimitives()
1280            self.failUnless(len(p) == 10, "inplace dilation has too many primitives.")
1281            self.failUnless(cl1 in p, "inplace dilation cl1 is missing")
1282            self.failUnless(l01 in p, "inplace dilation l01 is missing")
1283            self.failUnless(l12_1 in p, "inplace dilation l21 is missing")
1284            self.failUnless(l20 in p, "inplace dilation l20 is missing")
1285            self.failUnless(p0 in p, "inplace dilation p0 is missing")
1286            self.failUnless(p1 in p, "inplace dilation p1 is missing")
1287            self.failUnless(p2 in p, "inplace dilation p2 is missing")
1288            self.failUnless(p3 in p, "inplace dilation p3 is missing")
1289            self.failUnless(p4 in p, "inplace dilation p4 is missing")
1290    
1291       def test_PlaneSurface(self):
1292            p0=Point(0,0,0,0.1)
1293            p1=Point(10,0,0,0.2)
1294            p2=Point(10,10,0,0.3)
1295            p3=Point(0,10,3,0.4)
1296            p4=Point(5,5,0,0.001)
1297            p5=Point(7,5,0,0.001)
1298            p6=Point(5,7,0,0.001)
1299            p7=Point(8,8,0,0.001)
1300            p8=Point(9,9,0,0.001)
1301    
1302            l0=Line(p0,p1)
1303            l1=Line(p1,p2)
1304            l2=Line(p2,p3)
1305            l3=Line(p3,p0)
1306    
1307            l9=Line(p1,p8)
1308            l10=Line(p8,p3)
1309    
1310            l4=Line(p4,p5)
1311            l5=Line(p5,p6)
1312            l6=Line(p6,p4)
1313            l7=Line(p6,p7)
1314            l8=Line(p7,p4)
1315    
1316            a1=Arc(p4,p3,p1)
1317            a2=Arc(p7,p5,p6)
1318    
1319            cl=CurveLoop(l0,l1,l2,l3)
1320            h=CurveLoop(l4,l5,l6)
1321            cl_s=CurveLoop(l0,l9,l10,l3)
1322            h2=CurveLoop(l4,l5,l7,l8)
1323            cl_a=CurveLoop(a1,l1,l2)
1324            h_a=CurveLoop(a2,l6,l4)
1325    
1326            self.failUnlessRaises(TypeError,ValueError,PlaneSurface,l4,msg="non CurveLoop argument accepted.")
1327            self.failUnlessRaises(TypeError,ValueError,PlaneSurface,cl_a,h,msg="CurveLoop with no line curves accepted.")
1328            self.failUnlessRaises(TypeError,ValueError,PlaneSurface,cl,[h_a],msg="CurveLoop with no line curves as holes accepted.")
1329    
1330            s=PlaneSurface(cl,holes=[h])
1331    
1332            cl=s.getBoundaryLoop()
1333            self.failUnless(cl == cl, " wrong boundary loops")
1334    
1335            hs=s.getHoles()
1336            self.failUnless(len(hs) == 1, "one holes expected.")
1337            self.failUnless(h in hs, "h is not defined as hole.")
1338    
1339            crvs=s.getBoundary()
1340            self.failUnless(len(crvs) == 7, "too many boundary corves.")
1341            self.failUnless(l0 in crvs, "l0 is missing in boundary")
1342            self.failUnless(l1 in crvs, "l1 is missing in boundary")
1343            self.failUnless(l2 in crvs, "l2 is missing in boundary")
1344            self.failUnless(l3 in crvs, "l3 is missing in boundary")
1345            self.failUnless(l4 in crvs, "l4 is missing in boundary")
1346            self.failUnless(l5 in crvs, "l5 is missing in boundary")
1347            self.failUnless(l6 in crvs, "l6 is missing in boundary")
1348                  
1349            code=s.getGmshCommand()
1350            self.failUnless(code == "Plane Surface(29) = {23, 24};", "gmsh command wrong.")
1351    
1352            self.failUnless(not s.isColocated(p4),"PlaneSurface is colocated with point.")
1353            self.failUnless(s.isColocated(s),"PlaneSurface is not colocated with its self.")
1354            self.failUnless(s.isColocated(PlaneSurface(cl,holes=[h])),"PlaneSurface is not colocated with its copy.")
1355            self.failUnless(not s.isColocated(PlaneSurface(cl)),"PlaneSurface is colocated with PlaneSurface with same boundary but no hole")
1356            self.failUnless(not s.isColocated(PlaneSurface(cl_s,holes=[h])),"PlaneSurface is colocated with PlaneSurface with deformed boundary")
1357            self.failUnless(not s.isColocated(PlaneSurface(cl,holes=[h2])),"PlaneSurface is colocated with modified hole")
1358    
1359            s.setLocalScale(3.)
1360            self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1361            self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1362            self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1363            self.failUnless(p3.getLocalScale()==3., "p3 has wrong local scale.")
1364            self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1365            self.failUnless(p5.getLocalScale()==3., "p5 has wrong local scale.")
1366            self.failUnless(p6.getLocalScale()==3., "p6 has wrong local scale.")
1367    
1368            p=s.getPrimitives()
1369            self.failUnless(len(p) == 17, "too many primitives.")
1370            self.failUnless(s in p, "cl is missing")
1371            self.failUnless(cl in p, "cl is missing")
1372            self.failUnless(h in p, "h is missing")
1373            self.failUnless(l0 in p, "l0 is missing")
1374            self.failUnless(l1 in p, "l1 is missing")
1375            self.failUnless(l2 in p, "l2 is missing")
1376            self.failUnless(l3 in p, "l3 is missing")
1377            self.failUnless(l4 in p, "l4 is missing")
1378            self.failUnless(l5 in p, "l5 is missing")
1379            self.failUnless(l6 in p, "l6 is missing")
1380            self.failUnless(p0 in p, "p0 is missing")
1381            self.failUnless(p1 in p, "p1 is missing")
1382            self.failUnless(p2 in p, "p2 is missing")
1383            self.failUnless(p3 in p, "p3 is missing")
1384            self.failUnless(p4 in p, "p4 is missing")
1385            self.failUnless(p5 in p, "p5 is missing")
1386            self.failUnless(p6 in p, "p6 is missing")
1387    
1388            sp=s.copy()
1389            self.failUnless(isinstance(sp,PlaneSurface), "copy returns is not a PlaneSurface.")
1390            self.failUnless(not sp == s, "copy equals source")
1391            self.failUnless(sp.isColocated(s),"copy is not colocated with its source.")
1392            cbl=sp.getBoundaryLoop()
1393            self.failUnless(not cbl == cl,"copy uses cl1.")
1394            hs=sp.getHoles()
1395            self.failUnless(len(hs)==1,"copy is missing holes.")
1396            self.failUnless(not hs[0]== h,"copy contains h as a hole.")
1397            cp=sp.getPrimitives()
1398            self.failUnless(len(cp) == 17, "copy as too many primitives.")
1399            self.failUnless(not s in cp, "copy contains s")
1400            self.failUnless(not cl in cp, "copy contains cl")
1401            self.failUnless(not h in cp, "copy contains h")
1402            self.failUnless(not l0 in cp, "copy contains l0")
1403            self.failUnless(not l1 in cp, "copy contains l1")
1404            self.failUnless(not l2 in cp, "copy contains l2")
1405            self.failUnless(not l3 in cp, "copy contains l3")
1406            self.failUnless(not l4 in cp, "copy contains l4")
1407            self.failUnless(not l5 in cp, "copy contains l5")
1408            self.failUnless(not l6 in cp, "copy contains l6")
1409            self.failUnless(not p0 in cp, "copy contains p0")
1410            self.failUnless(not p1 in cp, "copy contains p1")
1411            self.failUnless(not p2 in cp, "copy contains p2")
1412            self.failUnless(not p3 in cp, "copy contains p3")
1413            self.failUnless(not p4 in cp, "copy contains p4")
1414            self.failUnless(not p5 in cp, "copy contains p5")
1415            self.failUnless(not p6 in cp, "copy contains p6")
1416            del sp
1417            
1418    
1419            p0_m=Point(0,0,0,0.1)
1420            p1_m=Point(-10,0,0,0.2)
1421            p2_m=Point(-10,-10,0,0.3)
1422            p3_m=Point(0,-10,-3,0.4)
1423            p4_m=Point(-5,-5,0,0.001)
1424            p5_m=Point(-7,-5,0,0.001)
1425            p6_m=Point(-5,-7,0,0.001)
1426    
1427            l0_m=Line(p0_m,p1_m)
1428            l1_m=Line(p1_m,p2_m)
1429            l2_m=Line(p2_m,p3_m)
1430            l3_m=Line(p3_m,p0_m)
1431    
1432            l4_m=Line(p4_m,p5_m)
1433            l5_m=Line(p5_m,p6_m)
1434            l6_m=Line(p6_m,p4_m)
1435    
1436            cl_m=CurveLoop(l0_m,l1_m,l2_m,l3_m)
1437            h_m=CurveLoop(l4_m,l5_m,l6_m)
1438    
1439            ds=s.apply(Dilation(-1.))
1440            self.failUnless(ds.isColocated(PlaneSurface(cl_m,holes=[h_m])),"dilation is wrong.")
1441            cbl=ds.getBoundaryLoop()
1442            self.failUnless(not cbl == cl,"dilation uses cl1.")
1443            hs=ds.getHoles()
1444            self.failUnless(len(hs)==1,"dilation is missing holes.")
1445            self.failUnless(not hs[0]== h,"dilation contains h as a hole.")
1446            cp=ds.getPrimitives()
1447            self.failUnless(len(cp) == 17, "dilation as too many primitives.")
1448            self.failUnless(not s in cp, "dilation contains s")
1449            self.failUnless(not cl in cp, "dilation contains cl")
1450            self.failUnless(not h in cp, "dilation contains h")
1451            self.failUnless(not l0 in cp, "dilation contains l0")
1452            self.failUnless(not l1 in cp, "dilation contains l1")
1453            self.failUnless(not l2 in cp, "dilation contains l2")
1454            self.failUnless(not l3 in cp, "dilation contains l3")
1455            self.failUnless(not l4 in cp, "dilation contains l4")
1456            self.failUnless(not l5 in cp, "dilation contains l5")
1457            self.failUnless(not l6 in cp, "dilation contains l6")
1458            self.failUnless(not p0 in cp, "dilation contains p0")
1459            self.failUnless(not p1 in cp, "dilation contains p1")
1460            self.failUnless(not p2 in cp, "dilation contains p2")
1461            self.failUnless(not p3 in cp, "dilation contains p3")
1462            self.failUnless(not p4 in cp, "dilation contains p4")
1463            self.failUnless(not p5 in cp, "dilation contains p5")
1464            self.failUnless(not p6 in cp, "dilation contains p6")
1465    
1466            s.modifyBy(Dilation(-1.))
1467            self.failUnless(s.isColocated(PlaneSurface(cl_m,holes=[h_m])),"inplace dilation is wrong.")
1468            cbl=s.getBoundaryLoop()
1469            self.failUnless(cbl == cl,"inplace dilation does not use cl1.")
1470            hs=s.getHoles()
1471            self.failUnless(len(hs)==1,"inplace dilation is missing holes.")
1472            self.failUnless(hs[0]== h,"inplace dilation must contain h as a hole.")
1473            cp=s.getPrimitives()
1474            self.failUnless(len(cp) == 17, "inplace dilation as too many primitives.")
1475            self.failUnless(s in cp, "inplace dilation must use s")
1476            self.failUnless(cl in cp, "inplace dilation must use cl")
1477            self.failUnless(h in cp, "inplace dilation must use h")
1478            self.failUnless(l0 in cp, "inplace dilation must use l0")
1479            self.failUnless(l1 in cp, "inplace dilation must use l1")
1480            self.failUnless(l2 in cp, "inplace dilation must use l2")
1481            self.failUnless(l3 in cp, "inplace dilation must use l3")
1482            self.failUnless(l4 in cp, "inplace dilation must use l4")
1483            self.failUnless(l5 in cp, "inplace dilation must use l5")
1484            self.failUnless(l6 in cp, "inplace dilation must use l6")
1485            self.failUnless(p0 in cp, "inplace dilation must use p0")
1486            self.failUnless(p1 in cp, "inplace dilation must use p1")
1487            self.failUnless(p2 in cp, "inplace dilation must use p2")
1488            self.failUnless(p3 in cp, "inplace dilation must use p3")
1489            self.failUnless(p4 in cp, "inplace dilation must use p4")
1490            self.failUnless(p5 in cp, "inplace dilation must use p5")
1491            self.failUnless(p6 in cp, "inplace dilation must use p6")
1492    
1493       def test_SurfaceLoop(self):
1494            p0=Point( 0, 0, 0,0.1)
1495            p1=Point(10, 0, 0,0.1)
1496            p2=Point( 0,10, 0,0.1)
1497            p3=Point(10,10, 0,0.1)
1498            p4=Point( 0, 0,10,0.1)
1499            p5=Point(10, 0,10,0.1)
1500            p6=Point( 0,10,10,0.1)
1501            p7=Point(10,10,10,0.1)
1502    
1503            q0=Point( 4, 0, 4,0.1)
1504            q1=Point( 6, 0, 4,0.1)
1505            q2=Point( 4,10, 4,0.1)
1506            q3=Point( 6,10, 4,0.1)
1507            q4=Point( 4, 0, 6,0.1)
1508            q5=Point( 6, 0, 6,0.1)
1509            q6=Point( 4,10, 6,0.1)
1510            q7=Point( 6,10, 6,0.1)
1511    
1512            l01=Line(p0,p1)
1513            l15=Line(p1,p5)
1514            l54=Line(p5,p4)
1515            l04=Line(p4,p0)
1516    
1517            l31=Line(p3,p1)
1518            l57=Line(p3,p1)
1519    
1520            m01=Line(q0,q1)
1521            m15=Line(q1,q5)
1522            m54=Line(q5,q4)
1523            m04=Line(q4,q0)
1524    
1525            cl_l1=CurveLoop(l01,l15,l54,l04)
1526            cl_m1=CurveLoop(m01,m15,m54,m04)
1527            s1=PlaneSurface(cl_l1,holes=[cl_m1])
1528    
1529        
1530    
1531    
1532  if __name__ == '__main__':  if __name__ == '__main__':
1533     suite = unittest.TestSuite()     suite = unittest.TestSuite()
1534     suite.addTest(unittest.makeSuite(Test_PyCAD_Transformations))     suite.addTest(unittest.makeSuite(Test_PyCAD_Transformations))

Legend:
Removed from v.927  
changed lines
  Added in v.928

  ViewVC Help
Powered by ViewVC 1.1.26