Commit 1201f347 1201f34789c8d0261772d0f91d1f43ddba1f170c by Vincent Peybernes

#1 Write structural test

1 parent 74c24f41
Pipeline #3 for 1201f347 failed in 13 seconds
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 var assert = require('assert'); 4 var assert = require('assert');
5 var RelativePlacement = require('../../relative-placement'); 5 var RelativePlacement = require('../../relative-placement');
6 6
7 describe('RelativePlacement', () => { 7 describe('RelativePlacement global', () => {
8 it('should provide RelativePlacement constructor', () => { 8 it('should provide RelativePlacement constructor', () => {
9 assert.ok(RelativePlacement instanceof Function, 'provide constructor'); 9 assert.ok(RelativePlacement instanceof Function, 'provide constructor');
10 assert.ok(RelativePlacement.prototype.addCandidate instanceof Function, 'provide "addCandidate" function in prototype'); 10 assert.ok(RelativePlacement.prototype.addCandidate instanceof Function, 'provide "addCandidate" function in prototype');
...@@ -71,15 +71,16 @@ describe('RelativePlacement', () => { ...@@ -71,15 +71,16 @@ describe('RelativePlacement', () => {
71 71
72 describe('Add votes', () => { 72 describe('Add votes', () => {
73 var election; 73 var election;
74 var candidates = ['A','B','C'];
74 75
75 beforeEach(()=> { 76 beforeEach(()=> {
76 election = new RelativePlacement(); 77 election = new RelativePlacement();
77 election.addCandidates(['A','B','C']); 78 election.addCandidates(candidates);
78 }); 79 });
79 80
80 it('should add a vote to each candidates', () => { 81 it('should add a vote to each candidates', () => {
81 var vote = ['A','B','C']; 82 var vote = candidates;
82 election.addVote(['A','B','C']); 83 election.addVote(vote);
83 for(let i = 0; i < vote.length; i++){ 84 for(let i = 0; i < vote.length; i++){
84 let candidate = election.candidateList[vote[i]]; 85 let candidate = election.candidateList[vote[i]];
85 assert.equal(candidate.votes.length, 1, 'number of candidates vote'); 86 assert.equal(candidate.votes.length, 1, 'number of candidates vote');
...@@ -125,5 +126,34 @@ describe('RelativePlacement', () => { ...@@ -125,5 +126,34 @@ describe('RelativePlacement', () => {
125 assert.equal(election.votes.length, 0, 'no vote registered'); 126 assert.equal(election.votes.length, 0, 'no vote registered');
126 assert.equal(election.candidateList['A'].votes.length, 0, 'no vote registered in candidate'); 127 assert.equal(election.candidateList['A'].votes.length, 0, 'no vote registered in candidate');
127 }); 128 });
129
130 it('should lock candidate after add the first vote', () => {
131 election.addVote(candidates);
132 assert.throws(()=>election.addCandidate('D'));
133 });
134 });
135
136 describe('Get result', () => {
137 /** @var RelativePlacement */
138 var election;
139 var candidates = ['A','B','C'];
140
141 beforeEach(()=> {
142 election = new RelativePlacement();
143 election.addCandidates(candidates);
144 election.addVote(candidates);
145 });
146
147 it('should return an array', () => {
148 assert.ok(election.getResult() instanceof Array);
149 });
150
151 it('should return only all candidates', () => {
152 var result = election.getResult();
153
154 assert.equal(result.length, candidates.length);
155 assert.ok(candidates.every(name => result.indexOf(name) != -1));
156 assert.ok(result.every(name => candidates.indexOf(name) != -1));
157 });
128 }); 158 });
129 }); 159 });
...\ No newline at end of file ...\ No newline at end of file
......