-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.py
48 lines (37 loc) · 1.04 KB
/
testing.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
from geometry import *
# Testing sphere methods
def test_intersect_True():
S = Sphere((0, 0, 0), 1, (10, 200, 20))
l = Line.through_points((0, 1, 0), (0, 1, 1))
assert S.intersection_value(l) != []
def test_intersect_False():
S = Sphere((100, 100, 100), 0.1, (10, 200, 20))
l = Line.through_points((0, 0, 1), (0, 0, 2))
assert S.intersection_value(l) == []
# Testing vector methods
def test_subtract():
v = Vector([1, 0, 0])
w = Vector([1, 1, 0])
r = Vector([0, 1, 0])
assert w.subtract(v).equals(r)
def test_norm():
v = Vector([1, 0, 0])
w = Vector([0, 2, 0])
assert v.norm() == 1.0
assert w.norm() == 2.0
def test_cross_product():
v = Vector([1, 2, 3])
w = Vector([4, 5, 6])
r = Vector([-3, 6, -3])
assert v.cross_product(w).equals(r)
def test_mul_by_number():
v = Vector([1, 1, 1])
r = Vector([2, 2, 2])
assert v.mul_by_number(2).equals(r)
# Calling tests
test_intersect_True()
test_intersect_False()
test_subtract()
test_norm()
test_cross_product()
test_mul_by_number()