added unittest to verify good connectivity generation; should be failing tests

This commit is contained in:
Stephen M. McQuay 2012-07-13 08:43:08 -06:00
parent 3fb1c97403
commit 3f927477e9
3 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1 @@
{"edges": [[4, 5], [5, 1], [1, 0], [0, 4], [5, 6], [6, 2], [2, 1], [6, 7], [7, 3], [3, 2], [7, 4], [0, 3]], "vertices": [[-1.0, -1.0, -1.0], [-1.0, 1.0, -1.0], [1.0, 1.0, -1.0], [1.0, -1.0, -1.0], [-1.0, -1.0, 1.0], [-1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, -1.0, 1.0]], "faces": [[4, 5, 1, 0], [5, 6, 2, 1], [6, 7, 3, 2], [7, 4, 0, 3], [0, 1, 2, 3], [7, 6, 5, 4]]}

View File

@ -207,6 +207,8 @@ class PolygonMesh(object):
'vertices': self.vertices,
'edges': self.edges,
'faces': self.faces,
'faces_for_vert': self.faces_for_vert,
'edges_for_vert': self.edges_for_vert,
}
return json.dumps(d)

View File

@ -11,17 +11,38 @@ class TestPM(unittest.TestCase):
path, file_name = os.path.split(__file__)
self.samples_dir = os.path.join(path, os.pardir, os.pardir,
'blender', 'samples')
cube_file_name = os.path.join(self.samples_dir, 'cube.json')
full_cube_file_name = os.path.join(self.samples_dir, 'cube.json')
with open(full_cube_file_name) as cube_file:
self.full_cube = json.load(cube_file)
cube_file_name = os.path.join(self.samples_dir, 'cube-no-connectivity.json')
with open(cube_file_name) as cube_file:
self.cube = json.load(cube_file)
self.skeleton_cube = json.load(cube_file)
self.skel = PolygonMesh(**self.skeleton_cube)
self.cube = PolygonMesh(**self.full_cube)
def test_cube_load(self):
p = PolygonMesh(**self.cube)
p = PolygonMesh(**self.full_cube)
v = p.vertices[0]
self.assertAlmostEqual(v.x, -1.0)
self.assertAlmostEqual(v.y, -1.0)
self.assertAlmostEqual(v.z, -1.0)
def test_connectivity(self):
self.skel.faces_for_vert
self.skel.edges_for_vert
self.skel.edges_for_face
self.skel.faces_for_edge
def test_faces_for_vert(self):
for pi, qi in zip(self.skel.faces_for_vert, self.cube.faces_for_vert):
self.assertEqual(sorted(pi), sorted(qi))
def test_edges_for_vert(self):
for pi, qi in zip(self.skel.edges_for_vert, self.cube.edges_for_vert):
self.assertEqual(sorted(pi), sorted(qi))
if __name__ == '__main__':
unittest.main(verbosity=3)