% file: rdr_unit_tests.pl % author: Douglas M. Auclair % created: September 24, 2008 % synopsis: Exercises the predicates in rdr_impl.pl. To run all the tests in this % file, call run_all_tests/0. :- [rdr_impl]. run_all_tests :- test_rule(_), test_run_concl(_). test_rule([Dir1 - Ans1, Dir2 - Ans2, Dir3 - Ans3, Dir4 - Ans4] - should_be(left - foo1, right - foo1, right - foo1, left - bar)) :- Env0 = env([foo - 1, bar - 2], concl(null)), make_equiv_cond(foo - 1, Cond1), assume(foo1, Conc1), Rule1 = rule(Cond1, Conc1), make_simple_rule(quux, quux, Rule2), make_equiv_cond(bar - 1, Cond3), assume(bar1, Conc3), Rule3 = rule(Cond3, Conc3), make_simple_rule(bar, bar, Rule4), test_rule(Rule1, Dir1, Env0, Env1), test_rule(Rule2, Dir2, Env1, Env2), test_rule(Rule3, Dir3, Env2, Env3), test_rule(Rule4, Dir4, Env3, Env4), run_concl(Env1, Ans1), run_concl(Env2, Ans2), run_concl(Env3, Ans3), run_concl(Env4, Ans4), print('*** test_rule/1: build, tested and run the following rules --'), nl, print(Rule1), nl, print(Rule2), nl, print(Rule3), nl, print(Rule4), nl. test_rule_env(rule_env(DesAnimaux, Env)) :- init_rule_env(rule_env(Tree, Env)), add_animals(Tree, DesAnimaux), print('*** test_rule_env/1: built the following rule environment --'), nl, print(rule_env(DesAnimaux, Env)), nl. add_animals --> add_rule(left, FourLegs), advance(left), add_rule(left, Dog), add_rule(right, Fish), advance(left), add_rule(right, Cat), withdraw, advance(right), add_rule(right, Spider), settle, { make_simple_rule('four legs', pony, FourLegs), make_simple_rule(barks, dog, Dog), make_simple_rule(meows, cat, Cat), make_simple_rule(swims, fish, Fish), make_simple_rule('spins web', spider, Spider) }. cat_me --> update_env('four legs' - _), update_env(meows - _). spider_me --> update_env('spins web' - _). test_run_rule([RuleEnv1, RuleEnv2]) :- test_rule_env(rule_env(Tree, Env0)), spider_me(Env0, Env1), run_rule(rule_env(Tree, Env1), RuleEnv1), cat_me(Env0, Env2), run_rule(rule_env(Tree, Env2), RuleEnv2), print('*** test_run_rule/1: ran the following rule environments --'), nl, print(RuleEnv1), nl, print(RuleEnv2), nl. test_run_concl([Concl1, Concl2] - should_be(spider, cat)) :- test_run_rule([rule_env(_, Env1), rule_env(_, Env2)]), run_concl(Env1, Concl1), run_concl(Env2, Concl2), attribs(Env1, Keys1), attribs(Env2, Keys2), print('*** test_run_concl/1: reached the following conclusions --'), nl, guess_animal(Keys1, Concl1), guess_animal(Keys2, Concl2). guess_animal(Keys, Animal) :- print('Is the animal that has these attributes '), print(Keys), print(' a '), print(Animal), print('?'), nl.