Commit 287e472b 287e472bf1691c6c2b8c2da3b56cd94ebd21c864 by Vincent Peybernes

#2 Write Algo test

1 parent 1201f347
Pipeline #4 for 287e472b failed in 15 seconds
1 /**
2 * Created by Techniv on 02/12/2016.
3 */
4 var assert = require('assert');
5 var RelativePlacement = require('../../relative-placement');
6 /** @var {TestData[]} */
7 var testDataList = require('./results_data.json');
8 describe('RelativePlacement algo', () => {
9
10 var election;
11
12 beforeEach(()=>{
13 election = new RelativePlacement();
14 });
15
16 describe('Process result data',() => {
17
18 testDataList.forEach(
19 /**
20 * @param {TestData} testData
21 * @param {Number} id
22 */
23 (testData,id) => {
24 it('#'+id+': '+(testData.comment||''), ()=>{
25 election.addCandidates(testData.result.concat().sort(()=>Math.random()-Math.random()));
26 var votes = compileVotes(testData);
27
28 votes.forEach((vote) => {
29 election.addVote(vote);
30 });
31
32 assert.deepEqual(election.getResult(), testData.result);
33 });
34 }
35 );
36 });
37
38 });
39
40 /**
41 * @name TestData
42 * @typedef Object
43 * @property {String} comment
44 * @property {Array[]}votes
45 * @property {String[]} result
46 */
47
48 /**
49 * @param {TestData} testData
50 * @return {String[][]}
51 */
52 function compileVotes(testData){
53 var votes = testData.votes;
54 var compileVotes = [];
55 var candidates = Object.keys(votes);
56 var voteNumber = votes[candidates[0]].length;
57
58 for(let i = 0; i < voteNumber; i++){
59 let compileVote = [];
60 for(let name in votes){
61 compileVote[votes[name][i]-1] = name;
62 }
63 compileVotes[i] = compileVote;
64 }
65
66 return compileVotes;
67 }
...\ No newline at end of file ...\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
9 "result": ["A","B","C"] 9 "result": ["A","B","C"]
10 }, 10 },
11 { 11 {
12 "comment": "Novice Strictly final",
12 "votes":{ 13 "votes":{
13 "320": [1,1,1,1,1], 14 "320": [1,1,1,1,1],
14 "284": [2,4,2,4,3], 15 "284": [2,4,2,4,3],
......