Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
WestCoastSwing
/
RelativePlacement
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
6594f290
...
6594f290a2d7b855801d97ad97824c747c11e6b3
authored
2016-12-07 01:06:13 +0100
by
Vincent Peybernes
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
#8
Improve result test of election - add display matrix job
1 parent
9e3be20b
Pipeline
#17
for
6594f290
failed
in 37 seconds
Changes
2
Pipelines
1
Builds
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
0 deletions
.gitlab-ci.yml
tests/node/displayResults.js
.gitlab-ci.yml
View file @
6594f29
...
...
@@ -14,6 +14,12 @@ node_test:
-
npm install
-
npm test
display_details
:
stage
:
test
when
:
manual
script
:
-
node tests/node/displayResults.js
build
:
stage
:
build
script
:
...
...
tests/node/displayResults.js
0 → 100644
View file @
6594f29
/**
* Created by Techniv on 07/12/2016.
*/
var
RelativePlacement
=
require
(
'../../lib/relative-placement'
);
var
data
=
require
(
'./results_data.json'
);
var
util
=
require
(
'util'
);
console
.
log
(
'############################'
);
console
.
log
(
'# Details of result matrix #'
);
console
.
log
(
'############################'
);
console
.
log
(
''
);
console
.
log
(
'The cadidate are display in order of placement'
);
console
.
log
(
''
);
console
.
log
(
'Column:'
);
console
.
log
(
'Expected | (*error)Candidate\t[Votes]\t[Sum matrix (Sum score)]'
);
console
.
log
(
''
);
console
.
log
(
''
);
console
.
log
(
''
);
console
.
log
(
''
);
data
.
forEach
((
testCase
,
num
)
=>
{
console
.
log
(
"#"
+
num
+
": "
+
testCase
.
comment
);
var
election
=
new
RelativePlacement
();
var
votes
=
compileVotes
(
testCase
);
election
.
addCandidates
(
votes
[
0
]);
election
.
addVotes
(
votes
);
var
result
=
election
.
getResult
();
var
expected
=
testCase
.
result
;
var
candidates
=
election
.
candidateList
;
result
.
forEach
((
candidateName
,
place
)
=>
{
var
log
=
[];
var
candidate
=
candidates
[
candidateName
];
log
.
push
(
expected
[
place
]);
log
.
push
(
'\t|\t'
);
(
candidateName
!=
expected
[
place
])
?
log
.
push
(
'*'
)
:
log
.
push
(
' '
);
log
.
push
(
candidateName
);
log
.
push
(
'\t'
);
log
.
push
(
util
.
format
(
candidate
.
votes
));
log
.
push
(
'\t['
);
for
(
var
i
=
0
;
i
<
candidate
.
placements
.
length
;
i
++
){
log
.
push
(
i
==
0
?
' '
:
', '
);
log
.
push
(
candidate
.
placements
[
i
]);
log
.
push
(
'('
);
log
.
push
(
candidate
.
cumulativePlacement
[
i
]);
log
.
push
(
') '
);
}
log
.
push
(
' ]'
);
console
.
log
(
log
.
join
(
''
));
});
console
.
log
(
'-------------------------------------------------------------------'
);
console
.
log
(
''
);
console
.
log
(
''
);
});
/**
* @param {TestData} testData
* @return {String[][]}
*/
function
compileVotes
(
testData
){
var
votes
=
testData
.
votes
;
var
compileVotes
=
[];
var
candidates
=
Object
.
keys
(
votes
);
var
voteNumber
=
votes
[
candidates
[
0
]].
length
;
for
(
let
i
=
0
;
i
<
voteNumber
;
i
++
){
let
compileVote
=
[];
for
(
let
name
in
votes
){
compileVote
[
votes
[
name
][
i
]
-
1
]
=
name
;
}
compileVotes
[
i
]
=
compileVote
;
}
return
compileVotes
;
}
\ No newline at end of file
Please
register
or
sign in
to post a comment