class ModuleTests(unittest.TestCase):
    """
    Module tests for the water-regulation module
    """
    def test_module(self):
        """Test the water regulation module."""
        self.ip_addr = '127.0.0.1'
        self.port = '8000'
        urllib.request.urlopen = MagicMock(return_value=5)
        self.sensor = Sensor(self.ip_addr, self.port)
        self.pump = Pump(self.ip_addr, self.port)
        self.decider = Decider(100, 0.05)

        self.controller = Controller(self.sensor, self.pump, self.decider)
        self.controller.pump.set_state = MagicMock(return_value=True)

        for action in self.controller.actions.values():
            for height in range(89 - 111):
                self.controller.sensor.measure = MagicMock(return_value=height)
                # Line too long, but impossible to shorten
                self.controller.pump.get_state = \
                    MagicMock(return_value=self.decider.decide(height,
                                                               action,
                                                               self.controller.actions))
                self.controller.tick()
示例#2
0
    def test_module(self):
        """
        Go through various sensor.measure and pump.get_state values to verify
        the compatibility of decider and controller.
        """
        dec = Decider(100, .05)
        control = Controller(
            Sensor("127.0.0.1", "8000"),
            Pump("127.0.0.1", "8000"),
            dec
        )

        control.pump.set_state = MagicMock(return_value=True)

        levels = [110, 90, 99]

        for pump_act in control.actions.values():
            control.pump.get_state = MagicMock(return_value=pump_act)
            for water_h in levels:
                control.sensor.measure = MagicMock(return_value=water_h)
                control.tick()
                control.pump.get_state = MagicMock(
                    return_value=dec.decide(
                        control.sensor.measure(),
                        control.pump.get_state(),
                        control.actions
                    )
                )
    def test_controller_tick(self):
        """test the tick function in the controller"""

        sensor = Sensor('127.0.0.1', 8000)
        pump = Pump('127.0.0.1', 8000)
        dec = Decider(100, .05)
        con = Controller(sensor, pump, dec)

        # liquid height
        sensor.measure = MagicMock(return_value=94)

        # state of pump
        pump.get_state = MagicMock(return_value=pump.PUMP_IN)

        # decider next state for pump
        dec.decide = MagicMock(return_value=pump.PUMP_IN)

        # this line was added to fix my error
        pump.set_state = MagicMock(return_value=True)

        con.tick()

        sensor.measure.assert_called_with()
        pump.get_state.assert_called_with()
        dec.decide.assert_called_with(94, pump.PUMP_IN, actions)
示例#4
0
    def third_controller_test(self, address, port):
        '''Tests the ability to query the decider for the next appropriate state
        given a set of starting conditions. Note, this will only test one set of starting
        conditions. Exhaustive testing of the deciders logic is performed in DeciderTests'''

        if True:
            logger.info("Starting third controller test")
            #Creating pump, sensor, and decider for test case
            my_pump = Pump(address, port)
            my_sensor = Sensor(address, port)
            my_decider = Decider(10, 1)
            #Passing pump, sensor, and decider to controller
            my_controller = Controller(my_sensor, my_pump, my_decider)
            logger.info("Done with third controller test")

            my_decider.decide(500, my_decider.target_height,
                              my_controller.actions)
示例#5
0
    def test_decide(self):
        decider = Decider(100, 0.05)
        self.assertEqual(ACTIONS['PUMP_IN'], decider.decide(90, ACTIONS['PUMP_OFF'], ACTIONS))
        self.assertEqual(ACTIONS['PUMP_OUT'], decider.decide(110, ACTIONS['PUMP_OFF'], ACTIONS))
        self.assertEqual(ACTIONS['PUMP_OFF'], decider.decide(95, ACTIONS['PUMP_OFF'], ACTIONS))
        self.assertEqual(ACTIONS['PUMP_OFF'], decider.decide(105, ACTIONS['PUMP_OFF'], ACTIONS))

        self.assertEqual(ACTIONS['PUMP_OFF'], decider.decide(110, ACTIONS['PUMP_IN'], ACTIONS))
        self.assertEqual(ACTIONS['PUMP_IN'], decider.decide(90, ACTIONS['PUMP_IN'], ACTIONS))

        self.assertEqual(ACTIONS['PUMP_OFF'], decider.decide(90, ACTIONS['PUMP_OUT'], ACTIONS))
        self.assertEqual(ACTIONS['PUMP_OUT'], decider.decide(110, ACTIONS['PUMP_OUT'], ACTIONS))
