Skip to content

Commit 7d0a078

Browse files
committed
basic tests
1 parent 8d805c1 commit 7d0a078

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

test/sample.js

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,77 @@
11
var assert = require('assert');
22
let ptime = require('quick-ptime');
3+
const { stacks } = require('../index');
34

4-
describe('Array', function() {
5-
describe('#indexOf()', function() {
6-
it('should return -1 when the value is not present', async function() {
7-
assert.equal([1,2,3].indexOf(4), -1);
8-
await new Promise((resolve, reject) => {
9-
setTimeout(resolve, 1000);
10-
})
11-
});
5+
describe('Stack', function() {
6+
it('should make a new stack', function() {
7+
const stack = new stacks.Stack();
8+
assert.equal(stack.height(), 0);
9+
});
10+
11+
it('should push an item on to the stack', function() {
12+
let stack = new stacks.Stack();
13+
stack.push('item');
14+
15+
assert.equal(stack.peek(), 'item');
16+
});
17+
18+
it('should pop an item off the stack', function() {
19+
let stack = new stacks.Stack();
20+
stack.push('item');
21+
let value = stack.pop();
22+
assert.equal(value, 'item');
23+
});
24+
25+
it('should push three items on and pop them off in order', function() {
26+
let stack = new stacks.Stack();
27+
stack.push('item1');
28+
stack.push('item2');
29+
stack.push('item3');
30+
31+
let value = stack.pop();
32+
assert.equal(value, 'item3');
33+
34+
value = stack.pop();
35+
assert.equal(value, 'item2');
36+
37+
value = stack.pop();
38+
assert.equal(value, 'item1');
39+
});
40+
});
41+
42+
describe('Array Stack', function() {
43+
it('should make a new stack', function() {
44+
const stack = new stacks.ArrayStack();
45+
assert.equal(stack.height(), 0);
46+
});
47+
48+
it('should push an item on to the stack', function() {
49+
let stack = new stacks.ArrayStack();
50+
stack.push('item');
51+
52+
assert.equal(stack.peek(), 'item');
53+
});
54+
55+
it('should pop an item off the stack', function() {
56+
let stack = new stacks.ArrayStack();
57+
stack.push('item');
58+
let value = stack.pop();
59+
assert.equal(value, 'item');
60+
});
61+
62+
it('should push three items on and pop them off in order', function() {
63+
let stack = new stacks.ArrayStack();
64+
stack.push('item1');
65+
stack.push('item2');
66+
stack.push('item3');
67+
68+
let value = stack.pop();
69+
assert.equal(value, 'item3');
70+
71+
value = stack.pop();
72+
assert.equal(value, 'item2');
73+
74+
value = stack.pop();
75+
assert.equal(value, 'item1');
1276
});
1377
});

0 commit comments

Comments
 (0)