GlobalSpec.js
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Created by Techniv on 30/11/2016.
*/
var assert = require('assert');
var RelativePlacement = require('../../relative-placement');
describe('RelativePlacement', () => {
it('should provide RelativePlacement constructor', () => {
assert.ok(RelativePlacement instanceof Function, 'provide constructor');
assert.ok(RelativePlacement.prototype.addCandidate instanceof Function, 'provide "addCandidate" function in prototype');
assert.ok(RelativePlacement.prototype.addCandidates instanceof Function, 'provide "addCandidates" function in prototype');
assert.ok(RelativePlacement.prototype.addVote instanceof Function, 'provide "addVote" function in prototype');
assert.ok(RelativePlacement.prototype.addVotes instanceof Function, 'provide "addVotes" function in prototype');
assert.ok(RelativePlacement.prototype.getResult instanceof Function, 'provide "getResult" function in prototype');
});
it('should correctly instantiate RelativePlacement election', () => {
var rp = new RelativePlacement();
assert.deepEqual({}, rp.candidateList);
});
describe('Add candidates', () => {
/** @var RelativePlacement */
var election;
beforeEach(()=> election = new RelativePlacement());
it('should add a candidate', () => {
assert.equal(0, election.numberOfCandidates);
election.addCandidate('foo');
assert.equal(1, election.numberOfCandidates);
assert.deepEqual({
name: 'foo',
votes:[]
}, election.candidateList['foo']);
assert.deepEqual([], election.candidateList['foo'].placement);
});
it('should add some candidates', () => {
assert.equal(0, election.numberOfCandidates);
election.addCandidates(['foo', 'bar']);
assert.equal(2, election.numberOfCandidates);
assert.deepEqual({
name: 'foo',
votes:[]
}, election.candidateList['foo']);
assert.deepEqual({
name: 'bar',
votes:[]
}, election.candidateList['bar']);
});
it('should not add a same candidate multiple time', () => {
});
});
});