test_openpg.py 3.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
import unittest
import openpg
import example_graphs
import isomorphic

class test_openpg(unittest.TestCase):
	"""
	Unittests for openpg library
	"""
	def setUp(self):
		self.G1 = example_graphs.example_graph1()
		self.G2 = example_graphs.example_graph2()
		self.G3 = example_graphs.example_graph3()
14
		self.G4 = example_graphs.example_graph4()
15 16 17 18 19 20 21

	def test_save_load(self):
		openpg.save(self.G1, '/tmp/openpg_test.save')
		g1 = openpg.load('/tmp/openpg_test.save')
		self.assertEqual(self.G1.name, g1.name)
		self.assertEqual(len(self.G1.faces), len(g1.faces))

22 23 24 25 26 27 28 29 30
	def test_save_load_facefmt(self):
		openpg.save_facefmt(self.G1, '/tmp/openpg_test.save', 
							lambda x: str(x))
		g1 = openpg.load_facefmt('/tmp/openpg_test.save', 
							lambda x: int(x))
		self.assertEqual(self.G1.name, g1.name)
		self.assertEqual(len(self.G1.faces), len(g1.faces))


31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	def test_find_pendents(self):
		g1 = self.G1.pendents()
		self.assertEqual(len(g1),1)

	def test_find_bridges(self):
		g1 = self.G1.bridges()
		self.assertEqual(len(g1),4)
	
	def test_find_branches(self):
		g2 = self.G2.branches()
		self.assertEqual(len(g2),1)

	def test_find_hinges(self):
		g3 = self.G3.hinges()
		self.assertEqual(len(g3),1)

	def test_normalize(self):
		for g in [self.G1, self.G2, self.G3]:
			g.normalize()
			self.assertEqual(g.hinges(), [])
			self.assertEqual(g.branches(), [])
			self.assertEqual(g.bridges(), [])

	def test_outer_face(self):
		g = openpg.openpg()
		f1 = openpg.face([], outer=True)
		f2 = openpg.face([], visible=True)
		g.add_face(f1)
		g.add_face(f2)
		self.assertIs(g.outer_face(), f1)

	def test_remove_face(self):
		g = openpg.openpg()
		f1 = openpg.face([], outer=True)
		f2 = openpg.face([], visible=True)
		g.add_face(f1)
		g.add_face(f2)
		self.assertEqual(len(g.faces), 2)
		g.remove_face(f1)
		self.assertEqual(len(g.faces), 1)

	def test_print_face(self):
		f1 = openpg.face([], outer=True)
74
		self.assertEqual(str(f1), 'Face(False)([]){}')
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

	def test_face_edges_lessthan_2(self):
		f1 = openpg.face([])
		self.assertEqual(f1.edges(), [])

	def test_printout(self):
		self.G1.print_info(verbose=True)

	def test_plane_iso_same(self):
		self.G1.normalize()
		self.assertTrue(
			isomorphic.check_plane_isomorphism(self.G1, self.G1))

	def test_plane_iso_diff(self):
		self.G1.normalize()
		self.G2.normalize()
		self.assertTrue(
			isomorphic.check_plane_isomorphism(self.G2, self.G1))

	def test_sphere_iso_same(self):
		self.G1.normalize()
		self.assertTrue(
			isomorphic.check_sphere_isomorphism(self.G1, self.G1))

	def test_sphere_iso_diff(self):
		self.G1.normalize()
		self.G2.normalize()
		self.assertTrue(
			isomorphic.check_sphere_isomorphism(self.G2, self.G1))

	def test_plane_iso_false(self):
		self.G1.normalize()
		self.G3.normalize()
		self.assertFalse(
			isomorphic.check_plane_isomorphism(self.G3, self.G1))

	def test_sphere_iso_false(self):
		self.G1.normalize()
		self.G3.normalize()
		self.assertFalse(
			isomorphic.check_sphere_isomorphism(self.G3, self.G1))

117 118
	def test_check_pattern_same(self):
		self.G1.normalize()
119
		self.assertTrue(isomorphic.check_pattern(self.G1,self.G1))
120

121 122 123 124
	def test_check_pattern_diff(self):
		self.G4.normalize()
		self.assertTrue(isomorphic.check_pattern(self.G4, self.G1))

125 126
	def test_contiguous_faces(self):
		g1 = list(self.G1.contiguous_visible_faces(self.G1.faces[1]))
127
		self.assertTrue(len(g1) == 4)
128 129 130 131 132
	

if __name__ == '__main__':
	unittest.main()