Reputation: 111
Just a little background: This is for a STRIPS like program. This test keeps returning false, even though it should be true. From what I can see in the debugger it should be true, and I can't see why it would be returning false.
Thanks for your help. Debugger image:
World:
def __init__(self):
self.logic = {}
self.actions = {}
self.goals = set()
self.curr_state = set()
Testcase:
def setUp(self):
self.world = World()
def testWorldis_true(self):
pred = "on"
params = ("A", "B")
self.assertFalse(self.world.is_true(pred, params))
self.world.logic[pred] = params
self.assertTrue(self.world.is_true(pred, params))
OUTPUT:
======================================================================
FAIL: testWorldis_true (objorstrippertests.TestWorldFunctions)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".stripperAssignment\src\objorstrippertests.py", line 54, in testWorldis_true
self.assertTrue(self.world.is_true(pred, params))
AssertionError: False is not true
Upvotes: 0
Views: 387
Reputation: 174692
The test is actually working correctly:
>>> d = {}
>>> d['on'] = ('A','B')
>>> ('A','B') in d['on']
False
This is False
because ('A','B')
is not in the tuple ('A','B')
. Each iteration over ('A','B')
will return A
and B
:
>>> for x in d['on']:
... print x
...
A
B
If you change your return to ==
then it will work correctly:
>>> d['on'] == ('A','B')
True
Upvotes: 1
Reputation: 23265
Replace:
self.world.logic[pred] = params
with:
self.world.logic[pred] = set([params])
or even better (maintaining encapsulation!):
self.world.set_true(pred, params)
logic
is a map from a predicate to a set of parameter tuples, not a single parameter tuple.
Upvotes: 1