Index: /inundation/ga/storm_surge/pmesh/test_mesh.py
===================================================================
--- /inundation/ga/storm_surge/pmesh/test_mesh.py	(revision 1229)
+++ /inundation/ga/storm_surge/pmesh/test_mesh.py	(revision 1229)
@@ -0,0 +1,229 @@
+#!/usr/bin/env python
+
+import unittest
+
+import mesh
+
+
+class TestCase(unittest.TestCase):
+    def setUp(self):
+        pass
+        
+    def tearDown(self):
+        pass
+
+    def test_set_stuff(self):
+        """
+        Documentation
+        """
+        #making a test mesh
+        p0=[0.,2.]
+        p1=[1.,2.]
+        p2=[0.,1.]
+        p3=[1.,1.]
+        p4=[0.,0.]
+        p5=[2.,0.]
+        p6=[-1.,1.]
+        point_list = [p0,p1,p2,p3,p4,p5,p6]
+
+        a0=[0]
+        a1=[0]
+        a2=[100]
+        a3=[0]
+        a4=[0]
+        a5=[0]
+        a6=[0]
+        attribute=[a0,a1,a2,a3,a4,a5,a6]
+        
+        t0=[0,3,1]
+        t1=[0,2,3]
+        t2=[2,4,3]
+        t3=[4,5,3]
+        t4=[1,3,5]
+        t5=[2,6,4]
+
+        n0=[4,-1,2]
+        n1=[2,0,-1]
+        n2=[3,1,5]
+        n3=[4,2,-1]
+        n4=[3,-1,0]
+        n5=[-1,2,-1]
+
+        tri_list = [t0,t1,t2,t3,t4,t5]
+        n_list = [n0,n1,n2,n3,n4,n5]
+        for i in range(6):
+            for j in (0,1,2):
+                a=attribute[tri_list[i][j]]
+                tri_list[i][j]=point_list[tri_list[i][j]]
+                tri_list[i][j]=mesh.Vertex(tri_list[i][j][0]\
+                                      ,tri_list[i][j][1],a)
+            neighbours=n_list[i]
+            tri_list[i]=mesh.Triangle(tri_list[i][0],\
+                                 tri_list[i][1],tri_list[i][2]\
+                                ,neighbors=neighbours)
+
+        #testing selectAll
+        Mesh = mesh.Mesh()
+        Mesh.attributeTitles=['attrib']
+
+        Mesh.meshTriangles=tri_list
+
+        Mesh.selectAllTriangles()
+        A=Mesh.sets[Mesh.setID['All']]
+        assert list_comp(tri_list,A)
+
+       #testing threshold
+        Mesh = mesh.Mesh()
+        Mesh.attributeTitles=['attrib']
+
+        Mesh.meshTriangles=tri_list
+        Mesh.selectAllTriangles()
+        Mesh.threshold('All',min=30,max=35,attribute_name = 'attrib')
+        A = [tri_list[1],tri_list[2],tri_list[5]]
+        B = Mesh.sets[Mesh.setID['All']]
+        assert list_comp(A,B)
+       
+
+        A = [tri_list[3],tri_list[2],tri_list[5]]
+        assert not list_comp(A,B)
+
+        #testing 
+
+    def test_Discretised_Tuple_Set_rounding(self):
+        #This is the hardest bit of DST
+        from mesh import Discretised_Tuple_Set
+
+        tol = 0.1
+        a=Discretised_Tuple_Set(p_rel=1,t_rel= tol)
+        m = 0.541
+        m_up = 0.6
+        m_down = 0.5
+        assert m_up == a.round_up_rel(m)
+        assert m_down == a.round_down_rel(m)
+
+        tol = 0.1
+        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
+        m = 0.539
+        m_up = 0.5
+        m_down = 0.5
+        assert m_up == a.round_up_rel(m)
+        assert m_down == a.round_down_rel(m)
+
+        tol = 0.5
+        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
+
+
+        m = 0.6
+        m_up = 0.7
+        m_down = 0.5
+        assert m_up == a.round_up_rel(m)
+        assert m_down == a.round_down_rel(m)
+
+        m = 0.599
+        m_up = 0.6
+        m_down = 0.5
+        assert m_up == a.round_up_rel(m)
+        assert m_down == a.round_down_rel(m)
+
+    def test_Discretised_Tuple_Set_tuple_rounding(self):
+        from mesh import Discretised_Tuple_Set
+
+        tol = 0.25
+        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
+        b = (1.,1.)
+        list = [(1.,1.)]
+        assert list_comp(list,a.rounded_keys(b))
+
+        b = (1.1,1.)
+        list = [(1.2,1.),(1.,1.)]
+        assert list_comp(list,a.rounded_keys(b))
+
+        b = (1.1,1.1)
+        list = [(1.2,1.),(1.,1.),(1.,1.2),(1.2,1.2)]
+        assert list_comp(list,a.rounded_keys(b))
+
+
+    def test_Discretised_Tuple_Set_set(self):
+        from mesh import Discretised_Tuple_Set
+        tol = 0.25
+        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
+        b = (1.1,1.1)
+        a.append(b)
+        list = [(1.2,1.),(1.,1.),(1.,1.2),(1.2,1.2)]
+        assert list_comp(list,a.keys())
+
+    def test_Discretised_Tuple_Set_get(self):
+        from mesh import Discretised_Tuple_Set
+        tol = 0.25
+        a=Discretised_Tuple_Set(p_rel=1,t_rel = tol)
+        b = (1.1,1.1)
+        a.append(b)
+        list = [(1.2,1.),(1.,1.),(1.,1.2),(1.2,1.2)]
+        for key in list:
+            assert a[key][0]==b
+            assert len(a[key])==1
+        
+        c = (2.1,1.)
+        a.append(c)
+        assert a[(2.,1.)][0]==c
+        assert a[(2.2,1.)][0]==c
+
+    def test_mapped_Discretised_Tuple_Set(self):
+
+        from mesh import Mapped_Discretised_Tuple_Set
+        from mesh import Discretised_Tuple_Set
+
+        def map(sequence):
+            return [len(sequence)]
+
+        tol = 0.5
+        a=Mapped_Discretised_Tuple_Set(map,p_rel=1,t_rel = tol)
+        b = range(20)
+        a.append(b)
+        assert b in a[range(17)] 
+        assert b in a[range(22)]
+
+        tol = 0.01
+        a=Mapped_Discretised_Tuple_Set(map,p_rel=1,t_rel = tol)
+        b = range(20)
+        a.append(b)
+        assert b in a[range(20)] 
+        assert b in a[range(19)] 
+        assert not range(17) in a
+
+
+
+
+"""
+        print 'A'
+        for triangle in A:
+            print tri_list.index(triangle)
+            print triangle
+        print ''
+        print 'B'
+        for triangle in B:
+            print tri_list.index(triangle)
+            print triangle
+        print ''
+"""
+
+
+
+def list_comp(A,B):
+    yes = len(A)==len(B)
+    #print "A"
+    #for item in A:
+    #    print item
+    #print "B"
+    #for item in B:
+    #    print item
+    for item in A:
+        if not item in B:
+            yes = False
+    return yes
+
+#-------------------------------------------------------------
+if __name__ == "__main__":
+    suite = unittest.makeSuite(TestCase,'test')
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
