UNPKG

1.76 kBJavaScriptView Raw
1import { interpreter, Time } from '../src';
2
3const DECISION_TREE_ENUM = require('./data/interpreter-test-suite/decide/trees/v1/enum.json');
4const EXPECTATION_DECISION_TREE_ENUM = require('./data/interpreter-test-suite/decide/expectations/v1/enum.json');
5const DECISION_TREE_UNKNOWN_OUTPUT = require('./data/interpreter-test-suite/decide/trees/v1/unknownOutput.json');
6const EXPECTATION_DECISION_TREE_UNKNOWN_OUTPUT = require('./data/interpreter-test-suite/decide/expectations/v1/unknownOutput.json');
7
8describe('interpreter.decideFromContextsArray', () => {
9 it('works on an array of contexts', function() {
10 const interestingExpectations = _.filter(EXPECTATION_DECISION_TREE_ENUM, (expectation) => expectation.error === undefined);
11 const contexts = _.map(interestingExpectations, (expectation) => ([
12 expectation.context,
13 expectation.time ? new Time(expectation.time.t, expectation.time.tz) : {}
14 ]));
15 const decisions = _.map(interestingExpectations, (expectation) => expectation.output);
16 expect(interpreter.decideFromContextsArray(DECISION_TREE_ENUM, contexts)).to.be.deep.equal(decisions);
17 });
18
19 it('gather \'CraftAiNullDecisionError\' instead of throwing them', function() {
20 const contexts = _.map(EXPECTATION_DECISION_TREE_UNKNOWN_OUTPUT, (expectation) => ([
21 expectation.context,
22 expectation.time ? new Time(expectation.time.t, expectation.time.tz) : {}
23 ]));
24 const decisions = _.map(EXPECTATION_DECISION_TREE_UNKNOWN_OUTPUT, (expectation) => (expectation.output || {
25 _version: '1.1.0',
26 context: expectation.context,
27 error: expectation.error
28 }));
29 expect(interpreter.decideFromContextsArray(DECISION_TREE_UNKNOWN_OUTPUT, contexts)).to.be.deep.equal(decisions);
30 });
31});