예제 #1
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.SELECT = Selector(name="SELECT")
        self.SELECT.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.SELECT._id)
예제 #2
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.RANDOM = Random("RANDOM")
        self.RANDOM.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.RANDOM._id)
예제 #3
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.ALL = All("ALL")
        self.ALL.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.ALL._id)
예제 #4
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.RUNNER = Runner("RUNNER")
        self.RUNNER.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.RUNNER._id)
예제 #5
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.SEQUENCE = Sequencer("SEQUENCE")
        self.SEQUENCE.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.SEQUENCE._id)
예제 #6
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)
        self.CONTINUE2 = Continue(name="CONTINUE2", blackboard=self.blackboard)

        self.MAJORITY = Majority("MAJORITY")
        self.MAJORITY.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.MAJORITY._id)
예제 #7
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)
        self.CONTINUE2 = Continue(name="CONTINUE2", blackboard=self.blackboard)

        self.PROGRESS = Progressor("PROGRESS")
        self.PROGRESS.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.PROGRESS._id)
예제 #8
0
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE1 = Continue(name="CONTINUE1", blackboard=self.blackboard)
        self.CONTINUE2 = Continue(name="CONTINUE2", blackboard=self.blackboard)

        self.FIRST = First("FIRST")
        self.FIRST.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.FIRST._id)
예제 #9
0
class TestMajority(object):
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)
        self.CONTINUE2 = Continue(name="CONTINUE2", blackboard=self.blackboard)

        self.MAJORITY = Majority("MAJORITY")
        self.MAJORITY.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.MAJORITY._id)

    def test_success(self):
        self.MAJORITY.add_child(self.SUCCESS1)
        self.MAJORITY.add_child(self.SUCCESS2)

        result = self.MAJORITY.tick()
        assert_equal(result.status, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.PENDING)

    def test_fail(self):
        self.MAJORITY.add_child(self.FAIL1)
        self.MAJORITY.add_child(self.FAIL2)

        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)

        self.MAJORITY.add_child(self.SUCCESS1)
        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)

    def test_active(self):
        self.MAJORITY.add_child(self.CONTINUE)
        self.MAJORITY.add_child(self.SUCCESS1)
        self.MAJORITY.add_child(self.SUCCESS2)
        self.MAJORITY.add_child(self.FAIL1)
        self.MAJORITY.add_child(self.FAIL2)

        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)

    def test_cancel(self):
        self.MAJORITY.add_child(self.CONTINUE)
        self.MAJORITY.add_child(self.SUCCESS1)
        self.MAJORITY.add_child(self.SUCCESS2)
        self.MAJORITY.add_child(self.FAIL1)
        self.MAJORITY.add_child(self.FAIL2)

        self.MAJORITY.tick()
        self.MAJORITY._cancel()
        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)

    def test_force_child(self):
        self.MAJORITY.add_child(self.CONTINUE)
        self.MAJORITY.add_child(self.SUCCESS1)
        self.MAJORITY.add_child(self.SUCCESS2)
        self.MAJORITY.add_child(self.FAIL1)
        self.MAJORITY.add_child(self.FAIL2)

        self.MAJORITY.tick()
        self.CONTINUE.force(NodeStatus.SUCCESS)
        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)

        self.CONTINUE.force(NodeStatus.FAIL)
        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)

    def test_force_behavior(self):
        self.MAJORITY.add_child(self.CONTINUE)
        self.MAJORITY.add_child(self.SUCCESS1)
        self.MAJORITY.add_child(self.SUCCESS2)
        self.MAJORITY.add_child(self.FAIL1)
        self.MAJORITY.add_child(self.FAIL2)

        self.MAJORITY.tick()
        self.MAJORITY.force(NodeStatus.SUCCESS)
        result = self.MAJORITY.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)
