Skip to content

Commit

Permalink
- Added checks for the election type and defaulting the VotesAllowed …
Browse files Browse the repository at this point in the history
…value to 1 if it is an n of m election (#305)

- Added C++ and C# unit tests to make sure the value gets set to 1
- Increased the build number for a new release of nuget package
  • Loading branch information
SteveMaier-IRT authored Jun 14, 2022
1 parent 3d6ab6e commit 6ba0bca
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ namespace ElectionGuard.Encrypt.Tests
public class TestManifest
{

[Test]
public void Test_Can_Create_Contest()
{
List<SelectionDescription> selections = new List<SelectionDescription>();

var contest = new ContestDescription("contest-id", "district-id", 1, VoteVariationType.n_of_m, 1,
"test election", selections.ToArray());

// Assert
Assert.AreEqual(contest.VotesAllowed, 1);
}


[Test]
public void Test_Can_Serialize_Sample_manifest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<!-- Project -->
<RootNamespace>ElectionGuard</RootNamespace>
<AssemblyName>ElectionGuard.Encryption</AssemblyName>
<Version>0.1.13</Version>
<AssemblyVersion>0.1.13.0</AssemblyVersion>
<AssemblyFileVersion>0.1.13.0</AssemblyFileVersion>
<Version>0.1.14</Version>
<AssemblyVersion>0.1.14.0</AssemblyVersion>
<AssemblyFileVersion>0.1.14.0</AssemblyFileVersion>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -19,7 +19,7 @@
<Title>ElectionGuard Encryption</Title>
<Description>Open source implementation of ElectionGuard's ballot encryption.</Description>
<Authors>Microsoft</Authors>
<PackageVersion>0.1.13</PackageVersion>
<PackageVersion>0.1.14</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/microsoft/electionguard-cpp</PackageProjectUrl>
<RepositoryUrl>https://github.com/microsoft/electionguard-cpp</RepositoryUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/electionguard/manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ namespace electionguard
this->sequenceOrder = sequenceOrder;
this->voteVariation = voteVariation;
this->numberElected = numberElected;
this->votesAllowed = 0UL;
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ? 1UL : 0UL;
this->primaryPartyIds = {};
}

Expand All @@ -1042,7 +1042,7 @@ namespace electionguard
this->sequenceOrder = sequenceOrder;
this->voteVariation = voteVariation;
this->numberElected = numberElected;
this->votesAllowed = 0UL;
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ? 1UL : 0UL;
}

Impl(const string &objectId, const string &electoralDistrictId,
Expand Down
3 changes: 2 additions & 1 deletion src/electionguard/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ namespace electionguard
auto elected = j["number_elected"].get<uint64_t>();
auto allowed = j.contains("votes_allowed") && !j["votes_allowed"].is_null()
? j["votes_allowed"].get<uint64_t>()
: 0;
: variation == VoteVariationType::n_of_m ? 1
: 0;
auto name = j["name"].get<string>();
auto title = j.contains("ballot_title") && !j["ballot_title"].is_null()
? internationalizedTextFromJson(j["ballot_title"])
Expand Down
13 changes: 13 additions & 0 deletions test/electionguard/test_manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ TEST_CASE("Can serialize InternalManifest")
// Assert
CHECK(internal->getManifestHash()->toHex() == fromJson->getManifestHash()->toHex());
}

TEST_CASE("Can construct Contest from Parameters")
{
vector<std::unique_ptr<electionguard::SelectionDescription>> selections;

// Arrange
auto data =
make_unique<ContestDescription>("contest-id", "district-id", 1, VoteVariationType::n_of_m, 1,
"test election", move(selections));

// Assert
CHECK_EQ(data->getVotesAllowed(), 1);
}

0 comments on commit 6ba0bca

Please sign in to comment.