Skip to content

Commit

Permalink
add resolutor additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
mauris committed Aug 27, 2018
1 parent 930b7cf commit 1d36d9c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/lps.js/engine/Resolutor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Resolutor', () => {
let engine = new Engine(program);
program.setState(state);

let result = Resolutor.reduceRuleAntecedent(engine, state, rule, 1);
let result = Resolutor.reduceRuleAntecedent(engine, [state], rule, 1);
expect(result).to.be.instanceof(Array);
expect(result).to.be.length(1);
expect(result[0].theta).to.be.not.undefined;
Expand All @@ -38,5 +38,27 @@ describe('Resolutor', () => {
expect(result[0].theta.T1).to.be.instanceof(Value);
expect(result[0].theta.T1.evaluate()).to.be.equal(1);
});

it('should return the correct result', () => {
let rule = new Clause(
[new Functor('buy', [new Value('alice'), new Variable('Item')])],
[new Functor('wantToBuy', [new Value('alice'), new Variable('Item')])]
);

let state = new LiteralTreeMap();
state.add(new Functor('wantToBuy', [new Value('alice'), new Value('cereal')]));
let program = new Program();
let engine = new Engine(program);
// program.setState(state);

let result = Resolutor.reduceRuleAntecedent(engine, [state], rule, 1);
expect(result).to.be.instanceof(Array);
expect(result).to.be.length(1);
expect(result[0].theta).to.be.not.undefined;
expect(Object.keys(result[0].theta)).to.be.length(1);
expect(result[0].theta.Item).to.be.not.undefined;
expect(result[0].theta.Item).to.be.instanceof(Value);
expect(result[0].theta.Item.evaluate()).to.be.equal('cereal');
});
});
});

0 comments on commit 1d36d9c

Please sign in to comment.