Beispiel #1
0
    def test_basics(self):
        v = VariableDesignator('Hello')
        self.assertEqual(v.resolve(), "Hello")

        w = v.writeable
        w.write("Goodbye")
        self.assertEqual(v.resolve(), "Goodbye")
Beispiel #2
0
    def test_list_write(self):
        v = VariableDesignator(['a', 'b', 'c'])
        vw = v.writeable
        self.assertEqual(vw.resolve_type, [str])
        self.assertListEqual(v.resolve(), ['a', 'b', 'c'])

        vw.write(v.resolve() + ['d'])
        self.assertListEqual(v.resolve(), ['a', 'b', 'c', 'd'])
Beispiel #3
0
    def test_write_not_possible(self):
        v = VariableDesignator('Hello')

        with self.assertRaises(DeprecationWarning):
            v.current = "Goodbye"

        self.assertEqual(v.resolve(), "Hello")  # No change
Beispiel #4
0
    def test_list_write_with_wrong_type(self):
        v = VariableDesignator(['a', 'b', 'c'])
        vw = v.writeable
        self.assertEqual(vw.resolve_type, [str])
        self.assertListEqual(v.resolve(), ['a', 'b', 'c'])

        with self.assertRaises(TypeError):
            vw.write([1, 2, 3, 4])
Beispiel #5
0
    def test_visited_and_unreachable(self):
        """In our RoboCup executives, we keep track of which items are 'processed' or visited,
        and which cannot be processed because they are unreachable.

        One way to do this, is to mark objectIDs (targets) as visited and unreachable in the reasoner,
        e.g. a global blackboard that can be manipulated an queried through Prolog.

        This gets messy with complex queries. With designators, it should be a lot simpler"""
        success = lambda goal: goal % 2  # Even targets will fail

        target_list = [i for i in range(10)] + [i for i in range(10)
                                                ]  # all are in twice!
        targets = Designator(target_list)

        unreachable_set = set()
        unreachable = VariableDesignator(unreachable_set, resolve_type=set)

        visited_set = set()
        visited = VariableDesignator(visited_set, resolve_type=set)

        for target in target_list:
            if target not in unreachable.resolve(
            ) and target not in visited.resolve():
                print("Processing target {0}".format(target))
                if success(target):
                    visited.resolve().add(
                        target)  # This is a set so no += [...]
                    print("Target {0} was successfull, its visited".format(
                        target))
                else:
                    unreachable.resolve().add(
                        target)  # This is a set so no += [...]
                    print("Target {0} failed, its unreachable".format(target))
            else:
                print(
                    "NOT processing target {0}: its unreachable or already visited"
                    .format(target))

        print("##### Done #####")
        print("These are unreachable: {0}".format(unreachable.resolve()))
        print("These are visited: {0}".format(visited.resolve()))

        self.assertEqual(len(unreachable.resolve()), 5)
        self.assertEqual(len(visited.resolve()), 5)
    def test_visited_and_unreachable(self):
        """In our RoboCup executives, we keep track of which items are 'processed' or visited,
        and which cannot be processed because they are unreachable.

        One way to do this, is to mark objectIDs (targets) as visited and unreachable in the reasoner,
        e.g. a global blackboard that can be manipulated an queried through Prolog.

        This gets messy with complex queries. With designators, it should be a lot simpler"""
        success = lambda goal: goal % 2  # Even targets will fail

        target_list = [i for i in range(10)] + [i for i in range(10)]  # all are in twice!
        targets = Designator(target_list)

        unreachable_set = set()
        unreachable = VariableDesignator(unreachable_set, resolve_type=set)

        visited_set = set()
        visited = VariableDesignator(visited_set, resolve_type=set)

        for target in target_list:
            if target not in unreachable.resolve() and target not in visited.resolve():
                print "Processing target {0}".format(target)
                if success(target):
                    visited.resolve().add(target)  # This is a set so no += [...]
                    print "Target {0} was successfull, its visited".format(target)
                else:
                    unreachable.resolve().add(target)  # This is a set so no += [...]
                    print "Target {0} failed, its unreachable".format(target)
            else:
                print "NOT processing target {0}: its unreachable or already visited".format(target)

        print "##### Done #####"
        print "These are unreachable: {0}".format(unreachable.resolve())
        print "These are visited: {0}".format(visited.resolve())

        self.assertEqual(len(unreachable.resolve()), 5)
        self.assertEqual(len(visited.resolve()), 5)
Beispiel #7
0
 def test_list(self):
     v = VariableDesignator(['a', 'b', 'c'])
     self.assertEqual(v.resolve_type, [str])
     self.assertListEqual(v.resolve(), ['a', 'b', 'c'])
Beispiel #8
0
 def test_basics(self):
     v = VariableDesignator('Hello')
     self.assertEqual(v.resolve_type, str)
     self.assertEqual(v.resolve(), "Hello")