Skip to content
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #77 from votingworks/fix/add-votes-for-ms-either-n…
Browse files Browse the repository at this point in the history
…either

fix: add votes for ms-either-neither contests
  • Loading branch information
eventualbuddha committed Sep 14, 2020
2 parents 5820463 + ced2d28 commit e4b8503
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@votingworks/hmpb-interpreter",
"version": "5.1.2",
"version": "5.1.3",
"description": "Interprets hand-marked paper ballots.",
"repository": "https://github.com/votingworks/hmpb-interpreter",
"license": "GPL-3.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,12 @@ test('interpret two-column template', async () => {
)
expect(votes).toMatchInlineSnapshot(`
Object {
"750000015": Array [
"yes",
],
"750000016": Array [
"yes",
],
"750000017": Array [
"no",
],
Expand Down
18 changes: 18 additions & 0 deletions src/getVotesFromMarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,27 @@ export default function getVotesFromMarks(
}
break

case 'ms-either-neither':
if (mark.score >= markScoreVoteThreshold) {
debug(
`'%s' contest '%s' mark score (%d) for '%s' meets vote threshold (%d)`,
mark.type,
mark.contest.id,
mark.score,
mark.option.label,
markScoreVoteThreshold
)
addVote(votes, mark.contest, mark.option)
}
break

case 'stray':
// TODO
break

default:
// @ts-expect-error - `mark` is `never` because the types say there are no other options
throw new Error(`mark type '${mark.type}' is not yet supported`)
}
}

Expand Down
49 changes: 35 additions & 14 deletions src/hmpb/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export function addVote(
export function addVote(
votes: VotesDict,
contest: MsEitherNeitherContest,
eitherNeither: YesNoOption,
pickOne: YesNoOption
option: YesNoOption
): void
export function addVote(
votes: VotesDict,
Expand All @@ -52,18 +51,40 @@ export function addVote(
contest.type === 'ms-either-neither' &&
typeof candidateOrYesNoOrEitherNeither === 'object'
) {
votes[contest.eitherNeitherContestId] = [
...(votes[contest.eitherNeitherContestId] ?? []),
candidateOrYesNoOrEitherNeither.id === contest.eitherOption.id
? 'yes'
: 'no',
] as YesNoVote
votes[contest.pickOneContestId] = [
...(votes[contest.pickOneContestId] ?? []),
candidateOrYesNoOrEitherNeither.id === contest.firstOption.id
? 'yes'
: 'no',
] as YesNoVote
switch (candidateOrYesNoOrEitherNeither.id) {
case contest.eitherOption.id:
votes[contest.eitherNeitherContestId] = [
...(votes[contest.eitherNeitherContestId] ?? []),
'yes',
] as YesNoVote
break

case contest.neitherOption.id:
votes[contest.eitherNeitherContestId] = [
...(votes[contest.eitherNeitherContestId] ?? []),
'no',
] as YesNoVote
break

case contest.firstOption.id:
votes[contest.pickOneContestId] = [
...(votes[contest.pickOneContestId] ?? []),
'yes',
] as YesNoVote
break

case contest.secondOption.id:
votes[contest.pickOneContestId] = [
...(votes[contest.pickOneContestId] ?? []),
'no',
] as YesNoVote
break

default:
throw new Error(
`unexpected option in ${contest.type} contest: ${candidateOrYesNoOrEitherNeither.id}`
)
}
} else {
throw new Error(
`Invalid vote for '${contest.type}' contest type: ${inspect(
Expand Down

0 comments on commit e4b8503

Please sign in to comment.