Example #1
0
    def test_event_decision4(self):
        """Test ED._temp_factor rule 2a & 3a and _rain_factor rule 1c"""
        weather_data = WeatherData()
        weather_data._weather_data.append(
            WeatherDataItem(5, 44, 20, 10, 61, 15, 30, "ESE", 1, 1016.3))
        sp = self.prediction.SimplePrediction(weather_data, 1)
        event = self.event_decision.Event('My Event', True, True, 13)
        ed = self.event_decision.EventDecision(event, sp)

        self.aggregate(self.assertAlmostEqual,
                       ed._temperature_factor(),
                       -1.8,
                       places=3,
                       tag='_temperature_factor')
        self.aggregate(self.assertAlmostEqual,
                       ed._rain_factor(),
                       0,
                       places=3,
                       tag='_rain_factor')
        self.aggregate(self.assertAlmostEqual,
                       ed.advisability(),
                       -1.8,
                       places=3,
                       tag='advisability')

        self.aggregate_tests()
Example #2
0
class TestHighTempEdgeCases(TestA2):
    """
    Test edge cases around high temperature (45).
    Test air pressure impact on predictions.
    Test max wind speed impact on wind speed.
    """
    weather_data = WeatherData()
    day_low = WeatherDataItem(1, 44, 29, 10, 49, 14, 40, "N", 1, 1015)
    day_mid = WeatherDataItem(2, 45, 30, 10, 50, 15, 60, "SE", 2, 1016)
    day_high = WeatherDataItem(3, 46, 31, 10, 51, 16, 100, "W", 3, 1017)

    @skipIfFailed(TestDesign,
                  TestDesign.test_simple_prediction_defined.__name__,
                  tag='defined')
    def test_simple_prediction(self):
        """Test SimplePrediction with high temp, little rain, low humidity"""
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_low)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_high)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_mid)
        sp = self.prediction.SimplePrediction(
            TestHighTempEdgeCases.weather_data,
            len(TestHighTempEdgeCases.weather_data._weather_data))

        self.aggregate(self.assertEqual,
                       sp.get_number_days(),
                       len(TestHighTempEdgeCases.weather_data._weather_data),
                       tag='get_number_days')
        self.aggregate(self.assertEqual,
                       sp.chance_of_rain(),
                       18,
                       tag='chance_of_rain')
        self.aggregate(self.assertAlmostEqual,
                       sp.high_temperature(),
                       46,
                       places=2,
                       tag='high_temperature')
        self.aggregate(self.assertAlmostEqual,
                       sp.low_temperature(),
                       29,
                       places=2,
                       tag='low_temperature')
        self.aggregate(self.assertEqual, sp.humidity(), 50, tag='humidity')
        self.aggregate(self.assertEqual,
                       sp.cloud_cover(),
                       2,
                       tag='cloud_cover')
        self.aggregate(self.assertEqual, sp.wind_speed(), 15, tag='wind_speed')

        self.aggregate_tests()

    @skipIfFailed(TestDesign,
                  TestDesign.test_sophisticated_prediction_defined.__name__,
                  tag='defined')
    def test_sophisticated_prediction_high_pressure(self):
        """Test SophisticatedPrediction with high temp and high pressure"""
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_low)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_mid)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_high)
        sp = self.prediction.SophisticatedPrediction(
            TestHighTempEdgeCases.weather_data,
            len(TestHighTempEdgeCases.weather_data._weather_data))

        self.aggregate(self.assertEqual,
                       sp.get_number_days(),
                       len(TestHighTempEdgeCases.weather_data._weather_data),
                       tag='get_number_days')
        self.aggregate(self.assertEqual,
                       sp.chance_of_rain(),
                       14,
                       tag='chance_of_rain')
        self.aggregate(self.assertAlmostEqual,
                       sp.high_temperature(),
                       47,
                       places=2,
                       tag='high_temperature')
        self.aggregate(self.assertAlmostEqual,
                       sp.low_temperature(),
                       30,
                       places=2,
                       tag='low_temperature')
        self.aggregate(self.assertEqual, sp.humidity(), 35, tag='humidity')
        self.aggregate(self.assertEqual,
                       sp.cloud_cover(),
                       2,
                       tag='cloud_cover')
        self.aggregate(self.assertEqual, sp.wind_speed(), 18, tag='wind_speed')

        self.aggregate_tests()

    @skipIfFailed(TestDesign,
                  TestDesign.test_sophisticated_prediction_defined.__name__,
                  tag='defined')
    def test_sophisticated_prediction_equal_pressure(self):
        """Test SophisticatedPrediction with high temp and equal pressure"""
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_low)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_high)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_mid)
        sp = self.prediction.SophisticatedPrediction(
            TestHighTempEdgeCases.weather_data,
            len(TestHighTempEdgeCases.weather_data._weather_data))

        self.aggregate(self.assertEqual,
                       sp.get_number_days(),
                       len(TestHighTempEdgeCases.weather_data._weather_data),
                       tag='get_number_days')
        self.aggregate(self.assertEqual,
                       sp.chance_of_rain(),
                       17,
                       tag='chance_of_rain')
        self.aggregate(self.assertAlmostEqual,
                       sp.high_temperature(),
                       45,
                       places=2,
                       tag='high_temperature')
        self.aggregate(self.assertAlmostEqual,
                       sp.low_temperature(),
                       30,
                       places=2,
                       tag='low_temperature')
        self.aggregate(self.assertEqual, sp.humidity(), 50, tag='humidity')
        self.aggregate(self.assertEqual,
                       sp.cloud_cover(),
                       2,
                       tag='cloud_cover')
        self.aggregate(self.assertEqual, sp.wind_speed(), 15, tag='wind_speed')

        self.aggregate_tests()

    @skipIfFailed(TestDesign,
                  TestDesign.test_sophisticated_prediction_defined.__name__,
                  tag='defined')
    def test_sophisticated_prediction_low_pressure(self):
        """Test SophisticatedPrediction with high temp and low pressure"""
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_mid)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_high)
        TestHighTempEdgeCases.weather_data._weather_data.append(
            TestHighTempEdgeCases.day_low)
        sp = self.prediction.SophisticatedPrediction(
            TestHighTempEdgeCases.weather_data,
            len(TestHighTempEdgeCases.weather_data._weather_data))

        self.aggregate(self.assertEqual,
                       sp.get_number_days(),
                       len(TestHighTempEdgeCases.weather_data._weather_data),
                       tag='get_number_days')
        self.aggregate(self.assertEqual,
                       sp.chance_of_rain(),
                       20,
                       tag='chance_of_rain')
        self.aggregate(self.assertAlmostEqual,
                       sp.high_temperature(),
                       45,
                       places=2,
                       tag='high_temperature')
        self.aggregate(self.assertAlmostEqual,
                       sp.low_temperature(),
                       28,
                       places=2,
                       tag='low_temperature')
        self.aggregate(self.assertEqual, sp.humidity(), 65, tag='humidity')
        self.aggregate(self.assertEqual,
                       sp.cloud_cover(),
                       4,
                       tag='cloud_cover')
        self.aggregate(self.assertEqual, sp.wind_speed(), 15, tag='wind_speed')

        self.aggregate_tests()