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)
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))
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)
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)