class WatertankSimulationTestCase(unittest.TestCase):
    def setUp(self):
        self.watertank = Watertank(1000, [10, 10], [10], 0.5)

    def test_water_raises(self):
        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["water"], so["water"])

    def test_water_lowers(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertLess(sf["water"], so["water"])

    def cleanUp(self):
        pass
Пример #2
0
class WatertankSimulationTestCase(unittest.TestCase):
    def setUp(self):
        self.watertank = Watertank(1000, [10, 10], [10], 0.5)

    def test_water_raises(self):
        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["water"], so["water"])

    def test_water_lowers(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertLess(sf["water"], so["water"])

    def cleanUp(self):
        pass
class WatertankSimulationTestCaseTemperatures(unittest.TestCase):
    def setUp(self):
        self.watertank = Watertank(1000, [10, 10], [10], 0.5, True)

    def test_not_overheat(self):

        self.assertFalse(self.watertank.firstPumpOverheated)
        self.assertFalse(self.watertank.secondPumpOverheated)

        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        self.assertFalse(self.watertank.firstPumpOverheated)
        self.assertFalse(self.watertank.secondPumpOverheated)

    def test_stay_within_temp_work_range(self):

        self.assertTrue(self.watertank.firstPumpWorkRange[1] >= self.watertank.firstPumpTemperature >=
                        self.watertank.secondPumpWorkRange[0])

        for i in range(3):
            self.watertank.update(1)

        self.assertTrue(self.watertank.firstPumpWorkRange[1] >= self.watertank.firstPumpTemperature >=
                        self.watertank.secondPumpWorkRange[0])

    def test_water_raises(self):
        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["water"], so["water"])

    def test_water_lowers(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertLess(sf["water"], so["water"])

    def test_left_temperature_raises(self):
        self.watertank.set_inputs([10, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["temperatures"][0], so["temperatures"][0])

    def test_left_temperature_remains(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        rso = self.watertank.firstPumpTemperature
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])
        rsf = self.watertank.firstPumpTemperature

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertEquals(rsf, rso)
        self.assertEquals(sf["temperatures"][0], so["temperatures"][0])

    def test_right_temperature_raises(self):
        self.watertank.set_inputs([0, 10])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["temperatures"][1], so["temperatures"][1])

    def test_right_temperature_remains(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        rso = self.watertank.secondPumpTemperature
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])
        rsf = self.watertank.secondPumpTemperature

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertEquals(rsf, rso)
        self.assertEquals(sf["temperatures"][1], so["temperatures"][1])

    def test_all_overheat(self):
        self.watertank.set_inputs([10, 10])

        for i in range(30):
            self.watertank.update(1)

        self.assertTrue(self.watertank.firstPumpOverheated)
        self.assertTrue(self.watertank.secondPumpOverheated)

    def test_all_recover_after_overheat(self):
        self.watertank.set_inputs([10, 10])

        for i in range(30):
            self.watertank.update(1)

        self.watertank.set_inputs([0, 0])

        for i in range(20):
            self.watertank.update(1)

        self.assertFalse(self.watertank.firstPumpOverheated)
        self.assertFalse(self.watertank.secondPumpOverheated)

    def cleanUp(self):
        pass
Пример #4
0
class WatertankSimulationTestCaseTemperatures(unittest.TestCase):
    def setUp(self):
        self.watertank = Watertank(1000, [10, 10], [10], 0.5, True)

    def test_not_overheat(self):

        self.assertFalse(self.watertank.firstPumpOverheated)
        self.assertFalse(self.watertank.secondPumpOverheated)

        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        self.assertFalse(self.watertank.firstPumpOverheated)
        self.assertFalse(self.watertank.secondPumpOverheated)

    def test_stay_within_temp_work_range(self):

        self.assertTrue(
            self.watertank.firstPumpWorkRange[1] >= self.watertank.
            firstPumpTemperature >= self.watertank.secondPumpWorkRange[0])

        for i in range(3):
            self.watertank.update(1)

        self.assertTrue(
            self.watertank.firstPumpWorkRange[1] >= self.watertank.
            firstPumpTemperature >= self.watertank.secondPumpWorkRange[0])

    def test_water_raises(self):
        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["water"], so["water"])

    def test_water_lowers(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertLess(sf["water"], so["water"])

    def test_left_temperature_raises(self):
        self.watertank.set_inputs([10, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["temperatures"][0], so["temperatures"][0])

    def test_left_temperature_remains(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        rso = self.watertank.firstPumpTemperature
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])
        rsf = self.watertank.firstPumpTemperature

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertEquals(rsf, rso)
        self.assertEquals(sf["temperatures"][0], so["temperatures"][0])

    def test_right_temperature_raises(self):
        self.watertank.set_inputs([0, 10])

        so = self.watertank.get_json_state([20, 20], [20])
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertGreater(sf["temperatures"][1], so["temperatures"][1])

    def test_right_temperature_remains(self):
        self.watertank.set_inputs([0, 0])

        so = self.watertank.get_json_state([20, 20], [20])
        rso = self.watertank.secondPumpTemperature
        for i in range(3):
            self.watertank.update(1)
        sf = self.watertank.get_json_state([20, 20], [20])
        rsf = self.watertank.secondPumpTemperature

        so = json.loads(so)
        sf = json.loads(sf)

        self.assertEquals(rsf, rso)
        self.assertEquals(sf["temperatures"][1], so["temperatures"][1])

    def test_all_overheat(self):
        self.watertank.set_inputs([10, 10])

        for i in range(30):
            self.watertank.update(1)

        self.assertTrue(self.watertank.firstPumpOverheated)
        self.assertTrue(self.watertank.secondPumpOverheated)

    def test_all_recover_after_overheat(self):
        self.watertank.set_inputs([10, 10])

        for i in range(30):
            self.watertank.update(1)

        self.watertank.set_inputs([0, 0])

        for i in range(20):
            self.watertank.update(1)

        self.assertFalse(self.watertank.firstPumpOverheated)
        self.assertFalse(self.watertank.secondPumpOverheated)

    def cleanUp(self):
        pass