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 @@
var assert = require('assert');
var RelativePlacement = require('../../relative-placement');
describe('RelativePlacement', () => {
describe('RelativePlacement global', () => {
it('should provide RelativePlacement constructor', () => {
assert.ok(RelativePlacement instanceof Function, 'provide constructor');
assert.ok(RelativePlacement.prototype.addCandidate instanceof Function, 'provide "addCandidate" function in prototype');
......@@ -71,15 +71,16 @@ describe('RelativePlacement', () => {
describe('Add votes', () => {
var election;
var candidates = ['A','B','C'];
beforeEach(()=> {
election = new RelativePlacement();
election.addCandidates(['A','B','C']);
election.addCandidates(candidates);
});
it('should add a vote to each candidates', () => {
var vote = ['A','B','C'];
election.addVote(['A','B','C']);
var vote = candidates;
election.addVote(vote);
for(let i = 0; i < vote.length; i++){
let candidate = election.candidateList[vote[i]];
assert.equal(candidate.votes.length, 1, 'number of candidates vote');
......@@ -125,5 +126,34 @@ describe('RelativePlacement', () => {
assert.equal(election.votes.length, 0, 'no vote registered');
assert.equal(election.candidateList['A'].votes.length, 0, 'no vote registered in candidate');
});
it('should lock candidate after add the first vote', () => {
election.addVote(candidates);
assert.throws(()=>election.addCandidate('D'));
});
});
describe('Get result', () => {
/** @var RelativePlacement */
var election;
var candidates = ['A','B','C'];
beforeEach(()=> {
election = new RelativePlacement();
election.addCandidates(candidates);
election.addVote(candidates);
});
it('should return an array', () => {
assert.ok(election.getResult() instanceof Array);
});
it('should return only all candidates', () => {
var result = election.getResult();
assert.equal(result.length, candidates.length);
assert.ok(candidates.every(name => result.indexOf(name) != -1));
assert.ok(result.every(name => candidates.indexOf(name) != -1));
});
});
});
\ No newline at end of file
......