-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.spec.ts
135 lines (106 loc) · 5.99 KB
/
operations.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { expect } from 'chai';
import { applyOperation, moveUpOperation, moveRightOperation, moveDownOperation, moveLeftOperation, getPositionOfBlankItem } from "../src/functions/operations";
import { State, StateItem } from "../src/utils/state";
import { operations } from '../src/utils/operations';
import StateItemPosition from '../src/classes/StateItemPosition';
describe('Operations Smoke Tests', () => {
it('should exist applyOperation function', () => {
expect(applyOperation).to.exist;
});
it('should exist moveUpOperation function', () => {
expect(moveUpOperation).to.exist;
});
it('should exist moveRightOperation function', () => {
expect(moveRightOperation).to.exist;
});
it('should exist moveDownOperation function', () => {
expect(moveDownOperation).to.exist;
});
it('should exist moveLeftOperation function', () => {
expect(moveLeftOperation).to.exist;
});
it('should exist getPositionOfBlankItem function', () => {
expect(getPositionOfBlankItem).to.exist;
});
it('should return an Array when call applyOperation function', () => {
const state: State = [[4,5,8], [0,1,6], [7, 2, 3]];
expect(applyOperation(state, operations.up)).to.be.an('array');
});
});
describe('Testing returns of getPositionOfBlankItem function', () => {
it('should return [1,0] when call getPositionOfBlankItem function', () => {
const state: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const expectedPosition = new StateItemPosition(1,0);
expect(getPositionOfBlankItem(state)).to.eql(expectedPosition);
});
it('should return [2,1] when call getPositionOfBlankItem function', () => {
const state: State = [[4,5,8], [3,1,6], [7, 0, 2]];
const expectedPosition = new StateItemPosition(2,1);
expect(getPositionOfBlankItem(state)).to.eql(expectedPosition);
});
it('should return [0,0] when call getPositionOfBlankItem function', () => {
const state: State = [[0,5,8], [3,1,6], [7, 2, 4]];
const expectedPosition = new StateItemPosition(0,0);
expect(getPositionOfBlankItem(state)).to.eql(expectedPosition);
});
});
describe('Testing returns of applyOperation function', () => {
it('should return correct state when call applyOperation function when using movUp operation', () => {
const actualState: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const goalState: State = [[0,5,8], [4,1,6], [7, 2, 3]];
expect(applyOperation(actualState, operations.up)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movUp operation', () => {
const actualState: State = [[1,2,3], [4,5,6], [7, 8, 0]];
const goalState: State = [[1,2,3], [4,5,0], [7, 8, 6]];
expect(applyOperation(actualState, operations.up)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movRight operation', () => {
const actualState: State = [[4,5,8], [0,1,6], [7, 2, 3]];
const goalState: State = [[4,5,8], [1,0,6], [7, 2, 3]];
expect(applyOperation(actualState, operations.right)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movRight operation', () => {
const actualState: State = [[0,5,8], [4,1,6], [7, 2, 3]];
const goalState: State = [[5,0,8], [4,1,6], [7, 2, 3]];
expect(applyOperation(actualState, operations.right)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movDown operation', () => {
const actualState: State = [[0,5,8], [4,1,6], [7, 2, 3]];
const goalState: State = [[4,5,8], [0,1,6], [7, 2, 3]];
expect(applyOperation(actualState, operations.down)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movDown operation', () => {
const actualState: State = [[1,2,3], [4,0,6], [7, 5, 8]];
const goalState: State = [[1,2,3], [4,5,6], [7, 0, 8]];
expect(applyOperation(actualState, operations.down)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movLeft operation', () => {
const actualState: State = [[1,2,3], [4,0,6], [7, 5, 8]];
const goalState: State = [[1,2,3], [0,4,6], [7, 5, 8]];
expect(applyOperation(actualState, operations.left)).to.eql(goalState);
});
it('should return correct state when call applyOperation function when using movLeft operation', () => {
const actualState: State = [[5,8,0], [4,1,6], [7, 2, 3]];
const goalState: State = [[5,0,8], [4,1,6], [7, 2, 3]];
expect(applyOperation(actualState, operations.left)).to.eql(goalState);
});
});
describe('Testing returns of applyOperation function when operation cannot be applied', () => {
it('should return null when call applyOperation function using movUp operation', () => {
const actualState: State = [[0,5,8], [4,1,6], [7, 2, 3]];
expect(applyOperation(actualState, operations.up)).to.eql(null);
});
it('should return null when call applyOperation function using movRight operation', () => {
const actualState: State = [[5,8,6], [4,1,0], [7, 2, 3]];
expect(applyOperation(actualState, operations.right)).to.eql(null);
});
it('should return null when call applyOperation function using movDown operation', () => {
const actualState: State = [[5,8,6], [4,1,3], [7, 0, 2]];
expect(applyOperation(actualState, operations.down)).to.eql(null);
});
it('should return null when call applyOperation function using movLeft operation', () => {
const actualState: State = [[5,8,6], [0,4,1], [7, 3, 2]];
expect(applyOperation(actualState, operations.left)).to.eql(null);
});
});