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
287e472b
...
287e472bf1691c6c2b8c2da3b56cd94ebd21c864
authored
2016-12-02 02:36:05 +0100
by
Vincent Peybernes
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
#2
Write Algo test
1 parent
1201f347
Pipeline
#4
for
287e472b
failed
in 15 seconds
Changes
2
Pipelines
1
Builds
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
tests/node/RelativePlacementSpec.js
tests/node/results_data.json
tests/node/RelativePlacementSpec.js
0 → 100644
View file @
287e472
/**
* Created by Techniv on 02/12/2016.
*/
var
assert
=
require
(
'assert'
);
var
RelativePlacement
=
require
(
'../../relative-placement'
);
/** @var {TestData[]} */
var
testDataList
=
require
(
'./results_data.json'
);
describe
(
'RelativePlacement algo'
,
()
=>
{
var
election
;
beforeEach
(()
=>
{
election
=
new
RelativePlacement
();
});
describe
(
'Process result data'
,()
=>
{
testDataList
.
forEach
(
/**
* @param {TestData} testData
* @param {Number} id
*/
(
testData
,
id
)
=>
{
it
(
'#'
+
id
+
': '
+
(
testData
.
comment
||
''
),
()
=>
{
election
.
addCandidates
(
testData
.
result
.
concat
().
sort
(()
=>
Math
.
random
()
-
Math
.
random
()));
var
votes
=
compileVotes
(
testData
);
votes
.
forEach
((
vote
)
=>
{
election
.
addVote
(
vote
);
});
assert
.
deepEqual
(
election
.
getResult
(),
testData
.
result
);
});
}
);
});
});
/**
* @name TestData
* @typedef Object
* @property {String} comment
* @property {Array[]}votes
* @property {String[]} result
*/
/**
* @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
tests/node/results_data.json
View file @
287e472
...
...
@@ -9,6 +9,7 @@
"result"
:
[
"A"
,
"B"
,
"C"
]
},
{
"comment"
:
"Novice Strictly final"
,
"votes"
:{
"320"
:
[
1
,
1
,
1
,
1
,
1
],
"284"
:
[
2
,
4
,
2
,
4
,
3
],
...
...
Please
register
or
sign in
to post a comment