Exemple #1
0
    def test_motor_to_action(self):

        # set([(active_motors, action)])
        # each motor is mapped to one action. It is only meaningful to
        # activate one motor at the time. All other combinations of
        # active motors are mapped to the action '-' (do nothing)
        motors = ['<', '>', '^', 'v']
        motors_to_action1 = {
            frozenset([0]): '<',
            frozenset([1]): '>',
            frozenset([2]): '^',
            frozenset([3]): 'v',
            '*': '-'
        }

        mnetwork = MotorNetwork(motors, motors_to_action1)
        mnetwork.update(frozenset([0]))
        self.assertTrue(mnetwork.get_action() == '<')
        mnetwork.update(frozenset([1]))
        self.assertTrue(mnetwork.get_action() == '>')
        mnetwork.update(frozenset([2]))
        self.assertTrue(mnetwork.get_action() == '^')
        mnetwork.update(frozenset([3]))
        self.assertTrue(mnetwork.get_action() == 'v')

        # Motor model where all combinations of active motors have an action
        motors_to_action2 = {
            frozenset(): '<',
            frozenset([0]): '>',
            frozenset([1]): '^',
            frozenset([0, 1]): 'v'
        }

        mnetwork = MotorNetwork(motors, motors_to_action2)
        mnetwork.update(frozenset())
        self.assertTrue(mnetwork.get_action() == '<')
        mnetwork.update(frozenset([0]))
        self.assertTrue(mnetwork.get_action() == '>')
        mnetwork.update(frozenset([1]))
        self.assertTrue(mnetwork.get_action() == '^')
        mnetwork.update(frozenset([0, 1]))
        self.assertTrue(mnetwork.get_action() == 'v')
Exemple #2
0
    def test_MOTOR_AND_SEQ(self):
        mnetwork = MotorNetwork()
        n1 = mnetwork.add_MOTOR_node('m1')
        self.assertTrue(mnetwork.get() == set())

        mnetwork.update(set([n1]))
        self.assertTrue(mnetwork.get() == set([0]))

        mnetwork.update(set())
        self.assertTrue(mnetwork.get() == set())

        n2 = mnetwork.add_MOTOR_node('m2')
        mnetwork.update(set([n2]))
        self.assertTrue(mnetwork.get() == set([n2]))

        mnetwork.update(set([n2, n1]))
        self.assertTrue(mnetwork.get() == set([n1, n2]))

        n3 = mnetwork.add_MAND_node([n1, n2])
        mnetwork.update(set())
        self.assertTrue(mnetwork.get() == set())
        mnetwork.update(set([n3]))
        self.assertTrue(mnetwork.get() == set([n1, n2]))

        n4 = mnetwork.add_MOTOR_node('m3')
        n5 = mnetwork.add_MSEQ_node([n3, n4])
        mnetwork.update(set())
        self.assertTrue(mnetwork.get() == set())
        mnetwork.update(set())
        self.assertTrue(mnetwork.get() == set())
        mnetwork.update(set([n5]))
        self.assertTrue(mnetwork.get() == set([n1, n2]))
        mnetwork.update(set())
        self.assertTrue(mnetwork.get() == set([n4]))
        mnetwork.update(set())
        self.assertTrue(mnetwork.get() == set())

        mnetwork.delete_nodes([n5])
        mnetwork.update(set([n4]))
        self.assertTrue(mnetwork.get() == set([n4]))