/
test_reject_redundant_points.py
110 lines (86 loc) · 3.87 KB
/
test_reject_redundant_points.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
74
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
from unittest import TestCase
from SimpleMath import Vector2D
from SimpleMath import Line2D
from SCE_Direct import find_constrained_centre_directly
from SCE_Nimrod import find_constrained_redundant_points
from random import uniform
__author__ = 'lav'
class TestReject_redundant_points(TestCase):
def easy_test_with_line(self, line):
ppp = [Vector2D(1.0, 0.0),
Vector2D(2.5, 1.0),
Vector2D(2.0, -1.5),
Vector2D(0.0, -1.9),
Vector2D(-0.5, 0.5),
Vector2D(-1.0, 0.0),
Vector2D(0.5, -1.0),
Vector2D(0.5, 1.5)]
rejected = find_constrained_redundant_points(ppp, line)
self.assertEqual(len(rejected), 2)
self.assertTrue(Vector2D(0.5, -1.0) in rejected)
self.assertTrue(Vector2D(-0.5, 0.5) in rejected)
for p in ppp:
if p in rejected:
ppp.remove(p)
rejected = find_constrained_redundant_points(ppp, line)
self.assertEqual(len(rejected), 1)
self.assertTrue(Vector2D(0.5, 1.5) in rejected)
for p in ppp:
if p in rejected:
ppp.remove(p)
rejected = find_constrained_redundant_points(ppp, line)
self.assertEqual(len(rejected), 1)
self.assertTrue(Vector2D(1.0, 0.) in rejected)
def internal_compare(self, lst, line):
circle, points = find_constrained_centre_directly(lst, line)
while len(lst) > 3:
rejected = find_constrained_redundant_points(lst, line)
if not rejected:
chk1 = len(lst)
last = lst[-1]
lst.remove(last)
lst.insert(0, last)
chk2 = len(lst)
assert chk1 == chk2
rejected = find_constrained_redundant_points(lst, line)
if not rejected:
print "bad bad bad"
for p in lst:
if p in rejected:
lst.remove(p)
for p in points:
self.assertTrue(p in lst)
def easy_test_with_line_based_on_direct_search(self, line):
ppp = [Vector2D(1.0, 0.0),
Vector2D(2.5, 1.0),
Vector2D(2.0, -1.5),
Vector2D(0.0, -1.9),
Vector2D(-0.5, 0.5),
Vector2D(-1.0, 0.0),
Vector2D(0.5, -1.0),
Vector2D(0.5, 1.5)]
self.internal_compare(ppp, line)
def internal_test_random(self, number_of_points, line):
thelist = list()
for i in range(number_of_points):
thelist.append(Vector2D(uniform(-10.0, 10.0), uniform(-10.0, 10.0)))
self.internal_compare(thelist, line)
def test_rejection(self):
# easy test with hard-coded control points
self.easy_test_with_line(Line2D(coefs=[0.0, 1.0, 0.0]))
self.easy_test_with_line(Line2D(coefs=[0.0, 1.0, 0.131045525]))
self.easy_test_with_line(Line2D(coefs=[0.0, 1.0, -0.15]))
# tests with comparing to results found directly (by brute force)
self.easy_test_with_line_based_on_direct_search(Line2D(coefs=[0.0, 1.0, 0.0]))
self.easy_test_with_line_based_on_direct_search(Line2D(coefs=[1.0, 0.0, 0.0]))
self.easy_test_with_line_based_on_direct_search(Line2D(coefs=[0.0, 1.0, 2.0]))
self.easy_test_with_line_based_on_direct_search(Line2D(coefs=[1.0, 0.0, 2.0]))
self.easy_test_with_line_based_on_direct_search(Line2D(coefs=[-1.0, 1.0, 0.0]))
self.easy_test_with_line_based_on_direct_search(Line2D(coefs=[-1.0, 1.4, 3.0]))
for i in range(10):
self.internal_test_random(20, Line2D(coefs=[0.0, 1.0, 0.0]))
for i in range(10):
self.internal_test_random(100, Line2D(coefs=[0.0, 1.0, 0.0]))
for i in range(5):
print i, "wde range started"
self.internal_test_random(400, Line2D(coefs=[0.0, 1.0, 0.0]))