示例#1
0
	def test_abstraction(self):
		ab = Abstraction([-1, -1], [1, 1], 1, 1)
		self.assertEquals(len(ab), 4)

		c1 = ab.point_to_midx((0.2, 0.2))
		self.assertEquals(ab.graph.node[c1]['lower_bounds'], (0.,0.))
		self.assertEquals(ab.graph.node[c1]['upper_bounds'], (1.,1.))

		c2 = ab.point_to_midx((0.2, -0.7))
		self.assertEquals(ab.graph.node[c2]['lower_bounds'], (0.,-1))
		self.assertEquals(ab.graph.node[c2]['upper_bounds'], (1,0))
示例#2
0
	def test_ordering(self):
		ab = Abstraction([0, 0], [5, 4], 1, 1)

		for i in range(5):
			for j in range(4):
				self.assertEquals(ab.node_to_idx( (i,j) ), 4*i+j)
				self.assertEquals(ab.idx_to_node(ab.node_to_idx((i,j))), (i,j))

		ab = Abstraction([0, 0, 0], [5, 4, 3], 1, 1)
		for i in range(5):
			for j in range(4):
				for k in range(3):
					self.assertEquals(ab.node_to_idx((i,j,k)), 3*(4*i+j) + k)
					self.assertEquals(ab.idx_to_node(ab.node_to_idx((i,j,k))), (i,j,k))

		ordering = sorted(ab.graph.nodes_iter(), key = ab.node_to_idx)
		assert(len(ordering) == len(ab))
		for i,node in enumerate(ordering):
			self.assertEquals( ab.idx_to_node(i), node )