Changeset 1361


Ignore:
Timestamp:
May 10, 2005, 4:15:53 PM (20 years ago)
Author:
duncan
Message:

moving tests..

Location:
inundation/ga/storm_surge/pmesh
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pmesh/meshHarness.py

    r1185 r1361  
    14111411            self.failUnless( regmaxarea == regactual.getMaxArea(),
    14121412                        'loadASCIITestCase failed. test 7')
    1413    
     1413
     1414
     1415#___________begining of Peters tests
     1416
     1417    def test_set_stuff(self):
     1418        """
     1419        Documentation
     1420        """
     1421        #making a test mesh
     1422        p0=[0.,2.]
     1423        p1=[1.,2.]
     1424        p2=[0.,1.]
     1425        p3=[1.,1.]
     1426        p4=[0.,0.]
     1427        p5=[2.,0.]
     1428        p6=[-1.,1.]
     1429        point_list = [p0,p1,p2,p3,p4,p5,p6]
     1430
     1431        a0=[0]
     1432        a1=[0]
     1433        a2=[100]
     1434        a3=[0]
     1435        a4=[0]
     1436        a5=[0]
     1437        a6=[0]
     1438        attribute=[a0,a1,a2,a3,a4,a5,a6]
     1439       
     1440        t0=[0,3,1]
     1441        t1=[0,2,3]
     1442        t2=[2,4,3]
     1443        t3=[4,5,3]
     1444        t4=[1,3,5]
     1445        t5=[2,6,4]
     1446
     1447        n0=[4,-1,2]
     1448        n1=[2,0,-1]
     1449        n2=[3,1,5]
     1450        n3=[4,2,-1]
     1451        n4=[3,-1,0]
     1452        n5=[-1,2,-1]
     1453
     1454        tri_list = [t0,t1,t2,t3,t4,t5]
     1455        n_list = [n0,n1,n2,n3,n4,n5]
     1456        for i in range(6):
     1457            for j in (0,1,2):
     1458                a=attribute[tri_list[i][j]]
     1459                tri_list[i][j]=point_list[tri_list[i][j]]
     1460                tri_list[i][j]=Vertex(tri_list[i][j][0]\
     1461                                      ,tri_list[i][j][1],a)
     1462            neighbours=n_list[i]
     1463            tri_list[i]=Triangle(tri_list[i][0],\
     1464                                 tri_list[i][1],tri_list[i][2]\
     1465                                ,neighbors=neighbours)
     1466
     1467        #testing selectAll
     1468        mesh = Mesh()
     1469        mesh.attributeTitles=['attrib']
     1470
     1471        mesh.meshTriangles=tri_list
     1472
     1473        mesh.selectAllTriangles()
     1474        A=mesh.sets[mesh.setID['All']]
     1475        assert list_comp(tri_list,A)
     1476
     1477       #testing threshold
     1478        mesh = Mesh()
     1479        mesh.attributeTitles=['attrib']
     1480
     1481        mesh.meshTriangles=tri_list
     1482        mesh.selectAllTriangles()
     1483        mesh.threshold('All',min=30,max=35,attribute_name = 'attrib')
     1484        A = [tri_list[1],tri_list[2],tri_list[5]]
     1485        B = mesh.sets[mesh.setID['All']]
     1486        assert list_comp(A,B)
     1487       
     1488
     1489        A = [tri_list[3],tri_list[2],tri_list[5]]
     1490        assert not list_comp(A,B)
     1491
     1492        #testing
     1493
     1494    def test_Discretised_Tuple_Set_rounding(self):
     1495        #This is the hardest bit of DST
     1496        from mesh import Discretised_Tuple_Set
     1497
     1498        tol = 0.1
     1499        a=Discretised_Tuple_Set(p_rel=1,t_rel= tol)
     1500        m = 0.541
     1501        m_up = 0.6
     1502        m_down = 0.5
     1503        assert m_up == a.round_up_rel(m)
     1504        assert m_down == a.round_down_rel(m)
     1505
     1506        tol = 0.1
     1507        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
     1508        m = 0.539
     1509        m_up = 0.5
     1510        m_down = 0.5
     1511        assert m_up == a.round_up_rel(m)
     1512        assert m_down == a.round_down_rel(m)
     1513
     1514        tol = 0.5
     1515        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
     1516
     1517
     1518        m = 0.6
     1519        m_up = 0.7
     1520        m_down = 0.5
     1521        assert m_up == a.round_up_rel(m)
     1522        assert m_down == a.round_down_rel(m)
     1523
     1524        m = 0.599
     1525        m_up = 0.6
     1526        m_down = 0.5
     1527        assert m_up == a.round_up_rel(m)
     1528        assert m_down == a.round_down_rel(m)
     1529
     1530    def test_Discretised_Tuple_Set_get(self):
     1531        from mesh import Discretised_Tuple_Set
     1532        tol = 0.25
     1533        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
     1534        b = (1.1,1.1)
     1535        a.append(b)
     1536        list = [(1.2,1.),(1.,1.),(1.,1.2),(1.2,1.2)]
     1537        for key in list:
     1538            assert a[key][0]==b
     1539            assert len(a[key])==1
     1540       
     1541        c = (2.1,1.)
     1542        a.append(c)
     1543        assert a[(2.,1.)][0]==c
     1544        assert a[(2.2,1.)][0]==c
     1545
     1546    def test_mapped_Discretised_Tuple_Set(self):
     1547
     1548        from mesh import Mapped_Discretised_Tuple_Set
     1549        from mesh import Discretised_Tuple_Set
     1550
     1551        def map(sequence):
     1552            return [len(sequence)]
     1553
     1554        tol = 0.5
     1555        a=Mapped_Discretised_Tuple_Set(map,p_rel=1,t_rel = tol)
     1556        b = range(20)
     1557        a.append(b)
     1558        assert b in a[range(17)]
     1559        assert b in a[range(22)]
     1560
     1561        tol = 0.01
     1562        a=Mapped_Discretised_Tuple_Set(map,p_rel=1,t_rel = tol)
     1563        b = range(20)
     1564        a.append(b)
     1565        assert b in a[range(20)]
     1566        assert b in a[range(19)]
     1567        assert not range(17) in a
     1568
     1569
     1570def list_comp(A,B):
     1571    yes = len(A)==len(B)
     1572    for item in A:
     1573        if not item in B:
     1574            yes = False
     1575    return yes
     1576
     1577#___________end of Peters tests
    14141578           
    14151579#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.