Commit 6594f290 6594f290a2d7b855801d97ad97824c747c11e6b3 by Vincent Peybernes

#8 Improve result test of election - add display matrix job

1 parent 9e3be20b
Pipeline #17 for 6594f290 failed in 37 seconds
...@@ -14,6 +14,12 @@ node_test: ...@@ -14,6 +14,12 @@ node_test:
14 - npm install 14 - npm install
15 - npm test 15 - npm test
16 16
17 display_details:
18 stage: test
19 when: manual
20 script:
21 - node tests/node/displayResults.js
22
17 build: 23 build:
18 stage: build 24 stage: build
19 script: 25 script:
......
1 /**
2 * Created by Techniv on 07/12/2016.
3 */
4 var RelativePlacement = require('../../lib/relative-placement');
5 var data = require('./results_data.json');
6 var util = require('util');
7
8 console.log('############################');
9 console.log('# Details of result matrix #');
10 console.log('############################');
11 console.log('');
12 console.log('The cadidate are display in order of placement');
13 console.log('');
14 console.log('Column:');
15 console.log('Expected | (*error)Candidate\t[Votes]\t[Sum matrix (Sum score)]');
16 console.log('');
17 console.log('');
18 console.log('');
19 console.log('');
20
21 data.forEach((testCase, num) => {
22 console.log("#"+ num + ": "+testCase.comment);
23
24 var election = new RelativePlacement();
25 var votes = compileVotes(testCase);
26
27 election.addCandidates(votes[0]);
28 election.addVotes(votes);
29
30 var result = election.getResult();
31 var expected = testCase.result;
32 var candidates = election.candidateList;
33
34 result.forEach((candidateName, place) => {
35 var log = [];
36 var candidate = candidates[candidateName];
37
38 log.push(expected[place]);
39 log.push('\t|\t');
40 (candidateName != expected[place]) ? log.push('*') : log.push(' ');
41 log.push(candidateName);
42 log.push('\t');
43 log.push(util.format(candidate.votes));
44 log.push('\t[');
45 for (var i = 0; i < candidate.placements.length; i++){
46 log.push(i==0 ? ' ' : ', ');
47 log.push(candidate.placements[i]);
48 log.push('(');
49 log.push(candidate.cumulativePlacement[i]);
50 log.push(') ');
51 }
52 log.push(' ]');
53
54 console.log(log.join(''));
55 });
56
57 console.log('-------------------------------------------------------------------');
58 console.log('');
59 console.log('');
60 });
61
62 /**
63 * @param {TestData} testData
64 * @return {String[][]}
65 */
66 function compileVotes(testData){
67 var votes = testData.votes;
68 var compileVotes = [];
69 var candidates = Object.keys(votes);
70 var voteNumber = votes[candidates[0]].length;
71
72 for(let i = 0; i < voteNumber; i++){
73 let compileVote = [];
74 for(let name in votes){
75 compileVote[votes[name][i]-1] = name;
76 }
77 compileVotes[i] = compileVote;
78 }
79
80 return compileVotes;
81 }
...\ No newline at end of file ...\ No newline at end of file