Ajout des test unitaires pour Boat, Fleet et Position

tests
Allan Point 3 years ago
parent fdc701b423
commit 2bd86f2ca9

@ -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()

@ -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()

@ -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()
Loading…
Cancel
Save