Esempio n. 1
0
    def testCheckBB(self):
        """Can we check a value on a blackboard?
        """
        value = "foo"
        checker = lambda x: x == value

        bb = blackboard.Blackboard('test', value=value)
        tree = blackboard.checkBB(key='value',
                                  check=checker)
        
        # Note that we can pass in the blackboard at run-time.
        v = owyl.visit(tree, blackboard=bb)

        # Check should succeed.
        self.assertEqual(v.next(), True)

        v = owyl.visit(tree, blackboard=bb)
        self.assertEqual(v.next(), True)

        bb['value'] = 'bar'

        # Check should now fail.
        v = owyl.visit(tree, blackboard=bb)
        self.assertEqual(v.next(), False)

        v = owyl.visit(tree, blackboard=bb)
        self.assertEqual(v.next(), False)
Esempio n. 2
0
    def testCheckBB(self):
        """Can we check a value on a blackboard?
        """
        value = "foo"
        checker = lambda x: x == value

        bb = blackboard.Blackboard('test', value=value)
        tree = blackboard.checkBB(key='value', check=checker)

        # Note that we can pass in the blackboard at run-time.
        v = owyl.visit(tree, blackboard=bb)

        # Check should succeed.
        self.assertEqual(v.next(), True)

        v = owyl.visit(tree, blackboard=bb)
        self.assertEqual(v.next(), True)

        bb['value'] = 'bar'

        # Check should now fail.
        v = owyl.visit(tree, blackboard=bb)
        self.assertEqual(v.next(), False)

        v = owyl.visit(tree, blackboard=bb)
        self.assertEqual(v.next(), False)
Esempio n. 3
0
    def testSetBB(self):
        """Can we set a value on a blackboard?
        """
        value = 'foo'
        checker = lambda x: x == value

        bb = blackboard.Blackboard('test', value='bar')
        tree = owyl.sequence(blackboard.setBB(key="value", value=value),
                             blackboard.checkBB(key='value', check=checker))

        # Note that we can pass in the blackboard at run-time.
        v = owyl.visit(tree, blackboard=bb)

        # Sequence will succeed if the check succeeds.
        result = [x for x in v][-1]
        self.assertEqual(result, True)

        v = owyl.visit(tree, blackboard=bb)
        result = [x for x in v][-1]
        self.assertEqual(result, True)
Esempio n. 4
0
 def testStructureBig(self):
     tree = owyl.parallel(owyl.sequence(owyl.repeatAlways(blackboard.setBB()), owyl.log()),
                          owyl.selector(owyl.repeatUntilSucceed(blackboard.checkBB())),
                          owyl.repeatUntilFail(owyl.fail()))
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['name', 'children'])
     self.assertEquals(structure,
                       {'name': 'parallel',
                        'children': [{'name': 'sequence',
                                      'children': [{'name': 'repeatAlways',
                                                    'children': [{'name': 'setBB',
                                                                  'children': []}]},
                                                   {'name': 'log',
                                                    'children': []}]},
                                     {'name': 'selector',
                                      'children': [{'name': 'repeatUntilSucceed',
                                                    'children': [{'name': 'checkBB',
                                                                  'children': []}]}]},
                                     {'name': 'repeatUntilFail',
                                      'children': [{'name': 'fail',
                                                    'children': []}]}]})
Esempio n. 5
0
    def testSetBB(self):
        """Can we set a value on a blackboard?
        """
        value = 'foo'
        checker = lambda x: x == value

        bb = blackboard.Blackboard('test', value='bar')
        tree = owyl.sequence(blackboard.setBB(key="value",
                                              value=value),
                             blackboard.checkBB(key='value',
                                                check=checker)
                             )
        
        # Note that we can pass in the blackboard at run-time.
        v = owyl.visit(tree, blackboard=bb)

        # Sequence will succeed if the check succeeds.
        result = [x for x in v][-1]
        self.assertEqual(result, True)

        v = owyl.visit(tree, blackboard=bb)
        result = [x for x in v][-1]
        self.assertEqual(result, True)
Esempio n. 6
0
 def testDescriptionCheckBB(self):
     tree = blackboard.checkBB(key='somekey', check=lambda x: x == 3)
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['desc'])
     self.assertEquals(structure, {'desc': 'somekey'})