UNPKG

4.14 kBJavaScriptView Raw
1import { interpreter } from '../src';
2
3const DECISION_TREE_1_V1 = require('./data/interpreter-test-suite/decide/trees/v1/enum.json');
4const DECISION_TREE_2_V1 = require('./data/interpreter-test-suite/decide/trees/v1/continuous.json');
5const DECISION_TREE_3_V1 = require('./data/interpreter-test-suite/decide/trees/v1/oneColor.json');
6
7const DECISION_TREE_1_V2 = require('./data/interpreter-test-suite/decide/trees/v2/enum.json');
8const DECISION_TREE_2_V2 = require('./data/interpreter-test-suite/decide/trees/v2/continuous.json');
9const DECISION_TREE_3_V2 = require('./data/interpreter-test-suite/decide/trees/v2/oneColor.json');
10const DECISION_TREE_4_V2 = require('./data/interpreter-test-suite/decide/trees/v2/optional_branch_enum.json');
11const DECISION_TREE_5_V2 = require('./data/interpreter-test-suite/decide/trees/v2/boolean_operator.json');
12
13const INVALID_DECISION_TREE_1 = require('./data/interpreter-test-suite/decide/trees/v1/emptyArray.json');
14
15describe('interpreter.getDecisionRulesProperties(<tree>)', function() {
16 it('can list the properties used in a tree\'s decision rules (enum output)', function() {
17 const expected_output = [
18 {
19 'is_generated': true,
20 'property': 'timeOfDay',
21 'type': 'time_of_day'
22 }
23 ];
24 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_1_V1)).to.be.deep.equal(expected_output);
25 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_1_V2)).to.be.deep.equal(expected_output);
26 });
27
28 it('can list the properties used in a tree\'s decision rules (continuous output)', function() {
29 const expected_output = [
30 {
31 'is_generated': true,
32 'property': 'time',
33 'type': 'time_of_day'
34 },
35 {
36 'is_generated': true,
37 'property': 'day',
38 'type': 'day_of_week'
39 },
40 {
41 'property': 'tz',
42 'type': 'timezone'
43 }
44 ];
45 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_2_V1)).to.be.deep.equal(expected_output);
46 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_2_V2)).to.be.deep.equal(expected_output);
47 });
48
49 it('can list the properties used in a tree\'s decision rules (optional property)', function() {
50 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_4_V2)).to.be.deep.equal([
51 {
52 'property': 'enum4',
53 'type': 'enum'
54 },
55 {
56 'property': 'continuous3',
57 'type': 'continuous'
58 },
59 {
60 'property': 'continuous5',
61 'type': 'continuous'
62 },
63 {
64 'property': 'continuous4',
65 'type': 'continuous'
66 },
67 {
68 'property': 'enum1',
69 'type': 'enum'
70 },
71 {
72 'property': 'enum5',
73 'type': 'enum'
74 },
75 {
76 'is_optional': true,
77 'property': 'enum2',
78 'type': 'enum'
79 },
80 {
81 'property': 'enum3',
82 'type': 'enum'
83 },
84 {
85 'property': 'enum6',
86 'type': 'enum'
87 },
88 {
89 'property': 'continuous2',
90 'type': 'continuous'
91 },
92 {
93 'property': 'continuous6',
94 'type': 'continuous'
95 },
96 {
97 'property': 'enum7',
98 'type': 'enum'
99 },
100 {
101 'property': 'continuous1',
102 'type': 'continuous'
103 }
104 ]);
105 });
106
107 it('can list the properties used in a tree\'s decision rules (boolean operator)', function() {
108 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_5_V2)).to.be.deep.equal([
109 {
110 'property': 'presence',
111 'type': 'boolean'
112 },
113 {
114 'property': 'timeOfDay',
115 'type': 'time_of_day',
116 'is_generated': true
117 }
118 ]);
119 });
120
121 it('can list the properties used in a tree\'s decision rules (single leaf)', function() {
122 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_3_V1)).to.be.deep.equal([]);
123 expect(interpreter.getDecisionRulesProperties(DECISION_TREE_3_V2)).to.be.deep.equal([]);
124 });
125
126 it('works properly on invalid trees', function() {
127 expect(() => interpreter.getDecisionRulesProperties(INVALID_DECISION_TREE_1)).to.throw;
128 });
129});