-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
191 lines (163 loc) · 7.34 KB
/
main.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from libs.vector import Vector
from libs.plane import Plane
from libs.linsys import LinearSystem
p0 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p1 = Plane(normal_vector=Vector([0, 1, 0]), constant_term=2)
p2 = Plane(normal_vector=Vector([1, 1, -1]), constant_term=3)
p3 = Plane(normal_vector=Vector([1, 0, -2]), constant_term=2)
s = LinearSystem([p0, p1, p2, p3])
s.swap_rows(0, 1)
if not (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3):
print('test case 1 failed')
s.swap_rows(1, 3)
if not (s[0] == p1 and s[1] == p3 and s[2] == p2 and s[3] == p0):
print('test case 2 failed')
s.swap_rows(3, 1)
if not (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3):
print('test case 3 failed')
s.multiply_coefficient_and_row(1, 0)
if not (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3):
print('test case 4 failed')
s.multiply_coefficient_and_row(-1, 2)
if not (s[0] == p1 and
s[1] == p0 and
s[2] == Plane(normal_vector=Vector([-1, -1, 1]), constant_term=-3) and
s[3] == p3):
print('test case 5 failed')
s.multiply_coefficient_and_row(10, 1)
if not (s[0] == p1 and
s[1] == Plane(normal_vector=Vector([10, 10, 10]), constant_term=10) and
s[2] == Plane(normal_vector=Vector([-1, -1, 1]), constant_term=-3) and
s[3] == p3):
print('test case 6 failed')
s.add_multiple_times_row_to_row(0, 0, 1)
if not (s[0] == p1 and
s[1] == Plane(normal_vector=Vector([10, 10, 10]), constant_term=10) and
s[2] == Plane(normal_vector=Vector([-1, -1, 1]), constant_term=-3) and
s[3] == p3):
print('test case 7 failed')
s.add_multiple_times_row_to_row(1, 0, 1)
if not (s[0] == p1 and
s[1] == Plane(normal_vector=Vector([10, 11, 10]), constant_term=12) and
s[2] == Plane(normal_vector=Vector([-1, -1, 1]), constant_term=-3) and
s[3] == p3):
print('test case 8 failed')
s.add_multiple_times_row_to_row(-1, 1, 0)
if not (s[0] == Plane(normal_vector=Vector([-10, -10, -10]), constant_term=-10) and
s[1] == Plane(normal_vector=Vector([10, 11, 10]), constant_term=12) and
s[2] == Plane(normal_vector=Vector([-1, -1, 1]), constant_term=-3) and
s[3] == p3):
print('test case 9 failed')
p1 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([0, 1, 1]), constant_term=2)
s = LinearSystem([p1, p2])
t = s.compute_triangular_form()
if not (t[0] == p1 and
t[1] == p2):
print('test case 10 failed')
p1 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=2)
s = LinearSystem([p1, p2])
t = s.compute_triangular_form()
if not (t[0] == p1 and
t[1] == Plane(constant_term=1)):
print('test case 11 failed')
p1 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([0, 1, 0]), constant_term=2)
p3 = Plane(normal_vector=Vector([1, 1, -1]), constant_term=3)
p4 = Plane(normal_vector=Vector([1, 0, -2]), constant_term=2)
s = LinearSystem([p1, p2, p3, p4])
t = s.compute_triangular_form()
if not (t[0] == p1 and
t[1] == p2 and
t[2] == Plane(normal_vector=Vector([0, 0, -2]), constant_term=2) and
t[3] == Plane()):
print('test case 12 failed')
p1 = Plane(normal_vector=Vector([0, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([1, -1, 1]), constant_term=2)
p3 = Plane(normal_vector=Vector([1, 2, -5]), constant_term=3)
s = LinearSystem([p1, p2, p3])
t = s.compute_triangular_form()
if not (t[0] == Plane(normal_vector=Vector([1, -1, 1]), constant_term=2) and
t[1] == Plane(normal_vector=Vector([0, 1, 1]), constant_term=1) and
t[2] == Plane(normal_vector=Vector([0, 0, -9]), constant_term=-2)):
print('test case 13 failed')
p1 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([0, 1, 1]), constant_term=2)
s = LinearSystem([p1, p2])
r = s.compute_rref()
if not (r[0] == Plane(normal_vector=Vector([1, 0, 0]), constant_term=-1) and
r[1] == p2):
print('test case 14 failed')
p1 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=2)
s = LinearSystem([p1, p2])
r = s.compute_rref()
if not (r[0] == p1 and
r[1] == Plane(constant_term=1)):
print('test case 15 failed')
p1 = Plane(normal_vector=Vector([1, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([0, 1, 0]), constant_term=2)
p3 = Plane(normal_vector=Vector([1, 1, -1]), constant_term=3)
p4 = Plane(normal_vector=Vector([1, 0, -2]), constant_term=2)
s = LinearSystem([p1, p2, p3, p4])
r = s.compute_rref()
if not (r[0] == Plane(normal_vector=Vector([1, 0, 0]), constant_term=0) and
r[1] == p2 and
r[2] == Plane(normal_vector=Vector([0, 0, -2]), constant_term=2) and
r[3] == Plane()):
print('test case 16 failed')
p1 = Plane(normal_vector=Vector([0, 1, 1]), constant_term=1)
p2 = Plane(normal_vector=Vector([1, -1, 1]), constant_term=2)
p3 = Plane(normal_vector=Vector([1, 2, -5]), constant_term=3)
s = LinearSystem([p1, p2, p3])
r = s.compute_rref()
if not (r[0] == Plane(normal_vector=Vector([1, 0, 0]), constant_term=23.0/9.0) and
r[1] == Plane(normal_vector=Vector([0, 1, 0]), constant_term=7.0/9.0) and
r[2] == Plane(normal_vector=Vector([0, 0, 1]), constant_term=2.0/9.0)):
print('test case 17 failed')
p1 = Plane(normal_vector=Vector([5.862, 1.178, -10.366]), constant_term=-8.15)
p2 = Plane(normal_vector=Vector([1, -1, 1]), constant_term=2)
p3 = Plane(normal_vector=Vector([1, 2, -5]), constant_term=3)
s = LinearSystem([p1, p2, p3])
r = s.compute_rref()
if not (r[0] == Plane(normal_vector=Vector([1, 0, 0]), constant_term=23.0/9.0) and
r[1] == Plane(normal_vector=Vector([0, 1, 0]), constant_term=7.0/9.0) and
r[2] == Plane(normal_vector=Vector([0, 0, 1]), constant_term=2.0/9.0)):
print('test case 18 failed')
p1 = Plane(Vector([5.862, 1.178, -10.366]), -8.15)
p2 = Plane(Vector([-2.931, -0.589, 5.183]), -4.075)
s = LinearSystem([p1, p2])
print('')
print(s.compute_rref())
p1 = Plane(Vector([8.631, 5.112, -1.816]), -5.113)
p2 = Plane(Vector([4.315, 11.132, -5.27]), -6.775)
p3 = Plane(Vector([-2.158, 3.01, -1.727]), -0.831)
s = LinearSystem([p1, p2, p3])
print('')
print(s.compute_rref())
p1 = Plane(Vector([5.262, 2.734, -9.878]), -3.441)
p2 = Plane(Vector([5.111, 6.358, 7.638]), -2.152)
p3 = Plane(Vector([2.016, -9.924, -1.367]), -9.278)
p4 = Plane(Vector([2.167, -13.543, -18.883]), -10.567)
s = LinearSystem([p1, p2, p3, p4])
print('')
print(s.compute_rref())
p1 = Plane(Vector([0.786, 0.786, 0.588]), -0.714)
p2 = Plane(Vector([-0.138, -0.138, 0.244]), 0.319)
s = LinearSystem([p1, p2])
print('')
print(s.compute_rref())
p1 = Plane(Vector([8.631, 5.112, -1.816]), -5.113)
p2 = Plane(Vector([4.315, 11.132, -5.27]), -6.775)
p3 = Plane(Vector([-2.158, 3.01, -1.727]), -0.831)
s = LinearSystem([p1, p2, p3])
print('')
print(s.compute_rref())
p1 = Plane(Vector([0.935, 1.76, -9.365]), -9.955)
p2 = Plane(Vector([0.187, 0.352, -1.873]), -1.991)
p3 = Plane(Vector([0.374, 0.704, -3.746]), -3.982)
p4 = Plane(Vector([-0.561, -1.056, 5.619]), 5.973)
s = LinearSystem([p1, p2, p3, p4])
print('')
print(s.compute_rref())