Exemplo n.º 1
0
    def test_iterator_list(self):
        geolog_core.reference_manager.ReferenceManager().reset()
        DummyIterator.control = 0
        iterator_atom = pyswip.Atom("iterator")
        geolog_core.reference_manager.ReferenceManager(
        )._object_dict[iterator_atom] = iter([[1, 2], [2, 3], [3, 4]])

        variable = pyswip.Variable()
        DummyIterator.execute(iterator_atom, variable, 0)
        self.assertEqual([1, 2], variable.value)
Exemplo n.º 2
0
    def test_execute_deterministic_with_atom(self):
        geolog_core.reference_manager.ReferenceManager().reset()
        atom = pyswip.Atom("test_me")
        geolog_core.reference_manager.ReferenceManager(
        )._object_dict[atom] = DummyObject(2)

        AtomDeterministicDummyProcess.execute(atom)

        self.assertEqual(DummyObject(2),
                         AtomDeterministicDummyProcess.argument)
        self.assertTrue(isinstance(atom, pyswip.Atom))
Exemplo n.º 3
0
    def test_iterator_prune(self):
        geolog_core.reference_manager.ReferenceManager().reset()
        DummyIterator.control = 0
        iterator_atom = pyswip.Atom("iterator")
        geolog_core.reference_manager.ReferenceManager(
        )._object_dict[iterator_atom] = iter([1, 2, 3])

        variable = pyswip.Variable()
        DummyIterator.execute(iterator_atom, variable, 0)

        DummyIterator.control = 2

        variable = pyswip.Variable()
        return_value = DummyIterator.execute(iterator_atom, variable, 0)
        self.assertFalse(return_value)
Exemplo n.º 4
0
    def test_iterator_bind_list_of_objects_to_variable(self):
        geolog_core.reference_manager.ReferenceManager().reset()
        DummyIterator.control = 0
        iterator_atom = pyswip.Atom("iterator")
        geolog_core.reference_manager.ReferenceManager(
        )._object_dict[iterator_atom] = iter([[DummyObject(1), 2]])

        variable = pyswip.Variable()
        DummyIterator.execute(iterator_atom, variable, 0)

        atom = geolog_core.reference_manager.ReferenceManager(
        )._object_dict.keys()[1]

        self.assertEqual(
            DummyObject(1),
            geolog_core.reference_manager.ReferenceManager()._object_dict[atom]
        )
        self.assertEqual([atom, 2], variable.value)
 def create_atom(self):
     atom_name = geolog_core.util.get_new_uuid()
     return pyswip.Atom(atom_name)