def test_Depth_update_agenda_asertion_order_affects_agenda_order_1(): from pyknow.strategies import Depth from pyknow.activation import Activation from pyknow.rule import Rule from pyknow.agenda import Agenda act1 = Activation(rule=Rule(), facts=(1, )) act2 = Activation(rule=Rule(), facts=(2, )) first = {act1, act2} act3 = Activation(rule=Rule(), facts=(3, )) act4 = Activation(rule=Rule(), facts=(4, )) second = {act3, act4} a = Agenda() st = Depth() st.update_agenda(a, first) st.update_agenda(a, second) left, right = set(list(a.activations)[:2]), set(list(a.activations)[2:]) assert left == second assert right == first
def test_Depth_update_agenda_different_salience(): from random import shuffle from pyknow.strategies import Depth from pyknow.activation import Activation from pyknow.rule import Rule from pyknow.agenda import Agenda act1 = Activation(rule=Rule(salience=1), facts=(1, )) act2 = Activation(rule=Rule(salience=2), facts=(2, )) act3 = Activation(rule=Rule(salience=3), facts=(3, )) act4 = Activation(rule=Rule(salience=4), facts=(4, )) acts = [act1, act2, act3, act4] shuffle(acts) st = Depth() a = Agenda() for act in acts: st.update_agenda(a, [act]) order = list(a.activations) assert (order.index(act4) < order.index(act3) < order.index(act2) < order.index(act1))
def test_Depth_update_agenda_no_facts_returns_empty_agenda(): from pyknow.strategies import Depth from pyknow.agenda import Agenda st = Depth() a = Agenda() st.update_agenda(a, set()) assert not a.activations
def test_Depth_update_agenda_activations_to_agenda(): from pyknow.strategies import Depth from pyknow.activation import Activation from pyknow.rule import Rule from pyknow.agenda import Agenda act1 = Activation(rule=Rule(), facts=(1, )) act2 = Activation(rule=Rule(), facts=(2, )) a = Agenda() st = Depth() st.update_agenda(a, {act1, act2}) assert act1 in a.activations assert act2 in a.activations