예제 #10
0
class TestRandom(object):
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.RANDOM = Random("RANDOM")
        self.RANDOM.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.RANDOM._id)

    def test_empty(self):
        # if empty, configuration should succeed but set child to None
        self.RANDOM._configure()
        assert_equal(self.RANDOM.child, None)

        # if ticked, random should report success if no children
        result = self.RANDOM.tick()
        assert_equal(self.RANDOM.child, None)
        assert_equal(result, NodeStatus.SUCCESS)

    def test_success(self):
        self.RANDOM.add_child(self.SUCCESS1)
        self.RANDOM.add_child(self.FAIL1)
        self.RANDOM.add_child(self.CONTINUE)

        self.RANDOM._configure()
        assert_equal(self.RANDOM.child in self.RANDOM._children, True)
        while (self.RANDOM.child != self.SUCCESS1):
            self.RANDOM._configure()

        result = self.RANDOM.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.PENDING)

    def test_fail(self):
        self.RANDOM.add_child(self.SUCCESS1)
        self.RANDOM.add_child(self.FAIL1)
        self.RANDOM.add_child(self.CONTINUE)

        self.RANDOM._configure()
        assert_equal(self.RANDOM.child in self.RANDOM._children, True)
        while (self.RANDOM.child != self.FAIL1):
            self.RANDOM._configure()

        result = self.RANDOM.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.PENDING)

    def test_active(self):
        self.RANDOM.add_child(self.SUCCESS1)
        self.RANDOM.add_child(self.FAIL1)
        self.RANDOM.add_child(self.CONTINUE)

        self.RANDOM._configure()
        assert_equal(self.RANDOM.child in self.RANDOM._children, True)
        while (self.RANDOM.child != self.CONTINUE):
            self.RANDOM._configure()

        result = self.RANDOM.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.ACTIVE)

    def test_cancel(self):
        self.RANDOM.add_child(self.SUCCESS1)
        self.RANDOM.add_child(self.FAIL1)
        self.RANDOM.add_child(self.CONTINUE)

        self.RANDOM._configure()
        assert_equal(self.RANDOM.child in self.RANDOM._children, True)
        while (self.RANDOM.child != self.CONTINUE):
            self.RANDOM._configure()

        self.RANDOM.tick()
        self.RANDOM._cancel()
        result = self.RANDOM.tick()
        assert_equal(result, NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)

    def test_force_child(self):
        self.RANDOM.add_child(self.SUCCESS1)
        self.RANDOM.add_child(self.FAIL1)
        self.RANDOM.add_child(self.CONTINUE)

        self.RANDOM._configure()
        self.RANDOM.child.force(NodeStatus.SUCCESS)
        result = self.RANDOM.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.RANDOM.child._id),
                     NodeStatus.SUCCESS)

    def test_force_behavior(self):
        self.RANDOM.add_child(self.SUCCESS1)
        self.RANDOM.add_child(self.FAIL1)
        self.RANDOM.add_child(self.CONTINUE)

        self.RANDOM._configure()
        self.RANDOM.force(NodeStatus.FAIL)
        result = self.RANDOM.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.RANDOM.child._id),
                     NodeStatus.PENDING)
예제 #11
0
class TestSelector(object):
    def setUp(self):
        self.blackboard = Blackboard()
        self.FAIL1 = Fail(name="FAIL1", blackboard=self.blackboard)
        self.FAIL2 = Fail(name="FAIL2", blackboard=self.blackboard)
        self.SUCCESS1 = Success(name="SUCCESS1", blackboard=self.blackboard)
        self.SUCCESS2 = Success(name="SUCCESS2", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

        self.SELECT = Selector(name="SELECT")
        self.SELECT.set_blackboard(self.blackboard)
        self.nd = self.blackboard.get_memory(self.SELECT._id)

    def test_fail(self):
        self.SELECT.add_child(self.FAIL1)
        self.SELECT.add_child(self.FAIL2)

        result = self.SELECT.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)

    def test_success(self):
        self.SELECT.add_child(self.FAIL1)
        self.SELECT.add_child(self.FAIL2)
        self.SELECT.add_child(self.SUCCESS1)
        self.SELECT.add_child(self.SUCCESS2)

        result = self.SELECT.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.PENDING)

    def test_active(self):
        self.SELECT.add_child(self.CONTINUE)
        self.SELECT.add_child(self.FAIL1)
        self.SELECT.add_child(self.FAIL2)
        self.SELECT.add_child(self.SUCCESS1)
        self.SELECT.add_child(self.SUCCESS2)

        result = self.SELECT.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.PENDING)

    def test_cancel(self):
        self.SELECT.add_child(self.CONTINUE)
        self.SELECT.add_child(self.FAIL1)
        self.SELECT.add_child(self.FAIL2)
        self.SELECT.add_child(self.SUCCESS1)
        self.SELECT.add_child(self.SUCCESS2)

        self.SELECT.tick()
        self.SELECT._cancel()
        result = self.SELECT.tick()
        assert_equal(result, NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.PENDING)

    def test_force_child(self):
        self.SELECT.add_child(self.CONTINUE)
        self.SELECT.add_child(self.FAIL1)
        self.SELECT.add_child(self.FAIL2)
        self.SELECT.add_child(self.SUCCESS1)
        self.SELECT.add_child(self.SUCCESS2)

        self.SELECT.tick()
        self.CONTINUE.force(NodeStatus.FAIL)
        result = self.SELECT.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.PENDING)
        self.blackboard.clear_node_status()

    def test_force_behavior(self):
        self.SELECT.add_child(self.CONTINUE)
        self.SELECT.add_child(self.FAIL1)
        self.SELECT.add_child(self.FAIL2)
        self.SELECT.add_child(self.SUCCESS1)
        self.SELECT.add_child(self.SUCCESS2)

        self.SELECT.tick()
        self.SELECT.force(NodeStatus.FAIL)
        result = self.SELECT.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.FAIL1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.FAIL2._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS1._id),
                     NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS2._id),
                     NodeStatus.PENDING)
        self.blackboard.clear_node_status()
예제 #12
0
        time.sleep(0.1)

    print("Running example 2 (10 times) -- using a decorator")

    count = Count(name="count_index")
    repeat = Repeat(name="repeat_count", child=count)
    result = NodeStatus(NodeStatus.ACTIVE)

    for i in range(0, 10):
        result = repeat.tick()
        print result
        time.sleep(0.1)

    print("Running example 3 -- using a behavior")

    b = Blackboard()

    count1 = Count(name="count_1", blackboard=b)
    count2 = Count(name="count_2", blackboard=b)
    count3 = Count(name="count_3", blackboard=b)

    finish_counts = Sequencer("finish_counts", blackboard=b)
    finish_counts.add_child(count1)
    finish_counts.add_child(count2)
    finish_counts.add_child(count3)

    # change the limit for the count
    b.save("limit", 1, count1._id)
    b.save("limit", 2, count2._id)
    b.save("limit", 3, count3._id)
    def setUp(self):
        self.blackboard = Blackboard()

        self.FAILURE = Failure(name="FAILURE", blackboard=self.blackboard)
        self.SUCCESS = Success(name="SUCCESS", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)
class TestRepeat(object):
    def setUp(self):
        self.blackboard = Blackboard()

        self.FAILURE = Failure(name="FAILURE", blackboard=self.blackboard)
        self.SUCCESS = Success(name="SUCCESS", blackboard=self.blackboard)
        self.CONTINUE = Continue(name="CONTINUE", blackboard=self.blackboard)

    def test_fail(self):
        REPEAT_FAIL = Repeat(name="REPEAT_FAILURE",
                             blackboard=self.blackboard,
                             child=self.FAILURE)
        result = REPEAT_FAIL.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(REPEAT_FAIL._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.FAILURE._id),
                     NodeStatus.FAIL)

    def test_success(self):
        REPEAT_SUCCESS = Repeat(name="REPEAT_SUCCESS",
                                blackboard=self.blackboard,
                                child=self.SUCCESS)
        result = REPEAT_SUCCESS.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(REPEAT_SUCCESS._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS._id),
                     NodeStatus.SUCCESS)

    def test_active(self):
        ACTIVE = Repeat(name="REPEAT_CONTINUE",
                        blackboard=self.blackboard,
                        child=self.CONTINUE)
        result = ACTIVE.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(ACTIVE._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.ACTIVE)

    def test_cancel(self):
        ACTIVE = Repeat(name="REPEAT_CONTINUE",
                        blackboard=self.blackboard,
                        child=self.CONTINUE)
        result = ACTIVE.tick()
        ACTIVE._cancel()
        assert_equal(ACTIVE.get_result(), NodeStatus.CANCEL)
        assert_equal(ACTIVE._child.get_result(), NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(ACTIVE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)
        result = ACTIVE.tick()
        assert_equal(result, NodeStatus.CANCEL)
        assert_equal(ACTIVE.get_result(), NodeStatus.PENDING)
        assert_equal(ACTIVE._child.get_result(), NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(ACTIVE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)

    def test_cancel_child(self):
        ACTIVE = Repeat(name="REPEAT_CONTINUE",
                        blackboard=self.blackboard,
                        child=self.CONTINUE)
        ACTIVE.tick()
        ACTIVE._child._cancel()
        assert_equal(ACTIVE.get_result(), NodeStatus.ACTIVE)
        assert_equal(ACTIVE._child.get_result(), NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(ACTIVE._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)
        result = ACTIVE.tick()
        assert_equal(result.status, NodeStatus.CANCEL)
        assert_equal(ACTIVE.get_result(), NodeStatus.PENDING)
        assert_equal(ACTIVE._child.get_result(), NodeStatus.PENDING)
        assert_equal(self.blackboard.get_node_status(ACTIVE._id),
                     NodeStatus.CANCEL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)

    def test_force_child(self):
        NOT_SUCCESS = Repeat(name="NOT_SUCCESS",
                             blackboard=self.blackboard,
                             child=self.SUCCESS)
        NOT_SUCCESS._child.force(NodeStatus.FAIL)
        result = NOT_SUCCESS.tick()
        assert_equal(result, NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(NOT_SUCCESS._id),
                     NodeStatus.ACTIVE)
        assert_equal(self.blackboard.get_node_status(self.SUCCESS._id),
                     NodeStatus.FAIL)

    def test_force_behavior(self):
        NOT_FAIL = Repeat(name="NOT_FAILURE",
                          blackboard=self.blackboard,
                          child=self.FAILURE)
        result = NOT_FAIL.tick()
        NOT_FAIL.force(NodeStatus.SUCCESS)
        result = NOT_FAIL.tick()
        assert_equal(result, NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(NOT_FAIL._id),
                     NodeStatus.SUCCESS)
        assert_equal(self.blackboard.get_node_status(self.FAILURE._id),
                     NodeStatus.FAIL)

        NOT_CONTINUE = Repeat(name="NOT_CONTINUE",
                              blackboard=self.blackboard,
                              child=self.CONTINUE)
        result = NOT_CONTINUE.tick()
        NOT_CONTINUE.force(NodeStatus.FAIL)
        result = NOT_CONTINUE.tick()
        assert_equal(result, NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(NOT_CONTINUE._id),
                     NodeStatus.FAIL)
        assert_equal(self.blackboard.get_node_status(self.CONTINUE._id),
                     NodeStatus.CANCEL)