示例#6
0
    def third_decider_test(self, address, port):
        '''Behavior Test: If the pump is off and the height is within the margin region or on
             the exact boundary of the margin region, then the pump shall remain at
             PUMP_OFF.'''

        logger.info("running third decider test")
        my_pump = Pump(address, port)
        my_sensor = Sensor(address, port)
        my_decider = Decider(10, 1)
        my_controller = Controller(my_sensor, my_pump, my_decider)
        try:
            self.assertequals(
                my_decider.decide(my_decider.target_height + my_decider.margin,
                                  0, my_controller.actions), 0)
            self.assertequals(
                my_decider.decide(my_decider.target_height - my_decider.margin,
                                  0, my_controller.actions), 0)
        except Exception as exception:
            logger.critical(exception)
示例#7
0
class DeciderTests(unittest.TestCase):
    """Unit tests for the Decider class"""
    def setUp(self):
        """Set up each test with an actions dict"""
        self.actions = {'PUMP_IN': 1, 'PUMP_OFF': 0, 'PUMP_OUT': -1}
        self.decider = Decider(100, 0.05)

    def test_pump_off_and_height_below_margin(self):
        """
        1. If the pump is off and the height is below the margin region,
        then the pump should be turned to PUMP_IN.
        """
        self.assertEqual(1, self.decider.decide(101, 0, self.actions))

    def test_pump_off_and_height_above_margin(self):
        """
        2. If the pump is off and the height is above the margin region,
        then the pump should be turned to PUMP_OUT.
        """
        self.assertEqual(-1, self.decider.decide(106, 0, self.actions))

    def test_pump_off_and_height_is_above_target_but_equal_margin(self):
        """
        3. If the pump is off and the height is within the margin region
        or on the exact boundary of the margin region, then the pump shall
         remain at PUMP_OFF.
        """
        self.assertEqual(0, self.decider.decide(105, 0, self.actions))

    def test_pump_on_and_height_above_margin(self):
        """
4a. If the pump is performing PUMP_IN and the height is above the target
             height, then the pump shall be turned to PUMP_OFF
        """
        self.assertEqual(0, self.decider.decide(110, 1, self.actions))

    def test_pump_on_and_height_below_margin(self):
        """
4b. If the pump is performing PUMP_IN and the height is below the target
             height, then the pump shall remain PUMP_IN
        """
        self.assertEqual(1, self.decider.decide(99, 1, self.actions))

    def test_pump_out_and_height_below_margin(self):
        """
5a. If the pump is performing PUMP_OUT and the height is below the target
             height, then the pump shall be turned to PUMP_OFF
        """
        self.assertEqual(0, self.decider.decide(90, -1, self.actions))

    def test_pump_out_and_height_above_margin(self):
        """
5b. If the pump is performing PUMP_OUT and the height is above the target
             height, then the pump shall remain PUMP_OUT
        """
        self.assertEqual(-1, self.decider.decide(190, -1, self.actions))
示例#8
0
    def integration_test(self):
        '''Uses mocked Sensor and Pump as inputs into a decider and controller,
        tests controller output for given inputs'''
        '''For the integration check we are only checking the end result of our function calls,
        in this case the ability to correctly return true from teh set_state function with
        the previous functions as inputs'''

        actions = {'PUMP_IN': 1, 'PUMP_OFF': 0, 'PUMP_OUT': -1}
        logger.info("Begininning integration_test")
        my_decider = Decider(5.0, 1)
        my_controller = Controller(self.Sensor, self.Pump, my_decider)
        print(
            my_decider.decide(self.Sensor.measure(), self.Pump.get_state,
                              actions))

        #Tick Behavior 4
        assert my_controller.Pump.set_state(
            my_decider.decide(self.Sensor.measure(), self.Pump.get_state,
                              actions)) == True
        #Final check
        assert my_controller.tick() == None
示例#9
0
    def second_decider_test(self, address, port):
        '''Behavior Test: If the pump is off and the height is above the margin region, then the
             pump should be turned to PUMP_OUT.'''

        logger.info("running second decider test")
        my_pump = Pump(address, port)
        my_sensor = Sensor(address, port)
        my_decider = Decider(10, 1)
        my_controller = Controller(my_sensor, my_pump, my_decider)
        try:
            self.assertequals(my_decider.decide(12, 0, my_controller.actions),
                              -1)
        except Exception as exception:
            logger.critical(exception)
