test(tests/): test

This commit is contained in:
songsenand 2024-02-16 07:28:41 +08:00
parent 4382d9dab7
commit 51c70f3312
2 changed files with 67 additions and 0 deletions

0
tests/__init__.py Normal file
View File

67
tests/test_plane.py Normal file
View File

@ -0,0 +1,67 @@
from math import isclose
from pytest import fixture
from tdcgal.plane.objects import *
class TestPoint2D:
def setup_method(self):
self.point1 = Point2D(1.0, 2.0)
self.point2 = Point2D(3.0, 4.0)
def test_distance(self):
assert isclose(self.point1.distance_to_point(self.point2), 8 ** 0.5)
def test_x(self):
assert self.point1.x() == 1
assert self.point2.x() == 3
def test_y(self):
assert self.point1.y() == 2
assert self.point2.y() == 4
"""
class TestLine:
def setup_method(self):
self.line1 = Line((1, 3), (1, 4))
self.line2 = Line((1, 1), (2, 2))
self.line3 = Line((37, 5), (7, 29))
def test_slope(self):
assert self.line1.slope == float("inf")
assert self.line2.slope == 1
def test_y_intercept(self):
assert self.line1.y_intercept == float("inf")
assert self.line2.y_intercept == 0
assert self.line3.y_intercept == 34.6
def test_equation(self):
assert self.line1.expression == "1.0*x - 1.0 = 0"
assert self.line2.expression == "1.0*x - 1.0*y = 0"
assert self.line3.expression == "24.0*x + 30.0*y - 1038.0 = 0"
def test_contains(self):
assert (1, 5) not in self.line1
assert (1, 3.2) in self.line1
assert (1.45, 1.45) in self.line2
assert (3, 3) not in self.line2
assert (37, 5) in self.line3
assert (7, 29) in self.line3
assert (12, 25) in self.line3
assert (12, 12) not in self.line3
assert (3, 32.2) not in self.line3
assert self.line3.contains((6, 29.8), allow_on_extended=True)
def test_length(self):
assert self.line1.length == 1
assert self.line2.length == 2 ** 0.5
assert isclose(self.line3.length, 38.41874542459709)
def test_distance(self):
assert self.line1.point_distance((1, 5)) == 1
assert self.line2.point_distance((1.5, 1.5)) == 0
assert isclose(self.line3.point_distance((12, 24)),0.780868809443030)
"""