Skip to content

Commit 6ba0bca

Browse files
- Added checks for the election type and defaulting the VotesAllowed 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
1 parent 3d6ab6e commit 6ba0bca

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ namespace ElectionGuard.Encrypt.Tests
1111
public class TestManifest
1212
{
1313

14+
[Test]
15+
public void Test_Can_Create_Contest()
16+
{
17+
List<SelectionDescription> selections = new List<SelectionDescription>();
18+
19+
var contest = new ContestDescription("contest-id", "district-id", 1, VoteVariationType.n_of_m, 1,
20+
"test election", selections.ToArray());
21+
22+
// Assert
23+
Assert.AreEqual(contest.VotesAllowed, 1);
24+
}
25+
26+
1427
[Test]
1528
public void Test_Can_Serialize_Sample_manifest()
1629
{

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/ElectionGuard.Encryption.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<!-- Project -->
88
<RootNamespace>ElectionGuard</RootNamespace>
99
<AssemblyName>ElectionGuard.Encryption</AssemblyName>
10-
<Version>0.1.13</Version>
11-
<AssemblyVersion>0.1.13.0</AssemblyVersion>
12-
<AssemblyFileVersion>0.1.13.0</AssemblyFileVersion>
10+
<Version>0.1.14</Version>
11+
<AssemblyVersion>0.1.14.0</AssemblyVersion>
12+
<AssemblyFileVersion>0.1.14.0</AssemblyFileVersion>
1313
</PropertyGroup>
1414

1515
<PropertyGroup>
@@ -19,7 +19,7 @@
1919
<Title>ElectionGuard Encryption</Title>
2020
<Description>Open source implementation of ElectionGuard's ballot encryption.</Description>
2121
<Authors>Microsoft</Authors>
22-
<PackageVersion>0.1.13</PackageVersion>
22+
<PackageVersion>0.1.14</PackageVersion>
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
<PackageProjectUrl>https://github.com/microsoft/electionguard-cpp</PackageProjectUrl>
2525
<RepositoryUrl>https://github.com/microsoft/electionguard-cpp</RepositoryUrl>

src/electionguard/manifest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ namespace electionguard
10271027
this->sequenceOrder = sequenceOrder;
10281028
this->voteVariation = voteVariation;
10291029
this->numberElected = numberElected;
1030-
this->votesAllowed = 0UL;
1030+
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ? 1UL : 0UL;
10311031
this->primaryPartyIds = {};
10321032
}
10331033

@@ -1042,7 +1042,7 @@ namespace electionguard
10421042
this->sequenceOrder = sequenceOrder;
10431043
this->voteVariation = voteVariation;
10441044
this->numberElected = numberElected;
1045-
this->votesAllowed = 0UL;
1045+
this->votesAllowed = voteVariation == VoteVariationType::n_of_m ? 1UL : 0UL;
10461046
}
10471047

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

src/electionguard/serialize.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ namespace electionguard
452452
auto elected = j["number_elected"].get<uint64_t>();
453453
auto allowed = j.contains("votes_allowed") && !j["votes_allowed"].is_null()
454454
? j["votes_allowed"].get<uint64_t>()
455-
: 0;
455+
: variation == VoteVariationType::n_of_m ? 1
456+
: 0;
456457
auto name = j["name"].get<string>();
457458
auto title = j.contains("ballot_title") && !j["ballot_title"].is_null()
458459
? internationalizedTextFromJson(j["ballot_title"])

test/electionguard/test_manifest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,16 @@ TEST_CASE("Can serialize InternalManifest")
6565
// Assert
6666
CHECK(internal->getManifestHash()->toHex() == fromJson->getManifestHash()->toHex());
6767
}
68+
69+
TEST_CASE("Can construct Contest from Parameters")
70+
{
71+
vector<std::unique_ptr<electionguard::SelectionDescription>> selections;
72+
73+
// Arrange
74+
auto data =
75+
make_unique<ContestDescription>("contest-id", "district-id", 1, VoteVariationType::n_of_m, 1,
76+
"test election", move(selections));
77+
78+
// Assert
79+
CHECK_EQ(data->getVotesAllowed(), 1);
80+
}

0 commit comments

Comments
 (0)