Exemplo n.º 1
0
    def test_length(self):
        """ Tests bt_length function """

        btsr = BehaviorTreeStringRepresentation([])

        btsr.set(['s(', 'a0', 'a1', ')'])
        self.assertEqual(btsr.length(), 3)

        btsr.set(['s(', 'a0', 'f(', 'a0', 'a0', ')', 'a0', ')'])
        self.assertEqual(btsr.length(), 6)

        btsr.set(['s(', ')'])
        self.assertEqual(btsr.length(), 1)

        btsr.set(['a0'])
        self.assertEqual(btsr.length(), 1)
Exemplo n.º 2
0
    def test_random(self):

        btsr = BehaviorTreeStringRepresentation([])
        random.seed(1337)

        for length in range(1, 11):
            btsr.random(length)
            assert btsr.length() == length
            assert btsr.is_valid()
Exemplo n.º 3
0
    def test_random_genome(self):

        gp_operators = Operators()
        length = 5

        for _ in range(10):
            genome = gp_operators.random_genome(length)
            btsr = BehaviorTreeStringRepresentation(genome)

            self.assertEqual(length, btsr.length())
            self.assertTrue(btsr.is_valid())