Created
March 8, 2016 09:25
-
-
Save drhanlau/d48bc3ebf2ff94410318 to your computer and use it in GitHub Desktop.
Nose2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ..location import Location | |
from nose2.tools.params import params | |
from datetime import datetime | |
# def test_temperature_of_a_new_location_class_should_be_None(): | |
# location = Location("PEN") | |
# assert location.temperature is None | |
def setup_test(): | |
global penang | |
penang = Location("PEN") | |
def teardown_test(): | |
global penang | |
penang = None | |
def test_temperature_of_a_new_location_class_should_be_None(): | |
assert penang.temperature is None, "Temperature of a new location should be None" | |
def given_a_series_of_temperatures(location, temperatures): | |
timestamps = [datetime(2014, 2, 10), datetime(2014, 2, 11), \ | |
datetime(2014, 2, 12), datetime(2014, 2, 13)] | |
for timestamp, temperature in zip(timestamps, temperatures): | |
location.update(timestamp, temperature) | |
@params( | |
([8, 10, 12], True), | |
([8, 12, 10], False), | |
([8, 10, 10], False) | |
) | |
def test_location_trends(temperatures, expected_output): | |
penang = Location("PEN") | |
given_a_series_of_temperatures(penang, temperatures) | |
assert penang.is_increasing_trend() == expected_output | |
def test_trend_with_all_consecutive_values_upto_100(): | |
for i in range(100): | |
yield location_trends_with_consecutive_temperatures, [i, i+1, i+2] | |
def location_trends_with_consecutive_temperatures(temperatures): | |
penang = Location("Penang") | |
given_a_series_of_temperatures(penang, temperatures) | |
assert penang.is_increasing_trend() | |
test_temperature_of_a_new_location_class_should_be_None.setup = setup_test | |
test_temperature_of_a_new_location_class_should_be_None.teardown = teardown_test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment