示例#1
0
	def test_vs_naive_randomly(self):
		TRIALS = 10000
		for _ in range(TRIALS):
			numpoints = random.randrange(100)
			if random.random() < 0.5:
				points = [(random.gauss(0, 1), random.gauss(0, 1)) for _ in range(numpoints)]
			else:
				points = [(random.randrange(10), random.randrange(10)) for _ in range(numpoints)]
			actual = convexhull.make_hull(points)
			expected = ConvexHullTest.make_hull_naive(points)
			self.assertEqual(actual, expected)
示例#2
0
	def test_hull_properties_randomly(self):
		TRIALS = 10000
		for _ in range(TRIALS):
			
			# Generate random points
			numpoints = random.randrange(100)
			if random.random() < 0.5:
				points = [(random.gauss(0, 1), random.gauss(0, 1)) for _ in range(numpoints)]
			else:
				points = [(random.randrange(10), random.randrange(10)) for _ in range(numpoints)]
			
			# Compute hull and check properties
			hull = convexhull.make_hull(points)
			self.assertTrue(ConvexHullTest.is_polygon_convex(hull))
			for p in points:
				self.assertTrue(ConvexHullTest.is_point_in_convex_polygon(hull, p))
			
			# Add duplicate points and check new hull
			if len(points) > 0:
				dupe = random.randrange(10) + 1
				for _ in range(dupe):
					points.append(points[random.randrange(len(points))])
				nexthull = convexhull.make_hull(points)
				self.assertEqual(hull, nexthull)
示例#3
0
	def test_vertical_randomly(self):
		TRIALS = 10000
		for _ in range(TRIALS):
			numpoints = random.randrange(30) + 1
			if random.random() < 0.5:
				x = random.gauss(0, 1)
				points = [(x, random.gauss(0, 1)) for _ in range(numpoints)]
			else:
				x = random.randrange(20) - 10
				points = [(x, random.randrange(30)) for _ in range(numpoints)]
			actual = convexhull.make_hull(points)
			expected = [min(points)]
			if max(points) != min(points):
				expected.append(max(points))
			self.assertEqual(actual, expected)
示例#4
0
	def test_rectangle(self):
		points = [(-3, 2), (1, 2), (1, -4), (-3, -4)]
		actual = convexhull.make_hull(points)
		expect = [(-3, -4), (-3, 2), (1, 2), (1, -4)]
		self.assertEqual(expect, actual)
示例#5
0
	def test_two_diagonal1(self):
		points = [(-2, 3), (2, 0)]
		actual = convexhull.make_hull(points)
		expect = points
		self.assertEqual(expect, actual)
示例#6
0
	def test_two_vertical1(self):
		points = [(-1, 2), (-1, -3)]
		actual = convexhull.make_hull(points)
		expect = [(-1, -3), (-1, 2)]
		self.assertEqual(expect, actual)
示例#7
0
	def test_two_vertical0(self):
		points = [(1, -4), (1, 4)]
		actual = convexhull.make_hull(points)
		expect = points
		self.assertEqual(expect, actual)
示例#8
0
	def test_two_horizontal1(self):
		points = [(-6, -3), (-8, -3)]
		actual = convexhull.make_hull(points)
		expect = [(-8, -3), (-6, -3)]
		self.assertEqual(expect, actual)
示例#9
0
	def test_two_horizontal0(self):
		points = [(2, 0), (5, 0)]
		actual = convexhull.make_hull(points)
		expect = points
		self.assertEqual(expect, actual)
示例#10
0
	def test_two_duplicate(self):
		points = [(0, 0), (0, 0)]
		actual = convexhull.make_hull(points)
		expect = [(0, 0)]
		self.assertEqual(expect, actual)
示例#11
0
	def test_one(self):
		points = [(3, 1)]
		actual = convexhull.make_hull(points)
		expect = points
		self.assertEqual(expect, actual)
示例#12
0
	def test_empty(self):
		points = []
		actual = convexhull.make_hull(points)
		expect = []
		self.assertEqual(expect, actual)