Changeset 429


Ignore:
Timestamp:
Oct 20, 2004, 2:26:43 PM (20 years ago)
Author:
duncan
Message:

added test for bug in writting .tsh file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r424 r429  
    117117       
    118118
    119            
    120     def teszt_more_triangles(self):
     119    # this causes a memory error in scipy.sparce       
     120    def bad_test_more_triangles(self):
    121121        print "dd"
    122122        a = [-1.0, 0.0]
     
    146146
    147147
    148     def test_smooth_attributes_to_mesh(self):
     148    def teszt_smooth_attributes_to_mesh(self):
    149149        print "ee"
    150150        a = [0.0, 0.0]
     
    162162        data_coords = [d1, d2, d3]
    163163       
    164         interp = Interpolation(points, triangles, data_coords, alpha=0.0000005)
     164        interp = Interpolation(points, triangles, data_coords, alpha=5.0e-7)
    165165        z = [z1, z2, z3]
    166166        f = interp.fit(z)
    167167        answer = [0, 5., 5.]
    168        
    169168        assert allclose(f, answer)
    170169       
     
    562561
    563562    def test_fit_to_mesh_file(self):
     563        from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \
     564             export_trianglulation_file   
     565        import tempfile
     566        import os
     567       
     568        # create a .tsh file, no user outline
     569        mesh_dic = {}
     570        mesh_dic['generatedpointlist'] = [[0.0, 0.0],
     571                                          [0.0, 5.0],
     572                                          [5.0, 0.0]]
     573        mesh_dic['generatedtrianglelist'] =  [[0, 2, 1]]
     574        mesh_dic['generatedsegmentlist'] = [[0, 1], [2, 0], [1, 2]]
     575        mesh_dic['generatedtriangleattributelist'] = [['']]
     576        mesh_dic['generatedpointattributelist'] = [[], [], []]
     577        mesh_dic['generatedpointattributetitlelist'] = []
     578        mesh_dic['generatedtriangleneighborlist'] = [[-1, -1, -1]]
     579        mesh_dic['generatedsegmentmarkerlist'] = ['external',
     580                                                  'external',
     581                                                  'external']       
     582        mesh_file = tempfile.mktemp(".tsh")
     583        export_trianglulation_file(mesh_file,mesh_dic)
     584       
     585        # create an .xya file
     586        point_file = tempfile.mktemp(".xya")
     587        fd = open(point_file,'w')
     588        fd.write("elevation, stage \n 1.0, 1.0,2.,4 \n 1.0, 3.0,4,8 \n 3.0,1.0,4.,8 \n")
     589        fd.close()
     590       
     591        mesh_output_file = "new_trianlge.tsh"
     592        fit_to_mesh_file(mesh_file,
     593                         point_file,
     594                         mesh_output_file,
     595                         alpha = 0.0) 
     596        # load in the .tsh file we just wrote
     597        mesh_dic = mesh_file_to_mesh_dictionary(mesh_output_file)
     598
     599        assert allclose(mesh_dic['generatedpointattributelist'],
     600                        [[0.0, 0.0],
     601                         [5.0, 10.0],
     602                         [5.0,10.0]])
     603       
     604        self.failUnless(mesh_dic['generatedpointattributetitlelist']  ==
     605                        ['elevation','stage'],
     606                        'test_fit_to_mesh_file failed')
     607       
     608        #clean up
     609        os.remove(mesh_file)
     610        os.remove(point_file)
     611       
     612    def test_fit_to_mesh_fileII(self):
    564613        from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \
    565614             export_trianglulation_file   
     
    613662#-------------------------------------------------------------
    614663if __name__ == "__main__":
    615     suite = unittest.makeSuite(TestCase,'test')
     664    suite = unittest.makeSuite(TestCase,'teszt')
    616665    runner = unittest.TextTestRunner()
    617666    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.