-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathch3-q1.spec.js
42 lines (34 loc) · 1.1 KB
/
ch3-q1.spec.js
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
import { expect } from 'chai';
import * as classes from './ch3-q1';
for (let key in classes) {
let Stack = classes[key];
describe('ch3-q1: ' + key, () => {
beforeEach(() => {
this.stack = new Stack();
});
it('can push and pop values from middle stack correctly', () => {
const stack = [];
for (let i = 1; i < 100; i += 4) {
let val = Math.trunc(Math.random() * 999999);
this.stack.push(2, val);
stack.push(val);
}
stack.reverse().forEach(v => expect(this.stack.pop(2)).to.equal(v));
});
it('can push, peek and pop values from all 3 stacks correctly', () => {
const stacks = [[], [], []];
for (let j = 9; j > 0; --j) {
for (let i = 1; i <= 3; ++i) {
let val = i * 10 + j;
this.stack.push(i, val);
stacks[i - 1].push(val);
expect(this.stack.peek(i)).to.equal(val);
}
}
for (let i = 1; i <= 3; ++i) {
stacks[i - 1].reverse().forEach(v => expect(this.stack.pop(i)).to.equal(v));
expect(this.stack.isEmpty(i)).to.be.true;
}
});
});
}