test(tests/test_object.py): 添加对Line的测试

This commit is contained in:
songsenand 2024-01-27 01:28:37 +08:00
parent d77f119c63
commit 86c1f27e38
2 changed files with 24 additions and 0 deletions

0
tests/__init__.py Normal file
View File

24
tests/test_object.py Normal file
View File

@ -0,0 +1,24 @@
# import sys
# sys.path.append('/home/songsenand/Project/ToyDesigner/')
from toydesigner.objects import *
def test_line():
line1 = Line((1, 3), (1, 4))
assert line1.slope() == float("inf")
assert line1.y_intercept() == 0
line2 = Line((1, 1), (2, 2))
assert line2.slope() == 1
assert line2.y_intercept() == 0
assert line2.equation() == "y = 1.0x"
line3 = Line((37, 5), (7, 29))
assert line3.slope() == -0.8
assert line3.y_intercept() == 34.6
assert line3.equation() == "y = -0.8x + 34.6"
assert (12, 25) in line3
assert (12, 12) not in line3
assert (3, 32.2) not in line3
assert line3.contains((6, 29.8), allow_on_extended=True) == True
assert line3.length()**2 == (37 - 7) ** 2 + (5 - 29) ** 2