def test_b(self): """Test the case with precipitation on two days.""" level_control = LevelControlComputer() tomorrow = self.today + timedelta(1) intakes_timeseries = {} pumps_timeseries = {} vertical_timeseries = [TimeseriesStub((self.today, 2.0), (tomorrow, 1.0)), TimeseriesStub((self.today, 0.0), (tomorrow, 0.0)), TimeseriesStub((self.today, 0.0), (tomorrow, 0.0)), TimeseriesStub((self.today, 0.0), (tomorrow, 0.0))] water_levels = TimeseriesWithMemoryStub((self.today, 1.0), (tomorrow, 1.0)) self.open_water.retrieve_minimum_level = lambda : water_levels self.open_water.retrieve_maximum_level = lambda : water_levels timeseries = level_control.compute(self.open_water, self.buckets_summary, vertical_timeseries[0], vertical_timeseries[1], vertical_timeseries[2], vertical_timeseries[3], water_levels, water_levels, intakes_timeseries, pumps_timeseries) expected_timeseries = (TimeseriesStub((self.today, 0.0), (tomorrow, 0.0)), TimeseriesStub((self.today, -2.0), (tomorrow, -1.0))) self.assertEqual(expected_timeseries[0], timeseries['intake_wl_control']) self.assertEqual(expected_timeseries[1], timeseries['outtake_wl_control'])
def test_e(self): """Test the case with both precipitation and evaporation on two days. """ level_control = LevelControlComputer() tomorrow = self.today + timedelta(1) minimum_water_levels = TimeseriesWithMemoryStub((self.today, 0.98), (tomorrow, 0.98)) maximum_water_levels = TimeseriesWithMemoryStub((self.today, 1.02), (tomorrow, 1.02)) intakes_timeseries = {} pumps_timeseries = {} vertical_timeseries = [TimeseriesStub((self.today, 2.0), (tomorrow, 0.0)), TimeseriesStub((self.today, 0.0), (tomorrow, -6.0)), TimeseriesStub((self.today, 0.0), (tomorrow, 0.0)), TimeseriesStub((self.today, 0.0), (tomorrow, 0.0))] timeseries = level_control.compute(self.open_water, self.buckets_summary, vertical_timeseries[0], vertical_timeseries[1], vertical_timeseries[2], vertical_timeseries[3], minimum_water_levels, maximum_water_levels, intakes_timeseries, pumps_timeseries) expected_timeseries = TimeseriesStub((self.today, 12.0), (tomorrow, 8.0)) self.assertEqual(expected_timeseries, timeseries['storage'])
def test_c(self): """Test the case with evaporation on a single day. The precipitation does reduce the water level below the minimum. """ level_control = LevelControlComputer() intakes_timeseries = {} pumps_timeseries = {} vertical_timeseries = [TimeseriesStub((self.today, 0.0)), TimeseriesStub((self.today, -4.0)), TimeseriesStub((self.today, 0.0)), TimeseriesStub((self.today, 0.0))] timeseries = level_control.compute(self.open_water, self.buckets_summary, vertical_timeseries[0], vertical_timeseries[1], vertical_timeseries[2], vertical_timeseries[3], self.minimum_water_levels, self.maximum_water_levels, intakes_timeseries, pumps_timeseries) expected_timeseries = TimeseriesStub((self.today, 8.0)) self.assertEqual(expected_timeseries, timeseries['storage'])
def test_h(self): """Test the case with multiple pumps.""" level_control = LevelControlComputer() buckets_summary = BucketsSummary() intakes_timeseries = {} pumps = [Mock(), Mock()] pumps[0].computed_level_control = False pumps[0].__hash__ = Mock(return_value=0) pumps[1].computed_level_control = False pumps[1].__hash__ = Mock(return_value=1) pumps_timeseries = {pumps[0]: TimeseriesStub((self.today, -10)), pumps[1]: TimeseriesStub((self.today, -10))} vertical_timeseries = [TimeseriesStub((self.today, 8.0)), TimeseriesStub((self.today, -4.0)), TimeseriesStub((self.today, 2.0)), TimeseriesStub((self.today, 0.0))] timeseries = level_control.compute(self.open_water, buckets_summary, vertical_timeseries[0], vertical_timeseries[1], vertical_timeseries[2], vertical_timeseries[3], self.water_levels, self.water_levels, intakes_timeseries, pumps_timeseries) expected_timeseries = (TimeseriesStub((self.today, 14.0)), TimeseriesStub((self.today, 0.0))) self.assertEqual(expected_timeseries[0], timeseries['intake_wl_control']) self.assertEqual(expected_timeseries[1], timeseries['outtake_wl_control'])
def test_g(self): """Test the case with a single pump.""" level_control = LevelControlComputer() buckets_summary = BucketsSummary() intakes_timeseries = {} pump = PumpingStation() pump.computed_level_control = False pumps_timeseries = {pump:TimeseriesStub((self.today, -10))} vertical_timeseries = [TimeseriesStub((self.today, 8.0)), TimeseriesStub((self.today, -4.0)), TimeseriesStub((self.today, 2.0)), TimeseriesStub((self.today, 0.0))] timeseries = level_control.compute(self.open_water, buckets_summary, vertical_timeseries[0], vertical_timeseries[1], vertical_timeseries[2], vertical_timeseries[3], self.water_levels, self.water_levels, intakes_timeseries, pumps_timeseries) expected_timeseries = (TimeseriesStub((self.today, 4.0)), TimeseriesStub((self.today, 0.0))) self.assertEqual(expected_timeseries[0], timeseries['intake_wl_control']) self.assertEqual(expected_timeseries[1], timeseries['outtake_wl_control'])
def test_a(self): """Test the case with precipitation on a single day.""" level_control = LevelControlComputer() intakes_timeseries = {} pumps_timeseries = {} vertical_timeseries = [TimeseriesStub((self.today, 2.0)), TimeseriesStub((self.today, 0.0)), TimeseriesStub((self.today, 0.0)), TimeseriesStub((self.today, 0.0))] timeseries = level_control.compute(self.open_water, self.buckets_summary, vertical_timeseries[0], vertical_timeseries[1], vertical_timeseries[2], vertical_timeseries[3], self.water_levels, self.water_levels, intakes_timeseries, pumps_timeseries) expected_timeseries = (TimeseriesStub((self.today, 0.0)), TimeseriesStub((self.today, -2.0))) self.assertEqual(expected_timeseries[0], timeseries['intake_wl_control']) self.assertEqual(expected_timeseries[1], timeseries['outtake_wl_control'])