Skip to content

Commit 15e6ad0

Browse files
committed
added additonal test for the graph generator
1 parent 859a57c commit 15e6ad0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

graphGenerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = class Node {
2-
constructor() {}
2+
constructor(name, value) {}
33
}

test/graph-traversal.spec.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ describe('Graph Generator', () => {
3636
expect(A.name).to.exist;
3737
expect(B.name).to.exist;
3838
expect(C.name).to.exist;
39+
expect(A.name).to.be.an('String');
40+
expect(B.name).to.be.an('String');
41+
expect(C.name).to.be.an('String');
3942
expect(A.name).to.equal('A');
4043
expect(B.name).to.equal('B');
4144
expect(C.name).to.equal('C');
@@ -54,9 +57,18 @@ describe('Graph Generator', () => {
5457
expect(A.neighbors).to.exist;
5558
expect(B.neighbors).to.exist;
5659
expect(C.neighbors).to.exist;
60+
expect(D.neighbors).to.exist;
61+
expect(E.neighbors).to.exist;
62+
expect(F.neighbors).to.exist;
63+
});
64+
65+
it('Node property `neighbors` should be initialized to an empty array', () => {
5766
expect(A.neighbors).to.be.an('Array');
5867
expect(B.neighbors).to.be.an('Array');
5968
expect(C.neighbors).to.be.an('Array');
69+
expect(A.neighbors).to.deep.equal([]);
70+
expect(B.neighbors).to.deep.equal([]);
71+
expect(C.neighbors).to.deep.equal([]);
6072
});
6173

6274
it('Node should have a method `addNeighbors`', () => {
@@ -65,10 +77,40 @@ describe('Graph Generator', () => {
6577
expect(C.addNeighbors()).to.exist;
6678
});
6779

68-
it('Node should have a method `getNeighbors`', () => {
80+
it('Node method `addNeighbors` should return an array', () => {
81+
expect(A.addNeighbors([])).to.be.an('Array');
82+
expect(B.addNeighbors([])).to.be.an('Array');
83+
expect(C.addNeighbors([])).to.be.an('Array');
84+
});
85+
86+
it('Node method `addNeighbors` should return an array of Nodes', () => {
87+
A.addNeighbors([B,C])
88+
expect(A.neighbors[0].name).to.equal('B');
89+
expect(A.neighbors[0].value).to.equal('Jon');
90+
expect(A.neighbors[1].name).to.equal('C');
91+
expect(A.neighbors[1].value).to.equal('Ray');
92+
93+
A.addNeighbors([D,E])
94+
expect(A.neighbors[0].name).to.equal('B');
95+
expect(A.neighbors[0].value).to.equal('Jon');
96+
expect(A.neighbors[1].name).to.equal('C');
97+
expect(A.neighbors[1].value).to.equal('Ray');
98+
expect(A.neighbors[2].name).to.equal('D');
99+
expect(A.neighbors[2].value).to.equal('JSON');
100+
expect(A.neighbors[3].name).to.equal('E');
101+
expect(A.neighbors[3].value).to.equal('Marifel');
102+
});
103+
104+
it('Node should have a method `getNeighbors`', () => {
69105
expect(A.getNeighbors()).to.exist;
70106
expect(B.getNeighbors()).to.exist;
71107
expect(C.getNeighbors()).to.exist;
108+
expect(A.getNeighbors()).to.be.an('Array');
109+
expect(B.getNeighbors()).to.be.an('Array');
110+
expect(C.getNeighbors()).to.be.an('Array');
111+
expect(A.getNeighbors()).to.deep.equal([]);
112+
expect(B.getNeighbors()).to.deep.equal([]);
113+
expect(B.getNeighbors()).to.deep.equal([]);
72114
});
73115

74116
it('Node `neighbors` should refernce other neighbors', () => {

0 commit comments

Comments
 (0)