97 lines
2.7 KiB
Python
97 lines
2.7 KiB
Python
#!/usr/bin/python3
|
|
|
|
import point
|
|
|
|
def test_init():
|
|
"""Test init routine"""
|
|
pnt = point.Point()
|
|
assert pnt.get_x() == 0
|
|
assert pnt.get_y() == 0
|
|
pnt = point.Point(10, 20)
|
|
assert pnt.get_x() == 10
|
|
assert pnt.get_y() == 20
|
|
|
|
def test_set_coordinates():
|
|
"""Test setting coordinates"""
|
|
pnt = point.Point()
|
|
assert pnt.get_x() == 0
|
|
assert pnt.get_y() == 0
|
|
pnt.set_x(123)
|
|
assert pnt.get_x() == 123
|
|
pnt.set_y(654)
|
|
assert pnt.get_y() == 654
|
|
pnt.set_x(321)
|
|
assert pnt.get_x() == 321
|
|
pnt.set_y(456)
|
|
assert pnt.get_y() == 456
|
|
|
|
def test_get_random():
|
|
"""Test setting random points"""
|
|
min_x = 10
|
|
max_x = 25
|
|
min_y = 30
|
|
max_y = 50
|
|
for _ in range(100):
|
|
pnt = point.get_random(min_x, max_x, min_y, max_y)
|
|
assert min_x <= pnt.get_x() <= max_x
|
|
assert min_y <= pnt.get_y() <= max_y
|
|
|
|
def test_is_equal():
|
|
"""Test the equal and not equal operator"""
|
|
# pylint: disable=unneeded-not
|
|
pnt = point.Point(123, 456)
|
|
pnt_eq = point.Point(123, 456)
|
|
pnt_diff = point.Point(456, 123)
|
|
pnt_diff_x = point.Point(321, 456)
|
|
pnt_diff_y = point.Point(123, 654)
|
|
|
|
assert pnt == pnt_eq
|
|
assert not pnt == pnt_diff
|
|
assert not pnt == pnt_diff_x
|
|
assert not pnt == pnt_diff_y
|
|
|
|
assert not pnt != pnt_eq
|
|
assert pnt != pnt_diff
|
|
assert pnt != pnt_diff_x
|
|
assert pnt != pnt_diff_y
|
|
|
|
assert not pnt == None
|
|
|
|
def test_sort_set():
|
|
"""Test the sorting algorithm"""
|
|
point_set = [ \
|
|
point.Point(94.01, 68.5), \
|
|
point.Point(33.08, 86.28), \
|
|
point.Point(75.56, 34.14), \
|
|
point.Point(29.46, 69.56), \
|
|
point.Point(72.76, 74.25), \
|
|
point.Point(35.42, 8.76), \
|
|
point.Point(31.44, 60.7), \
|
|
point.Point(31.97, 34.14), \
|
|
point.Point(29.46, 17.73), \
|
|
point.Point(74.33, 4.58), \
|
|
point.Point(76.13, 59.69), \
|
|
point.Point(1.37, 85.25), \
|
|
point.Point(29.46, 30.59), \
|
|
point.Point(69.69, 34.14), \
|
|
point.Point(40.71, 34.02), \
|
|
point.Point(35.18, 14.32), \
|
|
point.Point(81.29, 55.71), \
|
|
point.Point(78.28, 14.9), \
|
|
point.Point(22.01, 90.7), \
|
|
point.Point(9.42, 66.61)]
|
|
|
|
point.sort_set(point_set)
|
|
|
|
for i in range(len(point_set) - 1):
|
|
assert point_set[i].get_x() <= point_set[i + 1].get_x()
|
|
if point_set[i].get_x() == point_set[i + 1].get_x():
|
|
assert point_set[i].get_y() <= point_set[i + 1].get_y()
|
|
|
|
point.sort_set(point_set, True)
|
|
|
|
for i in range(len(point_set) - 1):
|
|
assert point_set[i].get_y() <= point_set[i + 1].get_y()
|
|
if point_set[i].get_y() == point_set[i + 1].get_y():
|
|
assert point_set[i].get_x() <= point_set[i + 1].get_x()
|