<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link href="https://unpkg.com/mocha@5.2.0/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="https://unpkg.com/chai/chai.js"></script>
<script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>
<div></div>
</body>
</html>
class Node{
constructor(data){
this.data = data;
this.next = null;
}
}
class Stack{
constructor(){
this.first = null;
this.last = null
this.size = 0
}
push(data){
let node = new Node(data)
if(!this.first){
this.first = node
this.last = node
}else{
node.next = this.first
this.first = node
}
this.size++
}
pop(){
if(!this.first) return null;
let node = this.first
if(node.next){
node = node.next
this.first = node
}else{
this.first = null
this.last = null
}
this.size--
}
}
mocha.setup('bdd');
var assert = chai.assert;
describe('Stacks',()=>{
it("should add the new node",()=>{
const stack = new Stack();
stack.push(10);
stack.push(9);
stack.push(8);
stack.push(7);
stack.push(6);
stack.pop();
stack.pop();
assert.equal(3,stack.size)
assert.equal(8,stack.first.data)
})
it("should remove the node ",()=>{
const stack = new Stack();
stack.push(10);
stack.push(9);
stack.push(8);
stack.push(7);
stack.push(6);
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
assert.equal(0,stack.size)
})
})
mocha.run()
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.