diff --git a/tests/boat_utest.py b/tests/boat_utest.py new file mode 100644 index 0000000..c00daf7 --- /dev/null +++ b/tests/boat_utest.py @@ -0,0 +1,28 @@ +#coding:utf-8 + +import unittest +import sys + +sys.path.append('../src') +from boat import Boat +from position import Position +from custom_exception.nothing_to_compare_error import * + +class BoatUTest(unittest.TestCase): + def test_get_temp_mean(self): + temps = [0.0, 25.0, 50.0, 75.0, 100.0] + test_boat = Boat("0", "50", "0", "0", "0", temps, []) + self.assertEqual(test_boat.get_temp_mean(), 50) + + def test_get_northiest_coords(self): + center = Position(0, 0) + north = Position(90, 0) + south = Position(-90, 0) + test_boat = Boat("0", "Test", "0", "0", "0", [], [center, north, south]) + test_broken_boat = Boat("0", "Broken", "0", "0", "0", [], []) + self.assertEqual(test_boat.get_northiest_coords(), north) + with self.assertRaises(NothingToCompareError): + test_broken_boat.get_northiest_coords() + +if __name__ == '__main__': + unittest.main() diff --git a/tests/fleet_utest.py b/tests/fleet_utest.py new file mode 100644 index 0000000..86efde6 --- /dev/null +++ b/tests/fleet_utest.py @@ -0,0 +1,44 @@ +#coding:utf-8 + +import unittest +import sys +import statistics +sys.path.append('../src') +from boat import Boat +from position import Position +from fleet import Fleet +from custom_exception.nothing_to_compare_error import * + +class FleetUTest(unittest.TestCase): + def test_get_northiest(self): + north = Position(90, 0) + less_north = Position(75, 0) + south = Position(-90, 0) + less_south = Position(-75, 0) + + test_south_boat = Boat("0", "south", "0", "0", "0", [], [north, less_south]) + test_north_boat = Boat("0", "north", "0", "0", "0", [], [less_north, south]) + f = Fleet(2020, boats = [test_north_boat, test_south_boat]) + + self.assertEqual(f.get_northiest(), (test_north_boat, north)) + + def test_get_highiest_heat_mean(self): + hot = [60.0, 45.6, 88.8, 36.7] + cold = [10.11, 11.10, 10.01, 1.11] + test_clod_boat = Boat("0", "cold", "0", "0", "0", cold, []) + test_hot_boat = Boat("0", "hot", "0", "0", "0", hot, []) + f = Fleet(2020, boats = [test_hot_boat, test_clod_boat]) + self.assertEqual(f.get_highiest_heat_mean(), (test_hot_boat, statistics.mean(hot))) + broken_f = Fleet(2020, boats = []) + with self.assertRaises(NothingToCompareError): + broken_f.get_highiest_heat_mean() + def test_compare_boats(self): + test_boat1 = Boat("0", "0", "0", "0", "0", [], []) + test_boat2 = Boat("1", "1", "1", "1", "1", [], []) + f = Fleet(2020, boats = [test_boat2, test_boat1]) + with self.assertRaises(TypeError): + f.compare_boats(lambda a, b, c : a + b + c, lambda a : 12) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/position_utest.py b/tests/position_utest.py new file mode 100644 index 0000000..ba55c7c --- /dev/null +++ b/tests/position_utest.py @@ -0,0 +1,26 @@ +#coding:utf-8 + +import unittest +import sys +sys.path.append('../src') +from position import Position + +class PositionUTest(unittest.TestCase): + def test_is_norther_than(self): + center = Position(0, 0) + north = Position(90, 0) + south = Position(-90, 0) + self.assertTrue(north.is_norther_than(south)) + self.assertFalse(south.is_norther_than(north)) + def test___eq__(self): + north = Position(90, 0) + south = Position(-90, 0) + self.assertTrue(north.__eq__(north)) + self.assertFalse(north.__eq__(south)) + self.assertFalse(north.__eq__(None)) + self.assertFalse(north.__eq__(12)) + + + +if __name__ == '__main__': + unittest.main()