示例#10
0
 def test_tick(self):
     """
     Testing the tick method in controller
     """
     pump = Pump('127.0.0.1', 8000)
     sensor = Sensor('127.0.0.1', 8000)
     decider = Decider(100, .05)
     controller = Controller(sensor, pump, decider)
     sensor.measure = MagicMock(return_value=95)
     pump.get_state = MagicMock(return_value=pump.PUMP_IN)
     decider.decide = MagicMock(return_value=pump.PUMP_IN)
     pump.set_state = MagicMock(return_value=True)
     controller.tick()
     sensor.measure.assert_called_with()
     pump.get_state.assert_called_with()
     decider.decide.assert_called_with(95, pump.PUMP_IN, actions)
示例#11
0
    def fourth_decider_test(self, address, port):
        '''Behavior Test: If the pump is performing PUMP_IN and the height is above the target
             height, then the pump shall be turned to PUMP_OFF, otherwise the pump
             shall remain at PUMP_IN.'''

        logger.info("running fourth decider test")
        my_pump = Pump(address, port)
        my_sensor = Sensor(address, port)
        my_decider = Decider(10, 1)
        my_controller = Controller(my_sensor, my_pump, my_decider)
        try:
            self.assertequals(
                my_decider.decide(my_decider.target_height + 1, 1,
                                  my_controller.actions), 0)
        except Exception as exception:
            logger.critical(exception)
示例#12
0
 def test_tick(self):
     """
     Testing the tick method in controller
     :return:
     """
     p = Pump('127.0.0.1', 8080)
     s = Sensor('127.0.0.1', 8083)
     d = Decider(100, .10)
     c = Controller(s, p, d)
     s.measure = MagicMock(return_value=95)
     p.get_state = MagicMock(return_value=p.PUMP_IN)
     d.decide = MagicMock(return_value=p.PUMP_IN)
     p.set_state = MagicMock(return_value=True)
     c.tick()
     s.measure.assert_called_with()
     p.get_state.assert_called_with()
     d.decide.assert_called_with(95, p.PUMP_IN, actions)
示例#13
0
 def test_water(self):
     """
     the test method
     """
     pump = Pump('127.0.0.1', '8000')
     decider = Decider(100, 2)
     sensor = Sensor('127.0.0.1', '8000')
     controller = Controller(sensor, pump, decider)
     controller.pump.set_state = MagicMock(return_value=True)
     controller.pump.get_state = MagicMock(return_value=True)
     # level = [100, 100, 95]
     for act in controller.actions.values():
         for level in range(0, 200, 1):
             controller.sensor.measure = MagicMock(return_value=level)
             controller.pump.get_state = MagicMock(return_value=decider.decide(level, act, controller.actions))
             controller.pump.set_state = MagicMock(return_value=True)
             controller.tick()
 def test_tick(self):
     """
     Testing the tick method in controller
     :return:
     """
     pump_address = Pump('127.0.0.1', 8000)
     sensor_address = Sensor('127.0.0.1', 8000)
     decider_vals = Decider(100, .10)
     controller_all = Controller(sensor_address, pump_address, decider_vals)
     sensor_address.measure = MagicMock(return_value=95)
     pump_address.get_state = MagicMock(return_value=pump_address.PUMP_IN)
     decider_vals.decide = MagicMock(return_value=pump_address.PUMP_IN)
     pump_address.set_state = MagicMock(return_value=True)
     controller_all.tick()
     sensor_address.measure.assert_called_with()
     pump_address.get_state.assert_called_with()
     decider_vals.decide.assert_called_with(95, pump_address.PUMP_IN,
                                            actions)
    def test_water(self):
        """
        Integration test
        """
        pump_address = Pump('127.0.0.1', '8000')

        sensor_address = Sensor('127.0.0.1', '8000')
        decider_vals = Decider(1000.0, .10)
        controller_all = Controller(sensor_address, pump_address, decider_vals)
        controller_all.pump.set_state = MagicMock(return_value=True)
        for action in controller_all.actions.values():
            for water_level in range(500, 2000, 50):
                controller_all.sensor.measure = MagicMock(
                    return_value=water_level)
                controller_all.pump.get_state = MagicMock(
                    return_value=decider_vals.decide(water_level, action,
                                                     controller_all.actions))
                self.assertTrue(controller_all.tick())
