Skip to content

Commit

Permalink
Fix issue #11 that was introduced with #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilp0inter committed Nov 16, 2019
1 parent 59fcaec commit a268513
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion experta/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def _update_agenda(self, agenda, added, removed):
act.key = self.get_key(act)
try:
idx = bisect.bisect_left(agenda.activations, act)
del agenda.activations[idx]
if agenda.activations[idx] == act:
del agenda.activations[idx]
except IndexError:
pass

Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,3 +986,36 @@ def first(self, f):
ke.declare(Fact(s=False))
ke.run()
assert executed == [first, second]

def test_last_activation_is_executed_2():
from experta import KnowledgeEngine, Rule, Fact, AS, DefFacts
from experta import NOT, W, MATCH

executed = None

class KE(KnowledgeEngine):
@DefFacts()
def _initial_action(self):
yield Fact(action="greet")

@Rule(Fact(action='greet'),
NOT(Fact(name=W())))
def ask_name(self):
self.declare(Fact(name="foo"))

@Rule(Fact(action='greet'),
NOT(Fact(location=W())))
def ask_location(self):
self.declare(Fact(location="bar"))

@Rule(Fact(action='greet'),
Fact(name=MATCH.name),
Fact(location=MATCH.location))
def greet(self, name, location):
nonlocal executed
executed = (name, location)

ke = KE()
ke.reset()
ke.run()
assert executed == ("foo", "bar")

0 comments on commit a268513

Please sign in to comment.