You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.6 KiB
45 lines
1.6 KiB
#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()
|