Changeset 5950


Ignore:
Timestamp:
Nov 12, 2008, 1:45:50 PM (16 years ago)
Author:
duncan
Message:

fixing bad tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/mesh_engine/test_generate_mesh.py

    r5875 r5950  
    77
    88
    9 #FIXME (Ole): Go through this file and check that array's
    10 #             aren't compared using ==. Need to use either alltrue
    11 #             (on 1D integer arrays) or allclose.
    12  
    13 
    149import sys
    1510
     
    1712from anuga.mesh_engine.mesh_engine import generate_mesh
    1813
    19 from Numeric import array, Float, Int
     14from Numeric import array, Float, Int, alltrue, allclose
    2015
    2116from anuga.utilities.numerical_tools import ensure_numeric
     
    3025        pass
    3126
    32     def metestrectangleII(self):
    33 
    34         points = []
    35         seglist = []
    36         holelist = []
    37         regionlist = []
    38 
    39         points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
    40         pointattlist = [[],[],[],[]]
    41         regionlist.append( (1.2,1.2,5.0) )
    42         seglist = [(0,1),(1,3),(3,2),(2,0)]
    43         segattlist = [0,0,0,0]
    44        
    45         mode = "Qzp"
    46        
    47         points =  ensure_numeric(points, Float)
    48         seglist = test = ensure_numeric(seglist, Int)
    49         data = triang.genMesh(points,seglist,holelist,regionlist,
    50                               pointattlist,segattlist, mode, test)
    51         print "data", data
    52         self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
    53                         'trianglelist is wrong!')
    54         self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
    55                                                         (3, 2), (2, 0)],
    56                         'segmentlist is wrong!')
    57         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    58                                                       (3.0, 0.0), (3.0, 10.0)],
    59                         ' is wrong!')
    60 
    61 
    6227    def testrectangleIIb(self):
    63         # segattlist = []
     28       
    6429        points = []
    6530        seglist = []
     
    7843                              pointattlist,segattlist, mode, points)
    7944
    80         self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
     45        correct = array([(1, 0, 2), (2, 3, 1)])
     46        self.failUnless(alltrue(data['generatedtrianglelist'].flat == \
     47                                correct.flat),
    8148                        'trianglelist is wrong!')
    82         self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
    83                                                         (3, 2), (2, 0)],
     49        correct = array([(0, 1), (1, 3), (3, 2), (2, 0)])
     50        self.failUnless(alltrue(data['generatedsegmentlist'].flat == \
     51                                correct.flat),
    8452                        'segmentlist is wrong!')
    85         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    86                                                       (3.0, 0.0), (3.0, 10.0)],
    87                         ' is wrong!')
     53
     54        correct = array([(0.0, 0.0), (0.0, 10.0),
     55                         (3.0, 0.0), (3.0, 10.0)])
     56        self.failUnless(allclose(data['generatedpointlist'].flat, \
     57                                correct.flat),
     58                        'Failed')
    8859     
    8960    def testrectangleIIc(self):
    90         # segattlist = None
    9161        points = []
    9262        seglist = []
     
    10474        data = generate_mesh(points,seglist,holelist,regionlist,
    10575                              pointattlist,segattlist, mode, points)
    106 
    107         self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
     76        correct = array([(1, 0, 2), (2, 3, 1)])
     77        self.failUnless(alltrue(data['generatedtrianglelist'].flat == \
     78                                correct.flat),
    10879                        'trianglelist is wrong!')
    109         self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
    110                                                         (3, 2), (2, 0)],
     80        correct = array([(0, 1), (1, 3), (3, 2), (2, 0)])
     81        self.failUnless(alltrue(data['generatedsegmentlist'].flat == \
     82                                correct.flat),
    11183                        'segmentlist is wrong!')
    112         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    113                                                       (3.0, 0.0), (3.0, 10.0)],
    114                         ' is wrong!')
    115        
     84
     85        correct = array([(0.0, 0.0), (0.0, 10.0),
     86                         (3.0, 0.0), (3.0, 10.0)])
     87        self.failUnless(allclose(data['generatedpointlist'].flat, \
     88                                correct.flat),
     89                        'Failed')
     90
    11691    def test_bad_point_atts(self):
    11792
     
    179154                              pointattlist,segattlist, mode, points)
    180155
    181         self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
     156        correct = array([(1, 0, 2), (2, 3, 1)])
     157        self.failUnless(alltrue(data['generatedtrianglelist'].flat == \
     158                                correct.flat),
    182159                        'trianglelist is wrong!')
    183         self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
    184                                                         (3, 2), (2, 0)],
     160        correct = array([(0, 1), (1, 3), (3, 2), (2, 0)])
     161        self.failUnless(alltrue(data['generatedsegmentlist'].flat == \
     162                                correct.flat),
    185163                        'segmentlist is wrong!')
    186         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    187                                                       (3.0, 0.0), (3.0, 10.0)],
    188                         'generatedpointlist is wrong!')
    189         self.failUnless(data['generatedsegmentmarkerlist'] ==[1,2,3,4],
    190                         'generatedsegmentmarkerlist is wrong!')
    191 
     164
     165        correct = array([(0.0, 0.0), (0.0, 10.0),
     166                         (3.0, 0.0), (3.0, 10.0)])
     167        self.failUnless(allclose(data['generatedpointlist'].flat, \
     168                                correct.flat),
     169                        'Failed')
     170       
     171        self.failUnless(alltrue(data['generatedsegmentmarkerlist'] == \
     172                                array([1,2,3,4])),
     173                        'Failed!')
     174       
    192175    def testbad_region(self):
    193176
     
    317300
    318301    def testbad_segattlist(self):
    319 
    320302        holelist = []
    321303        regionlist = []
     
    330312            data = generate_mesh(points,seglist,holelist,regionlist,
    331313                                  pointattlist,segattlist, mode, points)
    332             print "data",data
    333             self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
    334                         'trianglelist is wrong!')
     314           
    335315        except ANUGAError:
    336316            pass
     
    358338                              pointattlist,segattlist, mode, points)
    359339
    360         self.failUnless(data['generatedtriangleattributelist'] ==[[77.0], [77.0], [77.0], [77.0]],
    361                         'triangleattributelist is wrong!')
    362 
     340        correct = array([[77.0], [77.0], [77.0], [77.0]])
     341        self.failUnless(allclose(data['generatedtriangleattributelist'].flat,
     342                                 correct.flat),
     343                        'Failed')
     344       
    363345    def testrectangle_regionsII(self):
    364346        points = []
     
    380362                              pointattlist,segattlist, mode, points)
    381363
    382         self.failUnless(data['generatedtriangleattributelist'] ==[[77.0], [77.0], [77.0], [77.0]],
    383                         'triangleattributelist is wrong!')
    384 
    385 
    386     def BADtest_lone_verts(self):
    387         print "test_lone_verts"
    388         points = []
    389         seglist = []
    390         holelist = []
    391         regionlist = []
    392 
    393         points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0),(0.0,10.0)]
    394         pointattlist = [[],[],[],[],[]]
    395         regionlist.append( (1.2,1.2,5.0) )
    396         seglist = [(0,4),(4,1),(1,3),(3,2),(2,0)]
    397         segattlist = [0,0,0,0,0]
    398        
    399         mode = "QpznAa2000.1a"
    400         data = generate_mesh(points,seglist,holelist,regionlist,
    401                               pointattlist,segattlist, mode, points)
    402         #print "data['generatedtrianglelist']", data['generatedtrianglelist']
    403         self.failUnless(data['generatedtrianglelist'] ==[(4, 0, 2), (2, 3, 4)],
    404                         'trianglelist is wrong!')
    405         self.failUnless(data['generatedsegmentlist'] ==[(0, 4), (4, 3),
    406                                                         (3, 2), (2, 0)],
    407                         'segmentlist is wrong!')
    408         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    409                                                       (3.0, 0.0), (3.0, 10.0),
    410                                                       (0.0,10.0)],
    411                         ' is wrong!')
    412         #print "data['lonepointlist']", data['lonepointlist']
    413         self.failUnless(data['lonepointlist'] ==[1],
    414                         'lonepointlist is wrong!')
    415 
    416     def dont_test_lone_vertsII(self):
    417 
    418         points = []
    419         seglist = []
    420         holelist = []
    421         regionlist = []
    422 
    423         points = [(0.0,0.0),(0.0,0.0),(0.0,10.0),(0.0,10.0),(10.0,10.0),
    424                   (10.0,10.0),(0.0,10.0),(10.0,0.0)]
    425 
    426         pointattlist = []
    427         for point in points:
    428             pointattlist.append([])
    429         seglist = [(0,1),(1,2),(2,3),(3,4),(4,5),(5,7),(7,0)]
    430         segattlist = []
    431         for seg in seglist:
    432             segattlist.append(0)
    433        
    434         mode = "QpznAa2000.1a"
    435         data = generate_mesh(points,seglist,holelist,regionlist,
    436                               pointattlist,segattlist, mode, points)
    437         #print "data['generatedtrianglelist']", data['generatedtrianglelist']
    438         self.failUnless(data['generatedtrianglelist'] ==[(6, 1, 7), (7, 5, 6)],
    439                         'trianglelist is wrong!')
    440         self.failUnless(data['generatedsegmentlist'] ==[(1, 6), (6, 5),
    441                                                         (5, 7), (7, 1)],
    442                         'segmentlist is wrong!')
    443         self.failUnless(data['generatedpointlist'] ==[(0.0,0.0),(0.0,0.0),
    444                                                       (0.0,10.0),(0.0,10.0),
    445                                                       (10.0,10.0),
    446                                                       (10.0,10.0),(0.0,10.0),
    447                                                       (10.0,0.0)],
    448                         ' is wrong!')
    449         self.failUnless(data['lonepointlist'] ==[0,2,3,4],
    450                         'lonepointlist is wrong!')
    451 
    452     def dont_test_lone_vertsIII(self):
    453 
    454         points = []
    455         seglist = []
    456         holelist = []
    457         regionlist = []
    458 
    459         points = [(-3.,-5.),(0.0,0.0),(0.0,0.0),
    460                   (-5.,-8.),(0.0,10.0),(0.0,10.0),
    461                   (-3.,-5.),(10.0,10.0), (10.0,10.0),
    462                   (0.0,10.0),
    463                   (10.0,0.0),
    464                   (-12.,45.)]
    465 
    466         pointattlist = []
    467         for point in points:
    468             pointattlist.append([])
    469         seglist = [(1,2),(2,4),(4,5),(5,7),(7,8),(8,10),(10,1)]
    470         segattlist = []
    471         for seg in seglist:
    472             segattlist.append(0)
    473             """
    474             0 1
    475             1 2
    476             2 4
    477             3 5
    478             4 7
    479             5 8
    480             6 9
    481             7 10
    482             """
    483        
    484         mode = "QpznAa2000.1a"
    485         data = generate_mesh(points,seglist,holelist,regionlist,
    486                               pointattlist,segattlist, mode, points)
    487         #print "data['generatedtrianglelist']", data['generatedtrianglelist']
    488         #self.failUnless(data['generatedtrianglelist'] ==[(9, 2, 10),
    489          #                                                (10, 8, 9)],
    490           #              'trianglelist is wrong!')
    491         self.failUnless(data['generatedtrianglelist'] ==[(2, 10, 8),
    492                                                          (8, 9, 2)],
    493                         'trianglelist is wrong!')
    494         #print "data['generatedsegmentlist']",data['generatedsegmentlist']
    495         self.failUnless(data['generatedsegmentlist'] ==[(9, 2), (9, 8),
    496                                                         (8, 10), (2, 10)],
    497                         'segmentlist is wrong!')
    498         self.failUnless(data['generatedpointlist'] ==points,
    499                         ' is wrong!')
    500         self.failUnless(data['lonepointlist'] ==[0,1,3,4,5,6,7,11],
    501                         'lonepointlist is wrong!')
    502        
    503     def dont_test_lone_verts4(self):
    504         points = []
    505         seglist = []
    506         holelist = []
    507         regionlist = []
    508 
    509         points = [(-56.,-78),(0.0,0.0),(0.0,10.0),(10.,0.)]
    510         pointattlist = []
    511         seglist = [(1,2),(2,3),(3,1)]
    512         segattlist = []
    513        
    514         mode = "QpznAa2000.1a"
    515         data = generate_mesh(points,seglist,holelist,regionlist,
    516                               pointattlist,segattlist, mode, points)
    517         #print "data['generatedtrianglelist']", data['generatedtrianglelist']
    518         #self.failUnless(data['generatedtrianglelist'] ==[(4, 0, 2),(2, 3, 4)],
    519         #               'trianglelist is wrong!')
    520         print "seglist", seglist
    521         print "data['generatedsegmentlist']", data['generatedsegmentlist']
    522         print "points", points
    523         print "data['generatedpointlist'] ",data['generatedpointlist']
    524         print "points", points
    525         self.failUnless(data['generatedsegmentlist'] ==seglist,
    526                         'segmentlist is wrong!')
    527         self.failUnless(data['generatedpointlist'] ==points,
    528                         ' is wrong!')
    529         #print "data['lonepointlist']", data['lonepointlist']
    530         self.failUnless(data['lonepointlist'] ==[0],
    531                         'lonepointlist is wrong!')
    532 
    533 
    534 
    535     def dont_test_transition_to_arrays(self):
     364        correct = array([[77.0], [77.0], [77.0], [77.0]])
     365        self.failUnless(allclose(data['generatedtriangleattributelist'].flat,
     366                                 correct.flat),
     367                        'Failed')
     368
     369
     370    def test_numeric_arrays(self):
    536371        points = []
    537372        seglist = []
     
    541376        pointattlist = []
    542377        # 5.0 is the region tag, 99.0 is the max area
    543         regionlist.append( [0.2,0.2,5.0,99.0] )
     378        tri_tag = 123456.0
     379        regionlist.append( [0.2,0.2, tri_tag,99.0] )
    544380        seglist = [(0,1),(1,3),(3,2),(2,0)]
    545381        segattlist = [21,22,23,24]
     
    551387        #print "data", data
    552388
    553         self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
     389     
     390        correct = array([(1, 0, 2), (2, 3, 1)])
     391        self.failUnless(alltrue(data['generatedtrianglelist'].flat == \
     392                                correct.flat),
    554393                        'trianglelist is wrong!')
    555         self.failUnless(data['generatedtrianglelist'] ==data['trianglelist'],
    556                         'trianglelist is wrong!')
    557         self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
    558                                                         (3, 2), (2, 0)],
     394        correct = array([(0, 1), (1, 3), (3, 2), (2, 0)])
     395        self.failUnless(alltrue(data['generatedsegmentlist'].flat == \
     396                                correct.flat),
    559397                        'segmentlist is wrong!')
    560         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    561                                                       (3.0, 0.0), (3.0, 10.0)],
    562                         ' is wrong!')
    563         self.failUnless(data['generatedpointlist'] ==data['pointlist'],
    564                         ' is wrong!')
    565         self.failUnless(data['generatedtriangleattributelist'] == [[5.0],
    566                                                                    [5.0]],
    567                         ' is wrong!')
    568        
    569         self.failUnless(data['generatedtriangleattributelist'] == \
    570                         data['triangleattributelist'],
    571                         ' is wrong!')
    572         self.failUnless(data['generatedsegmentlist'] == seglist,
    573                         ' is wrong!')
    574         self.failUnless(data['generatedsegmentlist'] == data['segmentlist'],
    575                         ' is wrong!')
    576         self.failUnless(data['generatedsegmentmarkerlist'] == segattlist,
    577                         ' is wrong!')
    578         self.failUnless(data['generatedsegmentmarkerlist'] == \
    579                         data['segmentmarkerlist'],
    580                         ' is wrong!')
     398
     399        correct = array([(0.0, 0.0), (0.0, 10.0),
     400                         (3.0, 0.0), (3.0, 10.0)])
     401        self.failUnless(allclose(data['generatedpointlist'].flat, \
     402                                correct.flat),
     403                        'Failed')
     404       
     405        correct = array([[tri_tag], [tri_tag]])
     406        self.failUnless(allclose(data['generatedtriangleattributelist'].flat, \
     407                                correct.flat),
     408                        'Failed')
     409        correct = array([(0, 1), (1, 3), (3, 2), (2, 0)])
     410        self.failUnless(alltrue(data['generatedsegmentlist'].flat == \
     411                                correct.flat),
     412                        'Failed!')
     413       
     414        correct = array(segattlist)
     415        self.failUnless(allclose(data['generatedsegmentmarkerlist'].flat,
     416                                 correct.flat),
     417                        'Failed')
     418       
    581419        # I copied these answers from the output, so bad test..
    582         self.failUnless(data['generatedtriangleneighborlist'] == \
    583                         [(-1, 1, -1), (-1, 0, -1)],
    584                         ' is wrong!')
    585         self.failUnless(data['generatedtriangleneighborlist'] == \
    586                         data['triangleneighborlist'],
    587                         ' is wrong!')
    588        
    589     def test_numeric_arrays(self):
    590         points = []
    591         seglist = []
    592         holelist = []
    593         regionlist = []
    594         points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
    595         pointattlist = []
    596         # 5.0 is the region tag, 99.0 is the max area
    597         tri_tag = 123456.0
    598         regionlist.append( [0.2,0.2, tri_tag,99.0] )
    599         seglist = [(0,1),(1,3),(3,2),(2,0)]
    600         segattlist = [21,22,23,24]
    601          #The 'A' has to be there to get the region marker stuff working
    602         mode = "QzpnA"
    603         #mode = "jQpznAa2000.1a"
    604         data = generate_mesh(points,seglist,holelist,regionlist,
    605                               pointattlist,segattlist, mode, points)
    606         #print "data", data
    607 
    608         self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
    609                         'trianglelist is wrong!')
    610         self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
    611                                                         (3, 2), (2, 0)],
    612                         'segmentlist is wrong!')
    613         self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
    614                                                       (3.0, 0.0), (3.0, 10.0)],
    615                         ' is wrong!')
    616         self.failUnless(data['generatedtriangleattributelist'] == [[tri_tag],
    617                                                                    [tri_tag]],
    618                         ' is wrong!')
    619        
    620         self.failUnless(data['generatedsegmentlist'] == seglist,
    621                         ' is wrong!')
    622         self.failUnless(data['generatedsegmentmarkerlist'] == segattlist,
    623                         ' is wrong!')
    624         # I copied these answers from the output, so bad test..
    625         self.failUnless(data['generatedtriangleneighborlist'] == \
    626                         [(-1, 1, -1), (-1, 0, -1)],
    627                         ' is wrong!')
     420        correct = array([(-1, 1, -1), (-1, 0, -1)])
     421        self.failUnless(alltrue(data['generatedtriangleneighborlist'].flat == \
     422                                correct.flat),
     423                        'Failed!')
     424       
    628425       
    629426    def test_pointattlist(self):
     
    642439        data = generate_mesh(points,seglist,holelist,regionlist,
    643440                              pointattlist,segattlist, mode, points)
    644         self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0],
    645                                                                 [10],[10]],
    646                         ' is wrong!')
    647        
     441
     442        correct = array([[0.0],[0.0],[10],[10]])
     443        self.failUnless(allclose(data['generatedpointattributelist'].flat, \
     444                                correct.flat),
     445                        'Failed')
    648446       
    649447        pointattlist = [[0.],[0.],[10.],[10.]]
     
    651449        data = generate_mesh(points,seglist,holelist,regionlist,
    652450                              pointattlist,segattlist, mode, points)
    653         self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0],
    654                                                                 [10],[10]],
    655                         ' is wrong!')
     451        correct = array([[0.0],[0.0],[10],[10]])
     452        self.failUnless(allclose(data['generatedpointattributelist'].flat, \
     453                                correct.flat),
     454                        'Failed')
     455       
    656456        pointattlist = [[0.,1],[0.,1],[10.,20],[10.,20]]
    657457        mode = "Qzp"       
     
    659459                              pointattlist,segattlist, mode, points)
    660460        #print "data", data
    661         self.failUnless(data['generatedpointattributelist'] == pointattlist,
    662                         ' is wrong!')
    663            
    664     def dont_test_transition_pointattlist(self):
    665         # segattlist = []
    666         points = []
    667         seglist = []
    668         holelist = []
    669         regionlist = []
    670 
    671         points = [(0.0,0.0),(0.0,4.0),(4.0,2.0),(2.0,0.0)]
    672         pointattlist = [0.,0.,10.,10.]
    673         regionlist.append( [0.2,0.2,2.1, 99.] )
    674         seglist = [(0,1),(1,2),(2,3),(3,0)]
    675         segattlist = [11,12,13,14]
    676         mode = "Qzp"
    677         data = generate_mesh(points,seglist,holelist,regionlist,
    678                               pointattlist,segattlist, mode, points)
    679         self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0],
    680                                                                 [10],[10]],
    681                         ' is wrong!')
    682         self.failUnless(data['generatedpointattributelist'] == \
    683                         data['pointattributelist'],
    684                         ' is wrong!')
    685        
    686        
    687         pointattlist = [[0.],[0.],[10.],[10.]]
    688         mode = "Qzp"       
    689         data = generate_mesh(points,seglist,holelist,regionlist,
    690                               pointattlist,segattlist, mode, points)
    691         self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0],
    692                                                                 [10],[10]],
    693                         ' is wrong!')
    694         self.failUnless(data['generatedpointattributelist'] == \
    695                         data['pointattributelist'],
    696                         ' is wrong!')
    697         pointattlist = [[0.,1],[0.,1],[10.,20],[10.,20]]
    698         mode = "Qzp"       
    699         data = generate_mesh(points,seglist,holelist,regionlist,
    700                               pointattlist,segattlist, mode, points)
    701         #print "data", data
    702         self.failUnless(data['generatedpointattributelist'] == pointattlist,
    703                         ' is wrong!')
    704         self.failUnless(data['generatedpointattributelist'] == \
    705                         data['pointattributelist'],
    706                         ' is wrong!')
     461        correct = array(pointattlist)
     462        self.failUnless(allclose(data['generatedpointattributelist'].flat, \
     463                                correct.flat),
     464                        'Failed')
    707465     
    708466if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.