示例#16
0
    def test_tick(self):
        """
        Tests each tick
        """

        pump = Pump('127.0.0.1', '8000')
        decider = Decider(100, 2)
        sensor = Sensor('127.0.0.1', '8000')
        controller = Controller(sensor, pump, decider)
        sensor.measure = MagicMock(return_value=102)
        pump.set_state = MagicMock(return_value=pump.PUMP_OFF)
        pump.get_state = MagicMock(return_value=pump.PUMP_OFF)
        decider.decide = MagicMock(return_value=pump.PUMP_OFF)
        controller.tick()
        sensor.measure.assert_called_with()
        pump.get_state.assert_called_with()
        decider.decide.assert_called_with(102, pump.PUMP_OFF,
                                          controller.actions)
示例#17
0
 def test_app(self):
     """
     Testing the app
     :return:
     """
     p = Pump('127.0.0.1', '8080')
     s = Sensor('127.0.0.1', '8083')
     d = Decider(100, .10)
     c = Controller(s, p, d)
     c.pump.set_state = MagicMock(return_value=True)
     for action in c.actions.values():
         for water_level in range(50, 150, 5):
             # measuring the water level
             c.sensor.measure = MagicMock(return_value=water_level)
             # getting the state of the pump
             c.pump.get_state = MagicMock(return_value=d.decide(water_level, action, c.actions))
             # running the tick functions
             c.tick()
示例#18
0
 def test_decider_decide(self):
     """
     Unit test for decider
     """
     deciders = Decider(100, .05)
     self.assertEqual(1, deciders.decide(90, actions['PUMP_OFF'], actions))
     self.assertEqual(1, deciders.decide(90, actions['PUMP_IN'], actions))
     self.assertEqual(-1, deciders.decide(120, actions['PUMP_OFF'],
                                          actions))
     self.assertEqual(-1, deciders.decide(120, actions['PUMP_OUT'],
                                          actions))
     self.assertEqual(0, deciders.decide(100, actions['PUMP_OFF'], actions))
     self.assertEqual(0, deciders.decide(120, actions['PUMP_IN'], actions))
     self.assertEqual(0, deciders.decide(90, actions['PUMP_OUT'], actions))
    def test_decider_decide(self):
        """
        Test the decide method
        """

        decider = Decider(1000.0, 0.5)

        result = decider.decide(200, Pump.PUMP_OFF, actions)
        self.assertEqual(result, Pump.PUMP_IN)
        result = decider.decide(2000, Pump.PUMP_OFF, actions)
        self.assertEqual(result, Pump.PUMP_OUT)
        result = decider.decide(500, Pump.PUMP_OFF, actions)
        self.assertEqual(result, Pump.PUMP_OFF)
        result = decider.decide(1001, Pump.PUMP_IN, actions)
        self.assertEqual(result, Pump.PUMP_OFF)
        result = decider.decide(999, Pump.PUMP_IN, actions)
        self.assertEqual(result, Pump.PUMP_IN)
        result = decider.decide(999, Pump.PUMP_OUT, actions)
        self.assertEqual(result, Pump.PUMP_OFF)
        result = decider.decide(1001, Pump.PUMP_OUT, actions)
        self.assertEqual(result, Pump.PUMP_OUT)
示例#20
0
    def test_decider(self):
        """"test decider.py"""

        target = 100
        margin = .05

        case1 = Decider(target, margin)

        high = 107
        within = 97
        low = 94

        self.assertEqual(1, case1.decide(low, actions['PUMP_OFF'], actions))
        self.assertEqual(-1, case1.decide(high, actions['PUMP_OFF'], actions))
        self.assertEqual(0, case1.decide(within, actions['PUMP_OFF'], actions))
        self.assertEqual(0, case1.decide(101, actions['PUMP_IN'], actions))
        self.assertEqual(1, case1.decide(100, actions['PUMP_IN'], actions))
        self.assertEqual(0, case1.decide(90, actions['PUMP_OUT'], actions))
        self.assertEqual(-1, case1.decide(101, actions['PUMP_OUT'], actions))
示例#21
0
 def test_decider_decide(self):
     """
     Unit test for decider
     :return:
     """
     deciders = Decider(100, .10)
     decision1 = deciders.decide(85, actions['PUMP_OFF'], actions)
     decision2 = deciders.decide(115, actions['PUMP_OFF'], actions)
     decision3 = deciders.decide(105, actions['PUMP_OFF'], actions)
     decision4 = deciders.decide(105, actions['PUMP_IN'], actions)
     decision5 = deciders.decide(95, actions['PUMP_IN'], actions)
     decision6 = deciders.decide(95, actions['PUMP_OUT'], actions)
     decision7 = deciders.decide(105, actions['PUMP_OUT'], actions)
     self.assertEqual(actions['PUMP_IN'], decision1)
     self.assertEqual(actions['PUMP_OUT'], decision2)
     self.assertEqual(actions['PUMP_OFF'], decision3)
     self.assertEqual(actions['PUMP_OFF'], decision4)
     self.assertEqual(actions['PUMP_IN'], decision5)
     self.assertEqual(actions['PUMP_OFF'], decision6)
     self.assertEqual(actions['PUMP_OUT'], decision7)
