Skip to content

Commit

Permalink
Improvements from @michelleblom's review.
Browse files Browse the repository at this point in the history
  • Loading branch information
vteague committed Aug 2, 2024
1 parent f5d7224 commit f27089a
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import us.freeandfair.corla.persistence.StringListConverter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -96,7 +95,7 @@ public IRVBallotInterpretation() {
* @param orderedChoices the way colorado-rla interpreted the raw choices, as an order list of names.
*/
public IRVBallotInterpretation(final Contest contest, final CastVoteRecord.RecordType recordType,
int cvrNumber, final String imprintedId,
final int cvrNumber, final String imprintedId,
final List<String> rawChoices, final List<String> orderedChoices) {
this.contest = contest;
this.recordType = recordType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @version 1.0.0
* Edits by Vanessa Teague to incorporate recording of IRV invalid ballot interpretations. These
* are made only if the upload is OK but the IRV ballot is not a valid list of IRV preferences.
* These are stored in the IRVBallotInterpretations table.
* These are stored in the IRVBallotInterpretation table.
*/
@SuppressWarnings({"PMD.AtLeastOneConstructor", "PMD.CyclomaticComplexity"})
// TODO: consider rewriting along the same lines as CVRExportUpload
Expand Down Expand Up @@ -233,7 +233,7 @@ public String endpointBody(final Request the_request, final Response the_respons
* they are a valid list of IRV choices.
*/
private void recordIRVBallotInterpretations(final CastVoteRecord cvr, final RecordType recordType,
int cvrNumber, final String imprintedID) throws IRVParsingException {
final int cvrNumber, final String imprintedID) throws IRVParsingException {
for(CVRContestInfo contestInfo : cvr.contestInfo()) {
if(contestInfo.contest().description().equals(ContestType.IRV.toString())) {
final IRVChoices irvChoices = new IRVChoices(contestInfo.rawChoices());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ public class CVRContestInfo implements Serializable {
private List<String> my_choices = new ArrayList<>();

/**
* Raw, uninterpreted choices for this contest, for IRV. For example, These raw choices
* are used during ballot parsing, and are not required to be
* stored in the database.
* Raw, uninterpreted choices for this contest, for IRV. These raw choices are used during ballot
* parsing, and are not required to be stored in the database.
*/
@Transient
private final List<String> my_raw_choices = new ArrayList<>();
Expand Down Expand Up @@ -168,7 +167,7 @@ public ConsensusValue consensus() {
}

/**
* @return the choices in this record.
* @return the choices in this record, as an unmodifiable list.
*/
public List<String> choices() {
return Collections.unmodifiableList(my_choices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ public void initMocks() {

/**
* Basic test of proper functioning for uploaded audit CVRs, including:
* 1. a valid IRV vote
* 1. a valid IRV vote,
* 2. an invalid IRV vote, which should be stored as its valid interpretation,
* 3. a blank IRV vote,
* 4. a vote with non-IRV choices ("Alice" instead of "Alice(1)")
* 5. a vote with invalid choices (names not in the list of choices for the contest)
* 6. a vote that doesn't properly correspond to the IDs it should have
* 7. an unparseable vote (typos in json data)
* 4. a vote with non-IRV choices ("Alice" instead of "Alice(1)"),
* 5. a vote with invalid choices (names not in the list of choices for the contest),
* 6. a vote that doesn't properly correspond to the IDs it should have, and
* 7. an unparseable vote (typos in json data).
* We check that it is accepted and that the right records for CVR and CVRContestInfo are
* stored in the database.
*/
Expand All @@ -364,36 +364,38 @@ void testACVRUploadAndStorage() {
assertEquals(preCvrs.size(), 10);
assertEquals(preACvrs.size(), 0);

// // 1. Upload the first audit CVR (1-1-1; id 240509) (votes ["Bob(1)", "Chuan(2)"]) to the endpoint;
// // check that the right database records result, with correct interpreted vote ["Bob", "Chuan"].
// final Request request1 = new SparkRequestStub(validIRVAsJson, new HashSet<>());
// First test: upload the first audit CVR (1-1-1; id 240509) (votes ["Bob(1)", "Chuan(2)"]) to
// the endpoint. Check that the right database records result, with correct interpreted vote
// ["Bob", "Chuan"].
testSuccessResponse(240509L, "1-1-1", validIRVAsJson, List.of("Bob", "Chuan"), 1);

// // 2. Test that an invalid IRV vote [Chuan(1), Chuan(2), Bob(2), Alice(3)] is accepted and that its
// // valid interpretation [Chuan, Bob, Alice] is properly stored.
// Second test: upload an invalid IRV vote [Chuan(1), Chuan(2), Bob(2), Alice(3)]. Check that
// it is accepted and that its valid interpretation [Chuan, Bob, Alice] is properly stored.
testSuccessResponse(240510L, "1-1-2", invalidIRVAsJson, List.of("Chuan","Bob","Alice"), 2);
testIRVBallotInterpretations(2, "1-1-2", List.of("Chuan(1)","Chuan(2)","Bob(2)","Alice(3)"),
List.of("Chuan","Bob","Alice"));

// // 3. Upload a blank vote. Check the results.
// Third test: upload a blank vote. Check the results.
testSuccessResponse(240511L, "1-1-3", blankIRVAsJson, List.of(), 3);

// // 4. Upload a vote with plurality-style choices (no parenthesized ranks). This should cause an error.
// Fourth test: upload a vote with plurality-style choices (no parenthesized ranks). This
// should cause an error.

// Expected error messages for malformed upload cvrs.
String malformedACVRMsg = "malformed audit CVR upload";

testErrorResponse(240512L, pluralityIRVAsJson, malformedACVRMsg);

// // 5. Upload a vote with IRV choices that are not among the valid candidates. This should
// cause an error.
// Fifth test: upload a vote with IRV choices that are not among the valid candidates. This
// should cause an error.
testErrorResponse(240513L, wrongCandidateNamesIRVAsJson, malformedACVRMsg);

// // 6. Upload a vote with IDs that do not correspond properly to the expected CVR. This
// should cause an error.
// Sixth test: upload a vote with IDs that do not correspond properly to the expected CVR.
// This should cause an error.
testErrorResponse(240514L, IRVWithInconsistentIDsAsJson, malformedACVRMsg);

// // 7. Upload a vote that has typos preventing json deserialization. This should cause an error.
// Seventh test: upload a vote that has typos preventing json deserialization. This should
// cause an error.
testErrorResponse(240515L, IRVJsonDeserializationFail, malformedACVRMsg);
}
}
Expand All @@ -406,7 +408,7 @@ void testACVRUploadAndStorage() {
* @param rawChoices The raw choices (with parentheses, presumed invalid).
* @param validInterpretation The valid interpretation of the raw choices.
*/
private void testIRVBallotInterpretations(long CvrNum, final String imprintedId,
private void testIRVBallotInterpretations(final long CvrNum, final String imprintedId,
final List<String> rawChoices, final List<String> validInterpretation) {
final String CVRHeader = "CVR Number";
final String imprintedIDHeader = "Imprinted ID";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Democracy Developers IRV extensions to colorado-rla.
@copyright 2024 Colorado Department of State
These IRV extensions are designed to connect to a running instance of the raire
service (https://github.com/DemocracyDevelopers/raire-service), in order to
generate assertions that can be audited using colorado-rla.
The colorado-rla IRV extensions are free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
The colorado-rla IRV extensions are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
raire-service. If not, see <https://www.gnu.org/licenses/>.
*/

package au.org.democracydevelopers.corla.util;

import spark.Request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Democracy Developers IRV extensions to colorado-rla.
@copyright 2024 Colorado Department of State
These IRV extensions are designed to connect to a running instance of the raire
service (https://github.com/DemocracyDevelopers/raire-service), in order to
generate assertions that can be audited using colorado-rla.
The colorado-rla IRV extensions are free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
The colorado-rla IRV extensions are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
raire-service. If not, see <https://www.gnu.org/licenses/>.
*/

package au.org.democracydevelopers.corla.util;

import spark.Response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Democracy Developers IRV extensions to colorado-rla.
@copyright 2024 Colorado Department of State
These IRV extensions are designed to connect to a running instance of the raire
service (https://github.com/DemocracyDevelopers/raire-service), in order to
generate assertions that can be audited using colorado-rla.
The colorado-rla IRV extensions are free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
The colorado-rla IRV extensions are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
raire-service. If not, see <https://www.gnu.org/licenses/>.
*/

package au.org.democracydevelopers.corla.util;

import org.mockito.Mock;
Expand Down

0 comments on commit f27089a

Please sign in to comment.