Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

167 add test class dd version of assertionqueries #172

Merged
merged 7 commits into from
Aug 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ else if(loser_index != -1 && (winner_index == -1 || loser_index < winner_index))
* {@inheritDoc}
*/
public String getDescription(){
return String.format("%s NEB %s: oneOver = %d; two Over = %d; oneUnder = %d, twoUnder = %d; " +
return String.format("%s NEB %s: oneOver = %d; twoOver = %d; oneUnder = %d, twoUnder = %d; " +
"other = %d; optimistic = %d; estimated = %d; risk %f.", winner, loser, oneVoteOverCount,
twoVoteOverCount, oneVoteUnderCount, twoVoteUnderCount, otherCount, optimisticSamplesToAudit,
estimatedSamplesToAudit, currentRisk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ else if (choices_left.get(0).equals(loser)) {
* {@inheritDoc}
*/
public String getDescription(){
return String.format("%s NEN %s assuming (%s) are continuing: oneOver = %d; two Over = %d; " +
return String.format("%s NEN %s assuming (%s) are continuing: oneOver = %d; twoOver = %d; " +
"oneUnder = %d, twoUnder = %d; other = %d; optimistic = %d; estimated = %d; risk %f.",
winner, loser, assumedContinuing, oneVoteOverCount, twoVoteOverCount, oneVoteUnderCount,
twoVoteUnderCount, otherCount, optimisticSamplesToAudit, estimatedSamplesToAudit, currentRisk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,39 +467,39 @@ public void testInitialOptimisticSampleSizeMixedAssertions(){
* Two CastVoteRecord's with a blank vote will not trigger a discrepancy.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyNone1(RecordType auditedType){
public void testComputeDiscrepancyNone1(final RecordType auditedType){
testComputeDiscrepancyNone(blank, auditedType, "Mixed Contest");
}

/**
* Two CastVoteRecord's with a single vote for "A" will not trigger a discrepancy.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyNone2(RecordType auditedType){
public void testComputeDiscrepancyNone2(final RecordType auditedType){
testComputeDiscrepancyNone(A, auditedType, "Mixed Contest");
}

/**
* Two CastVoteRecord's with a single vote for "B" will not trigger a discrepancy.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyNone3(RecordType auditedType){
public void testComputeDiscrepancyNone3(final RecordType auditedType){
testComputeDiscrepancyNone(B, auditedType, "Mixed Contest");
}

/**
* Two CastVoteRecord's with a vote for "A", "B", "C", "D" will not trigger a discrepancy.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testNENComputeDiscrepancyNone4(RecordType auditedType){
public void testNENComputeDiscrepancyNone4(final RecordType auditedType){
testComputeDiscrepancyNone(ABCD, auditedType, "Mixed Contest");
}

/**
* Two CastVoteRecord's with a vote for "B", "A", "C", "D" will not trigger a discrepancy.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testNENComputeDiscrepancyNone5(RecordType auditedType){
public void testNENComputeDiscrepancyNone5(final RecordType auditedType){
testComputeDiscrepancyNone(BACD, auditedType, "Mixed Contest");
}

Expand All @@ -509,7 +509,7 @@ public void testNENComputeDiscrepancyNone5(RecordType auditedType){
*/
@Test(dataProvider = "DiscrepancyTypes", dataProviderClass = AssertionTests.class,
expectedExceptions = IllegalArgumentException.class)
public void testNENRecordNoDiscrepancy(int theType){
public void testNENRecordNoDiscrepancy(final int theType){
IRVComparisonAudit ca = testComputeDiscrepancyNone(BACD, RecordType.AUDITOR_ENTERED,
"Mixed Contest");

Expand Down Expand Up @@ -587,7 +587,7 @@ public void testRemoveNullAuditInfoCVR(){
* The maximum discrepancy is 0.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyCVR_A_ACVR_ABCD(RecordType auditedType){
public void testComputeDiscrepancyCVR_A_ACVR_ABCD(final RecordType auditedType){
log(LOGGER, String.format("testComputeDiscrepancyCVR_A_ACVR_ABCD[%s]", auditedType));
resetMocks(A, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand Down Expand Up @@ -630,7 +630,7 @@ public void testRecordWrongDiscrepancy(){
* risk measurement before and after the removal of the recorded discrepancy.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeRecordRemoveDiscrepancyCVR_ABCD_ACVR_BACD(RecordType auditedType){
public void testComputeRecordRemoveDiscrepancyCVR_ABCD_ACVR_BACD(final RecordType auditedType){
log(LOGGER, String.format("testComputeRecordRemoveDiscrepancyCVR_ABCD_ACVR_BACD[%s]", auditedType));
resetMocks(ABCD, BACD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand Down Expand Up @@ -689,7 +689,7 @@ private void riskMeasurementCheck(IRVComparisonAudit audit, final List<Pair<Inte
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class,
expectedExceptions = RuntimeException.class)
public void testComputeRecordDiscrepancyNoCover(RecordType auditedType){
public void testComputeRecordDiscrepancyNoCover(final RecordType auditedType){
log(LOGGER, String.format("testComputeRecordDiscrepancyNoCover[%s]", auditedType));
resetMocks(ABCD, BACD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand All @@ -711,7 +711,7 @@ public void testComputeRecordDiscrepancyNoCover(RecordType auditedType){
* "A","B","C","D". The maximum discrepancy is 1.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyCVR_BACD_ACVR_ABCD(RecordType auditedType){
public void testComputeDiscrepancyCVR_BACD_ACVR_ABCD(final RecordType auditedType){
log(LOGGER, String.format("testComputeDiscrepancyCVR_BACD_ACVR_ABCD[%s]", auditedType));
resetMocks(BACD, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand All @@ -733,7 +733,7 @@ public void testComputeDiscrepancyCVR_BACD_ACVR_ABCD(RecordType auditedType){
* Audits to compute the expected risk values.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD(RecordType auditedType){
public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD(final RecordType auditedType){
log(LOGGER, String.format("testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD[%s]", auditedType));
resetMocks(BACD, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand Down Expand Up @@ -776,7 +776,7 @@ public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD(RecordType audi
* compute the expected risk values.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_mixed2(RecordType auditedType){
public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_mixed2(final RecordType auditedType){
log(LOGGER, String.format("testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_mixed2[%s]", auditedType));
resetMocks(BACD, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest 2");
IRVComparisonAudit ca = createIRVComparisonAuditMixed2();
Expand Down Expand Up @@ -819,7 +819,7 @@ public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_mixed2(RecordTy
* compute the expected risk values. Simple Contest 3 contains one NEB assertion.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_simple3(RecordType auditedType){
public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_simple3(final RecordType auditedType){
log(LOGGER, String.format("testComputeRecordDiscrepancyCVR_BACD_ACVR_ABCD_simple3[%s]", auditedType));
resetMocks(BACD, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Simple Contest 3");
IRVComparisonAudit ca = createIRVComparisonAuditSimple3();
Expand Down Expand Up @@ -892,7 +892,7 @@ public void testComputeRecordRemoveDiscrepancyCVR_BACD_ACVR_ABCD_simple4(RecordT
* discrepancy is 2.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyCVR_A_ACVR_B(RecordType auditedType){
public void testComputeDiscrepancyCVR_A_ACVR_B(final RecordType auditedType){
log(LOGGER, String.format("testComputeDiscrepancyCVR_A_ACVR_B[%s]", auditedType));
resetMocks(A, B, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand All @@ -911,7 +911,7 @@ public void testComputeDiscrepancyCVR_A_ACVR_B(RecordType auditedType){
* discrepancy is 1.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyCVR_B_ACVR_A(RecordType auditedType){
public void testComputeDiscrepancyCVR_B_ACVR_A(final RecordType auditedType){
log(LOGGER, String.format("testComputeDiscrepancyCVR_B_ACVR_A[%s]", auditedType));
resetMocks(B, A, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand All @@ -930,7 +930,7 @@ public void testComputeDiscrepancyCVR_B_ACVR_A(RecordType auditedType){
* The maximum discrepancy is 0.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyCVR_blank_ACVR_ABCD(RecordType auditedType){
public void testComputeDiscrepancyCVR_blank_ACVR_ABCD(final RecordType auditedType){
log(LOGGER, String.format("testComputeDiscrepancyCVR_blank_ACVR_ABCD[%s]", auditedType));
resetMocks(blank, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand All @@ -951,7 +951,7 @@ public void testComputeDiscrepancyCVR_blank_ACVR_ABCD(RecordType auditedType){
* Stark's Super Simple Simultaneous Single-Ballot Risk Limiting Audits to compute the expected risk values.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeRecordRemoveDiscrepancyCVR_blank_ACVR_ABCD(RecordType auditedType){
public void testComputeRecordRemoveDiscrepancyCVR_blank_ACVR_ABCD(final RecordType auditedType){
log(LOGGER, String.format("testComputeRecordRemoveDiscrepancyCVR_blank_ACVR_ABCD[%s]", auditedType));
resetMocks(blank, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand Down Expand Up @@ -989,7 +989,7 @@ public void testComputeRecordRemoveDiscrepancyCVR_blank_ACVR_ABCD(RecordType aud
* The maximum discrepancy is 0.
*/
@Test(dataProvider = "AuditedRecordTypes", dataProviderClass = AssertionTests.class)
public void testComputeDiscrepancyCVR_ABCD_ACVR_blank(RecordType auditedType){
public void testComputeDiscrepancyCVR_ABCD_ACVR_blank(final RecordType auditedType){
log(LOGGER, String.format("testComputeDiscrepancyCVR_ABCD_ACVR_blank[%s]", auditedType));
resetMocks(blank, ABCD, RecordType.UPLOADED, ConsensusValue.YES, auditedType, "Mixed Contest");
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand All @@ -1013,7 +1013,8 @@ public void testComputeDiscrepancyCVR_ABCD_ACVR_blank(RecordType auditedType){
* @param u2 Number of expected two vote understatements.
* @param o Number of expected "other" discrepancies.
*/
private void checkDiscrepancies(final IRVComparisonAudit ca, int o1, int o2, int u1, int u2, int o){
private void checkDiscrepancies(final IRVComparisonAudit ca, final int o1, final int o2,
final int u1, final int u2, final int o){
assertEquals(o1, ca.discrepancyCount(1));
assertEquals(o2, ca.discrepancyCount(2));
assertEquals(u1, ca.discrepancyCount(-1));
Expand All @@ -1029,8 +1030,8 @@ private void checkDiscrepancies(final IRVComparisonAudit ca, int o1, int o2, int
* @param contestName Name of the vote's contest.
* @return The IRVComparisonAudit constructed during the check.
*/
private IRVComparisonAudit testComputeDiscrepancyNone(CVRContestInfo info, RecordType auditedType,
final String contestName) {
private IRVComparisonAudit testComputeDiscrepancyNone(final CVRContestInfo info,
final RecordType auditedType, final String contestName) {
log(LOGGER, String.format("testComputeDiscrepancyNone[%s;%s]", info.choices(), auditedType));
resetMocks(info, info, RecordType.UPLOADED, ConsensusValue.YES, auditedType, contestName);
IRVComparisonAudit ca = createIRVComparisonAuditMixed();
Expand Down Expand Up @@ -1118,7 +1119,7 @@ private IRVComparisonAudit createIRVComparisonAuditSimple4(){
* @param dilutedMargin Diluted margin of the contest being audited.
*/
private void checkIRVComparisonAudit(final IRVComparisonAudit ca, final BigDecimal risk,
final AuditReason reason, final AuditStatus status, double dilutedMargin){
final AuditReason reason, final AuditStatus status, final double dilutedMargin){

assertEquals(status, ca.auditStatus());
assertEquals(reason, ca.auditReason());
Expand Down Expand Up @@ -1153,12 +1154,13 @@ private void checkIRVComparisonAudit(final IRVComparisonAudit ca, final BigDecim
* @param dilutedMargin Expected diluted margin.
*/
private void checkNEBAssertion(final Assertion a, final String winner, final String loser,
int oneOver, int twoOver, int oneUnder, int twoUnder, int other, int optimistic,
int estimated, double risk, final Map<Long,Integer> cvrDiscrepancy, double dilutedMargin){
final int oneOver, final int twoOver, final int oneUnder, final int twoUnder, final int other,
final int optimistic, final int estimated, final double risk, final Map<Long,Integer> cvrDiscrepancy,
final double dilutedMargin){

assert(a instanceof NEBAssertion);

final String expected = String.format("%s NEB %s: oneOver = %d; two Over = %d; oneUnder = %d, " +
final String expected = String.format("%s NEB %s: oneOver = %d; twoOver = %d; oneUnder = %d, " +
"twoUnder = %d; other = %d; optimistic = %d; estimated = %d; risk %f.", winner, loser,
oneOver, twoOver, oneUnder, twoUnder, other, optimistic, estimated,
BigDecimal.valueOf(risk).setScale(Assertion.RISK_DECIMALS, RoundingMode.HALF_UP));
Expand Down Expand Up @@ -1188,13 +1190,14 @@ private void checkNEBAssertion(final Assertion a, final String winner, final Str
* @param dilutedMargin Expected diluted margin.
*/
private void checkNENAssertion(final Assertion a, final String winner, final String loser,
final List<String> continuing, int oneOver, int twoOver, int oneUnder, int twoUnder, int other,
int optimistic, int estimated, double risk, final Map<Long,Integer> cvrDiscrepancy, double dilutedMargin){
final List<String> continuing, final int oneOver, final int twoOver, final int oneUnder,
final int twoUnder, final int other, final int optimistic, final int estimated, final double risk,
final Map<Long,Integer> cvrDiscrepancy, final double dilutedMargin){

assert(a instanceof NENAssertion);

final String expected = String.format("%s NEN %s assuming (%s) are continuing: oneOver = %d; " +
"two Over = %d; oneUnder = %d, twoUnder = %d; other = %d; optimistic = %d; estimated = %d; " +
"twoOver = %d; oneUnder = %d, twoUnder = %d; other = %d; optimistic = %d; estimated = %d; " +
"risk %f.", winner, loser, continuing, oneOver, twoOver, oneUnder, twoUnder, other,
optimistic, estimated, BigDecimal.valueOf(risk).setScale(Assertion.RISK_DECIMALS,
RoundingMode.HALF_UP));
Expand Down
Loading
Loading