예제 #1
0
    def test_initialization(self):
        node = b3.MemSequence()

        self.assertIsNotNone(node.id)
        self.assertEqual(node.name, 'MemSequence')
        self.assertEqual(node.title, 'MemSequence')
        self.assertIsNotNone(node.description)
예제 #2
0
    def test_memory_continue(self):
        node1 = get_node(b3.SUCCESS)
        node2 = get_node(b3.SUCCESS)
        node3 = get_node(b3.SUCCESS)
        node4 = get_node(b3.FAILURE)
        node5 = get_node(b3.SUCCESS)

        memsequence = b3.MemSequence(
            children=[node1, node2, node3, node4, node5])
        memsequence.id = 'node1'
        tick = TickStub()
        tick.blackboard.get.return_value = 2
        status = memsequence._execute(tick)

        expected = [
            mock.call('is_open', False, 'tree1', 'node1'),
        ]
        result = tick.blackboard.set.mock_calls
        self.assertListEqual(result, expected)

        self.assertEqual(node1._execute.call_count, 0)
        self.assertEqual(node2._execute.call_count, 0)
        self.assertEqual(node3._execute.call_count, 1)
        self.assertEqual(node4._execute.call_count, 1)
        self.assertEqual(node5._execute.call_count, 0)
예제 #3
0
    def test_success(self):
        node1 = get_node(b3.SUCCESS)
        node2 = get_node(b3.SUCCESS)
        node3 = get_node(b3.SUCCESS)

        memsequence = b3.MemSequence(children=[node1, node2, node3])
        tick = TickStub()
        tick.blackboard.get.return_value = 0
        status = memsequence.tick(tick)

        self.assertEqual(status, b3.SUCCESS)
        self.assertEqual(node1._execute.call_count, 1)
        self.assertEqual(node2._execute.call_count, 1)
        self.assertEqual(node3._execute.call_count, 1)
예제 #4
0
    def test_memory(self):
        node1 = get_node(b3.SUCCESS)
        node2 = get_node(b3.SUCCESS)
        node3 = get_node(b3.RUNNING)
        node4 = get_node(b3.FAILURE)
        node5 = get_node(b3.SUCCESS)

        memsequence = b3.MemSequence(
            children=[node1, node2, node3, node4, node5])
        memsequence.id = 'node1'
        tick = TickStub()
        tick.blackboard.get.return_value = 0
        status = memsequence._execute(tick)

        expected = [
            mock.call('is_open', True, 'tree1', 'node1'),
            mock.call('running_child', 0, 'tree1', 'node1'),
            mock.call('running_child', 2, 'tree1', 'node1')
        ]
        result = tick.blackboard.set.mock_calls
        self.assertListEqual(result, expected)
예제 #5
0
    def test_dump(self):
        tree = b3.BehaviorTree()

        class Custom(b3.Condition):
            title = 'custom'

        tree.properties = {
            'prop': 'value',
            'comp': {
                'val1': 234,
                'val2': 'value'
            }
        }

        node5 = Custom()
        node5.id = 'node-5'
        node5.title = 'Node5'
        node5.description = 'Node 5 Description'

        node4 = b3.Wait()
        node4.id = 'node-4'
        node4.title = 'Node4'
        node4.description = 'Node 4 Description'

        node3 = b3.MemSequence([node5])
        node3.id = 'node-3'
        node3.title = 'Node3'
        node3.description = 'Node 3 Description'

        node2 = b3.Inverter(node4)
        node2.id = 'node-2'
        node2.title = 'Node2'
        node2.description = 'Node 2 Description'

        node1 = b3.Priority([node2, node3])
        node1.id = 'node-1'
        node1.title = 'Node1'
        node1.description = 'Node 1 Description'
        node1.properties = {'key': 'value'}

        tree.root = node1
        tree.title = 'Title in Tree'
        tree.description = 'Tree Description'

        data = tree.dump()

        self.assertEqual(data['title'], 'Title in Tree')
        self.assertEqual(data['description'], 'Tree Description')
        self.assertEqual(data['root'], 'node-1')
        self.assertEqual(data['properties']['prop'], 'value')
        self.assertEqual(data['properties']['comp']['val1'], 234)
        self.assertEqual(data['properties']['comp']['val2'], 'value')

        self.assertNotEqual(data['custom_nodes'], None)
        self.assertEqual(len(data['custom_nodes']), 1)
        self.assertEqual(data['custom_nodes'][0]['name'], 'Custom')
        self.assertEqual(data['custom_nodes'][0]['title'], 'Node5')
        self.assertEqual(data['custom_nodes'][0]['category'], b3.CONDITION)

        self.assertNotEqual(data['nodes']['node-1'], None)
        self.assertNotEqual(data['nodes']['node-2'], None)
        self.assertNotEqual(data['nodes']['node-3'], None)
        self.assertNotEqual(data['nodes']['node-4'], None)
        self.assertNotEqual(data['nodes']['node-5'], None)

        self.assertEqual(data['nodes']['node-1']['id'], 'node-1')
        self.assertEqual(data['nodes']['node-1']['name'], 'Priority')
        self.assertEqual(data['nodes']['node-1']['title'], 'Node1')
        self.assertEqual(data['nodes']['node-1']['description'],
                         'Node 1 Description')
        self.assertEqual(data['nodes']['node-1']['children'][0], 'node-3')
        self.assertEqual(data['nodes']['node-1']['children'][1], 'node-2')
        self.assertEqual(data['nodes']['node-1']['properties']['key'], 'value')

        self.assertEqual(data['nodes']['node-2']['name'], 'Inverter')
        self.assertEqual(data['nodes']['node-2']['title'], 'Node2')
        self.assertEqual(data['nodes']['node-2']['description'],
                         'Node 2 Description')
        self.assertNotEqual(data['nodes']['node-2']['child'], None)

        self.assertEqual(data['nodes']['node-3']['name'], 'MemSequence')
        self.assertEqual(data['nodes']['node-3']['title'], 'Node3')
        self.assertEqual(data['nodes']['node-3']['description'],
                         'Node 3 Description')
        self.assertEqual(len(data['nodes']['node-3']['children']), 1)

        self.assertEqual(data['nodes']['node-4']['name'], 'Wait')
        self.assertEqual(data['nodes']['node-4']['title'], 'Node4')
        self.assertEqual(data['nodes']['node-4']['description'],
                         'Node 4 Description')

        self.assertEqual(data['nodes']['node-5']['name'], 'Custom')
        self.assertEqual(data['nodes']['node-5']['title'], 'Node5')
        self.assertEqual(data['nodes']['node-5']['description'],
                         'Node 5 Description')