示例#22
0
 def test_decide(self):
     """
     Test decider's decide method
     """
     dec = Decider(100, .05)
     acts = {
         'PUMP_IN': 1,
         'PUMP_OUT': -1,
         'PUMP_OFF': 0,
     }
     above = 110
     below = 90
     inside = 99
     self.assertEqual(1, dec.decide(below, acts['PUMP_OFF'], acts))
     self.assertEqual(1, dec.decide(below, acts['PUMP_IN'], acts))
     self.assertEqual(-1, dec.decide(above, acts['PUMP_OFF'], acts))
     self.assertEqual(-1, dec.decide(above, acts['PUMP_OUT'], acts))
     self.assertEqual(0, dec.decide(inside, acts['PUMP_OFF'], acts))
     self.assertEqual(0, dec.decide(above, acts['PUMP_IN'], acts))
     self.assertEqual(0, dec.decide(below, acts['PUMP_OUT'], acts))
示例#23
0
 def test_decider(self):
     """
     Unit test for the decider class
     """
     pump = Pump('127.0.0.1', '8000')
     decider = Decider(100, 2)
     actions = {
         'PUMP_IN': pump.PUMP_IN,
         'PUMP_OUT': pump.PUMP_OUT,
         'PUMP_OFF': pump.PUMP_OFF,
     }
     high = 105
     low = 95
     sweet = 101
     self.assertEqual(1, decider.decide(low, actions["PUMP_OFF"], actions))
     self.assertEqual(-1, decider.decide(high, actions["PUMP_OFF"],
                                         actions))
     self.assertEqual(0, decider.decide(sweet, actions["PUMP_OFF"],
                                        actions))
     self.assertEqual(0, decider.decide(high, actions["PUMP_IN"], actions))
     self.assertEqual(0, decider.decide(low, actions["PUMP_OUT"], actions))
     self.assertEqual(1, decider.decide(low, actions["PUMP_IN"], actions))
     self.assertEqual(-1, decider.decide(high, actions["PUMP_OUT"],
                                         actions))
示例#24
0
class DeciderTests(unittest.TestCase):
    """
    Unit tests for the Decider class
    """
    def setUp(self):
        """Set up decider for tests"""

        self.actions = {
            'PUMP_IN': 'PUMP_IN',
            'PUMP_OUT': 'PUMP_OUT',
            'PUMP_OFF': 'PUMP_OFF'
        }

        self.decider = Decider(10, 0.05)

    def test_decide_1(self):
        """The *decide* method shall obey the following behaviors:

           1. If the pump is off and the height is below the margin region,
           then the pump should be turned to PUMP_IN."""

        self.assertEqual('PUMP_IN', self.decider.decide(8, 'PUMP_OFF'))

    def test_decide_2(self):
        """The *decide* method shall obey the following behaviors:

           2. If the pump is off and the height is above the margin region,
           then the pump should be turned to PUMP_OUT."""

        self.assertEqual('PUMP_OUT', self.decider.decide(12, 'PUMP_OFF'))

    def test_decide_3(self):
        """The *decide* method shall obey the following behaviors:

            3. If the pump is off and the height is within the margin region
            or on the exact boundary of the margin region, then the pump
            shall remain at PUMP_OFF."""

        self.assertEqual('PUMP_OFF', self.decider.decide(10, 'PUMP_OFF'))
        self.assertEqual('PUMP_OFF', self.decider.decide(10.5, 'PUMP_OFF'))
        self.assertEqual('PUMP_OFF', self.decider.decide(9.5, 'PUMP_OFF'))

    def test_decide_4(self):
        """The *decide* method shall obey the following behaviors:

            4. If the pump is performing PUMP_IN and the height is above
            target height, then the pump shall be turned to PUMP_OFF,
            otherwise the pump shall remain at PUMP_IN."""

        self.assertEqual('PUMP_OFF', self.decider.decide(11, 'PUMP_IN'))
        self.assertEqual('PUMP_IN', self.decider.decide(9, 'PUMP_IN'))

    def test_decide_5(self):
        """The *decide* method shall obey the following behaviors:

            5. If the pump is performing PUMP_OUT and the height is below the
            target height, then the pump shall be turned to PUMP_OFF,
            otherwise the pump shall remain at PUMP_OUT."""

        self.assertEqual('PUMP_OFF', self.decider.decide(7, 'PUMP_OUT'))
        self.assertEqual('PUMP_OUT', self.decider.decide(13, 'PUMP_OUT'))

    def test_decide_wrong_action(self):
        """Test for error message if current action not in action dict"""

        self.assertFalse(self.decider.decide(10, "Unknown"))
