Skip to content

Commit 5591045

Browse files
Setup default value for votes_allowed to match the number_elected (#312)
* Setup default value for votes_allowed to match the number_elected Create C# unit test to test various default values * Removed the test for a single vote_allowed. * Changed the test name to be clearer
1 parent d92a866 commit 5591045

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestManifest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public class TestManifest
1212
{
1313

1414
[Test]
15-
public void Test_Can_Create_Contest()
15+
public void Test_Votes_Allowed_On_Create_Contest()
1616
{
1717
List<SelectionDescription> selections = new List<SelectionDescription>();
1818

19-
var contest = new ContestDescription("contest-id", "district-id", 1, VoteVariationType.n_of_m, 1,
19+
var contestThreeVotes = new ContestDescription("contest-id", "district-id", 1, VoteVariationType.n_of_m, 3,
2020
"test election", selections.ToArray());
2121

2222
// Assert
23-
Assert.AreEqual(contest.VotesAllowed, 1);
23+
Assert.AreEqual(3, contestThreeVotes.VotesAllowed);
2424
}
2525

2626

src/electionguard/manifest.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,10 @@ namespace electionguard
10271027
this->sequenceOrder = sequenceOrder;
10281028
this->voteVariation = voteVariation;
10291029
this->numberElected = numberElected;
1030-
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ? 1UL : 0UL;
1030+
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ||
1031+
voteVariation == VoteVariationType::one_of_m
1032+
? numberElected
1033+
: 0UL;
10311034
this->primaryPartyIds = {};
10321035
}
10331036

@@ -1042,7 +1045,10 @@ namespace electionguard
10421045
this->sequenceOrder = sequenceOrder;
10431046
this->voteVariation = voteVariation;
10441047
this->numberElected = numberElected;
1045-
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ? 1UL : 0UL;
1048+
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ||
1049+
voteVariation == VoteVariationType::one_of_m
1050+
? numberElected
1051+
: 0UL;
10461052
}
10471053

10481054
Impl(const string &objectId, const string &electoralDistrictId,

src/electionguard/serialize.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,12 @@ namespace electionguard
450450
auto sequenceOrder = j["sequence_order"].get<uint64_t>();
451451
auto variation = getVoteVariationType(j["vote_variation"].get<string>());
452452
auto elected = j["number_elected"].get<uint64_t>();
453-
auto allowed = j.contains("votes_allowed") && !j["votes_allowed"].is_null()
454-
? j["votes_allowed"].get<uint64_t>()
455-
: variation == VoteVariationType::n_of_m ? 1
456-
: 0;
453+
auto allowed =
454+
j.contains("votes_allowed") && !j["votes_allowed"].is_null()
455+
? j["votes_allowed"].get<uint64_t>()
456+
: variation == VoteVariationType::n_of_m || variation == VoteVariationType::one_of_m
457+
? elected
458+
: 0;
457459
auto name = j["name"].get<string>();
458460
auto title = j.contains("ballot_title") && !j["ballot_title"].is_null()
459461
? internationalizedTextFromJson(j["ballot_title"])

0 commit comments

Comments
 (0)