-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.spec.ts
119 lines (92 loc) · 5.79 KB
/
node.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { operations } from './../src/utils/operations';
import { expect } from 'chai';
import { generateNodeList, generateNode } from "../src/functions/node";
import { NodeInfo } from "../src/classes/Node";
import { State } from '../src/utils/state';
import HeuristicValue from '../src/classes/HeuristicValue';
describe('Node Smoke Tests', () => { // the tests container
it('should exist generateNodeList function', () => {
expect(generateNodeList).to.exist;
});
it('should exist generateNode function', () => {
expect(generateNode).to.exist;
});
it('should return an Array when call generateNodeList function', () => {
const state: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const heuristicValue = new HeuristicValue(0, 14, 14);
const node: NodeInfo = new NodeInfo(heuristicValue, operations.none, state);
expect(generateNodeList(node, state)).to.be.an('Array');
});
it('should return a NodeInfo object when call generateNode function', () => {
const state: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const gValue = 0;
expect(generateNode(state, operations.none,state, gValue)).to.be.instanceOf(NodeInfo);
});
});
describe('Testing returns of generateNode function', () => {
it('should return this NodeInfo obj when call generateNode function', () => {
const state: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const finalState: State = [[1,2,3], [4,5,6], [7, 8, 0]];
const heuristicValue = new HeuristicValue(0, 14, 14);
const expectedNode = new NodeInfo(heuristicValue, operations.none, state);
const gValue = 0;
expect(generateNode(state, operations.none, finalState, gValue)).to.eql(expectedNode);
});
it('should return this NodeInfo obj when call generateNode function', () => {
const state: State = [[4,5,8], [1,0,6], [7, 2, 3]];
const finalState: State = [[1,2,3], [4,5,6], [7, 8, 0]];
const heuristicValue = new HeuristicValue(1, 12, 13);
const expectedNode = new NodeInfo(heuristicValue, operations.left, state);
const gValue = 1;
expect(generateNode(state, operations.left, finalState, gValue)).to.eql(expectedNode);
});
it('should return this NodeInfo obj when call generateNode function', () => {
const state: State = [[4,5,8], [1,2,6], [7, 3, 0]];
const finalState: State = [[1,2,3], [4,5,6], [7, 8, 0]];
const heuristicValuePrevious = new HeuristicValue(0, 0, 0);
const mockedPreviousNode = new NodeInfo(heuristicValuePrevious, operations.none, state);
const heuristicValueExpected = new HeuristicValue(3, 10, 13);
const expectedNode = new NodeInfo(heuristicValueExpected, operations.up, state, mockedPreviousNode);
const gValue = 3;
expect(generateNode(state, operations.up, finalState, gValue, mockedPreviousNode)).to.eql(expectedNode);
});
});
describe('Testing returns of generateNodeList function', () => {
it('should return this NodeInfo array when call generateNodeList function', () => {
const state: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const goalState: State = [[1,2,3], [4,5,6], [7, 8, 0]];
const heuristicValueRoot = new HeuristicValue(0, 14, 14);
const rootNode = new NodeInfo(heuristicValueRoot, operations.none, state);
const stateChild1: State = [[0,5,8], [4,1,6], [7, 2, 3]];
const heuristicValue1 = new HeuristicValue(1, 14, 15);
const expectedChild1 = new NodeInfo(heuristicValue1, operations.up, stateChild1, rootNode);
const stateChild2: State = [[4,5,8], [1,0,6], [7, 2, 3]];
const heuristicValue2 = new HeuristicValue(1, 12, 13);
const expectedChild2 = new NodeInfo(heuristicValue2, operations.right, stateChild2, rootNode);
const stateChild3: State = [[4,5,8], [7,1,6], [0, 2, 3]];
const heuristicValue3 = new HeuristicValue(1, 14, 15);
const expectedChild3 = new NodeInfo(heuristicValue3, operations.down, stateChild3, rootNode);
const childrenList = [expectedChild1, expectedChild2 , expectedChild3];
expect(generateNodeList(rootNode, goalState)).to.eql(childrenList);
});
it('should return this NodeInfo array when call generateNodeList function', () => {
const state: State = [[4,5,8], [1,0,6], [7, 2, 3]];
const goalState: State = [[1,2,3], [4,5,6], [7, 8, 0]];
const heuristicValueRoot = new HeuristicValue(1, 12, 13);
const rootNode = new NodeInfo(heuristicValueRoot, operations.right, state);
const stateChild1: State = [[4,0,8], [1,5,6], [7, 2, 3]];
const heuristicValue1 = new HeuristicValue(2, 12, 14);
const expectedChild1 = new NodeInfo(heuristicValue1, operations.up, stateChild1, rootNode);
const stateChild2: State = [[4,5,8], [1,6,0], [7, 2, 3]];
const heuristicValue2 = new HeuristicValue(2, 12, 14);
const expectedChild2 = new NodeInfo(heuristicValue2, operations.right, stateChild2, rootNode);
const stateChild3: State = [[4,5,8], [1,2,6], [7, 0, 3]];
const heuristicValue3 = new HeuristicValue(2, 10, 12);
const expectedChild3 = new NodeInfo(heuristicValue3, operations.down, stateChild3, rootNode);
const stateChild4: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const heuristicValue4 = new HeuristicValue(2, 14, 16);
const expectedChild4 = new NodeInfo(heuristicValue4, operations.left, stateChild4, rootNode);
const childrenList = [expectedChild1, expectedChild2, expectedChild3, expectedChild4];
expect(generateNodeList(rootNode, goalState)).to.eql(childrenList);
});
});