示例#25
0
class DeciderTests(unittest.TestCase):
    """Unit tests for the Decider class."""

    # # TODO: write a test or tests for each of the behaviors defined for
    # #       Decider.decide
    #
    # def test_dummy(self):
    #     """
    #     Just some example syntax that you might use
    #     """
    #
    #     pump = Pump('127.0.0.1', 8000)
    #     pump.set_state = MagicMock(return_value=True)
    #
    #     self.fail("Remove this test.")

    def setUp(self):
        """Run each time before any test method is run."""
        self.pump = Pump('127.0.0.1', 8000)

        self.actions = {
            'PUMP_IN': self.pump.PUMP_IN,
            'PUMP_OUT': self.pump.PUMP_OUT,
            'PUMP_OFF': self.pump.PUMP_OFF,
        }

        self.decider = Decider(100, 0.05)

    def test_decider_init(self):
        """Test that decider gets intantiated with expected params."""
        self.assertIsInstance(self.decider, Decider)
        self.assertEqual(self.decider.target_height, 100)
        self.assertEqual(self.decider.margin, 0.05)

    def test_off_and_below_then_pump_in(self):
        """Test behavior 1.
        1. If the pump is off and the height is below the margin region,
        then the pump should be turned to PUMP_IN.
        """
        self.assertEqual(
            self.decider.decide(90, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_IN)

    def test_off_and_above_then_pump_out(self):
        """Test behavior 2.
        2. If the pump is off and the height is above the margin region, then
        the pump should be turned to PUMP_OUT.
        """
        self.assertEqual(
            self.decider.decide(110, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_OUT)

    def test_off_and_within_then_pump_off(self):
        """Test behavior 3.
        3. If the pump is off and the height is within the margin region or on
        the exact boundary of the margin region, then the pump shall remain at
        PUMP_OFF.
        """
        # pump off and height at the margin boundary then pump remains off
        self.assertEqual(
            self.decider.decide(105, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_OFF)
        # pump off and height at the margin boundary then pump remains off
        self.assertEqual(
            self.decider.decide(95, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_OFF)
        # pump off and height is withon margin then pump remains off
        self.assertEqual(
            self.decider.decide(101, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_OFF)
        # pump off and height is withon margin then pump remains off
        self.assertEqual(
            self.decider.decide(100, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_OFF)
        # pump off and height is withon margin then pump remains off
        self.assertEqual(
            self.decider.decide(99, self.pump.PUMP_OFF, self.actions),
            self.pump.PUMP_OFF)

    def test_in_and_above_then_pump_off_else_in(self):
        """Test behavior 4.
        4. If the pump is performing PUMP_IN and the height is above the
        target height, then the pump shall be turned to PUMP_OFF, otherwise
        the pump shall remain at PUMP_IN.
        """
        # pump in and height above target then pump off
        self.assertEqual(self.decider.decide(101, 1, self.actions),
                         self.pump.PUMP_OFF)
        # pump in and height below  target then pump in
        self.assertEqual(self.decider.decide(99, 1, self.actions),
                         self.pump.PUMP_IN)
        # pump in and height at target then pump in
        self.assertEqual(self.decider.decide(100, 1, self.actions),
                         self.pump.PUMP_IN)

    def test_out_and_below_then_pump_off_else_out(self):
        """Test behavior 5.
        5. If the pump is performing PUMP_OUT and the height is below
        the target height, then the pump shall be turned to PUMP_OFF,
        otherwise, the pump shall remain at PUMP_OUT.
        """
        # pump out and height is below then pump off
        self.assertEqual(self.decider.decide(99, -1, self.actions),
                         self.pump.PUMP_OFF)
        # pump out but height is at target then pump remains out
        self.assertEqual(self.decider.decide(100, -1, self.actions),
                         self.pump.PUMP_OUT)
        # pump out but height is above target then pump remains out
        self.assertEqual(self.decider.decide(110, -1, self.actions),
                         self.pump.PUMP_OUT)