Commit 08997556 authored by Mathieu Istas's avatar Mathieu Istas
Browse files

added tests to weather_station

parent 0093f7e0
Pipeline #83979 passed with stage
in 51 seconds
import unittest
class WeatherStation(object):
""" A weather station that holds wind and temperature
:param wind: any ordered iterable
......@@ -28,3 +30,39 @@ idx_max_temp = paris.arg_max_temp()
print(f"max temp is {paris.max_temp()}°C at index {paris.arg_max_temp()}")
print(f"wind speed at max temp = {paris.wind[idx_max_temp]} km/h")
# testing
class TestWeatherStation(unittest.TestCase):
"""Test the weather station """
def setUp(self):
"""Generates a well structured station (paris)"""
self.paris = WeatherStation(
[10, 0, 20, 30, 20, 0],
[1, 5, 1, -1, -1, 3],
)
def test_building_with_good_input_arrays(self):
""" test that things goes smoothly if the input are correct"""
self.assertEqual(0, self.paris.wind[1])
self.assertEqual(5, self.paris.temp[1])
def test_building_with_input_iterables(self):
""" test that things goes smoothly if the input are correct"""
r_station = WeatherStation(range(10), range(10))
self.assertEqual(4, r_station.wind[4])
self.assertEqual(5, r_station.temp[5])
def test_building_with_bad_arrays(self):
""" test that an exception is raised with incorrect inputs"""
with self.assertRaises(ValueError):
bad_station = WeatherStation([10, 0, 20, 30, 20, 0], [1, 5, 1])
def test_max_temp(self):
""" test test_max_temp function"""
self.assertEqual(5, self.paris.max_temp())
def test_arg_max_temp(self):
""" test arg_max_temp function"""
self.assertEqual(1, self.paris.arg_max_temp())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment