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
1201f347
...
1201f34789c8d0261772d0f91d1f43ddba1f170c
authored
2016-12-02 01:51:54 +0100
by
Vincent Peybernes
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
#1
Write structural test
1 parent
74c24f41
Pipeline
#3
for
1201f347
failed
in 13 seconds
Changes
1
Pipelines
1
Builds
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
4 deletions
tests/node/GlobalSpec.js
tests/node/GlobalSpec.js
View file @
1201f34
...
...
@@ -4,7 +4,7 @@
var
assert
=
require
(
'assert'
);
var
RelativePlacement
=
require
(
'../../relative-placement'
);
describe
(
'RelativePlacement'
,
()
=>
{
describe
(
'RelativePlacement
global
'
,
()
=>
{
it
(
'should provide RelativePlacement constructor'
,
()
=>
{
assert
.
ok
(
RelativePlacement
instanceof
Function
,
'provide constructor'
);
assert
.
ok
(
RelativePlacement
.
prototype
.
addCandidate
instanceof
Function
,
'provide "addCandidate" function in prototype'
);
...
...
@@ -71,15 +71,16 @@ describe('RelativePlacement', () => {
describe
(
'Add votes'
,
()
=>
{
var
election
;
var
candidates
=
[
'A'
,
'B'
,
'C'
];
beforeEach
(()
=>
{
election
=
new
RelativePlacement
();
election
.
addCandidates
(
[
'A'
,
'B'
,
'C'
]
);
election
.
addCandidates
(
candidates
);
});
it
(
'should add a vote to each candidates'
,
()
=>
{
var
vote
=
[
'A'
,
'B'
,
'C'
]
;
election
.
addVote
(
[
'A'
,
'B'
,
'C'
]
);
var
vote
=
candidates
;
election
.
addVote
(
vote
);
for
(
let
i
=
0
;
i
<
vote
.
length
;
i
++
){
let
candidate
=
election
.
candidateList
[
vote
[
i
]];
assert
.
equal
(
candidate
.
votes
.
length
,
1
,
'number of candidates vote'
);
...
...
@@ -125,5 +126,34 @@ describe('RelativePlacement', () => {
assert
.
equal
(
election
.
votes
.
length
,
0
,
'no vote registered'
);
assert
.
equal
(
election
.
candidateList
[
'A'
].
votes
.
length
,
0
,
'no vote registered in candidate'
);
});
it
(
'should lock candidate after add the first vote'
,
()
=>
{
election
.
addVote
(
candidates
);
assert
.
throws
(()
=>
election
.
addCandidate
(
'D'
));
});
});
describe
(
'Get result'
,
()
=>
{
/** @var RelativePlacement */
var
election
;
var
candidates
=
[
'A'
,
'B'
,
'C'
];
beforeEach
(()
=>
{
election
=
new
RelativePlacement
();
election
.
addCandidates
(
candidates
);
election
.
addVote
(
candidates
);
});
it
(
'should return an array'
,
()
=>
{
assert
.
ok
(
election
.
getResult
()
instanceof
Array
);
});
it
(
'should return only all candidates'
,
()
=>
{
var
result
=
election
.
getResult
();
assert
.
equal
(
result
.
length
,
candidates
.
length
);
assert
.
ok
(
candidates
.
every
(
name
=>
result
.
indexOf
(
name
)
!=
-
1
));
assert
.
ok
(
result
.
every
(
name
=>
candidates
.
indexOf
(
name
)
!=
-
1
));
});
});
});
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment