Skip to content

Commit

Permalink
Merge branch 'main' into useTestClassWithDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
michelleblom authored Jun 24, 2024
2 parents 207db69 + 2bc6a87 commit 9348a78
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 411 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:

- name: Classic Tests
run: cd server/eclipse-project; mvn -Dtest='us.freeandfair.corla.**' test

- name: IRV Tests
run: cd server/eclipse-project; mvn -Dtest='au.org.democracydevelopers.corla.**' test
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ prefix, contestName, auditStatus(), auditReason(), diluted_margin, assertions.si
@Override
protected void recalculateSamplesToAudit() {
if(assertions == null){
// We have not associated assertions with this audit yet. When an IRVComparisonAudit
// We have not associated assertions with this audit yet. When an IRVComparisonAudit is
// constructed, we call the base class constructor first. The ComparisonAudit constructor
// calls sample size computation methods. So, this method may end up being called before
// the IRVComparisonAudit constructor has completed its setup (retrieving assertions from
Expand Down Expand Up @@ -255,13 +255,10 @@ protected void recalculateSamplesToAudit() {
}

/**
* This method is currently not being used in the base class. However, if it starts being used
* in the future, we need an IRV version for IRV audits. Consequently, we provide the IRV
* version here. This method computes and returns the initial (optimistic) sample size
* for the audit. This is computed by calling the optimistic sample size computation method
* of each of the audit's assertions, and returning the maximum of these. A RuntimeException is
* thrown if an unexpected error arises in computing optimistic sample sizes for each assertion.
* @return the optimistic sample size for the audit.
* This method computes and returns the initial (optimistic) sample size for the audit. This is
* computed by calling an initial sample size computation method in each assertion, and returning
* the maximum of the returned values.
* @return the initial (optimistic) sample size for the audit.
*/
@Override
public int initialSamplesToAudit() {
Expand All @@ -277,19 +274,19 @@ public int initialSamplesToAudit() {
final String contestName = getContestName();

try {
LOGGER.debug(String.format("%s computing the initial samples to audit for the IRV contest %s.",
prefix, contestName));
LOGGER.debug(String.format("%s computing the initial optimistic samples to audit for the " +
"IRV contest %s.", prefix, contestName));

if (assertions.isEmpty()) {
LOGGER.debug(String.format("%s No assertions for contest %s; returning an initial sample " +
"size of 0.", prefix, contestName));
return 0;
} else {
LOGGER.debug(String.format("%s calling computeOptimisticSamplesToAudit() for each " +
LOGGER.debug(String.format("%s calling computeInitialOptimisticSamplesToAudit() for each " +
"assertion in contest %s given risk limit %f.", prefix, contestName, getRiskLimit()));
final int samples = max(assertions.stream().map(a ->
a.computeOptimisticSamplesToAudit(getRiskLimit())).toList());
LOGGER.debug(String.format("%s optimistic sample size of %d computed for contest %s.",
a.computeInitialOptimisticSamplesToAudit(getRiskLimit())).toList());
LOGGER.debug(String.format("%s initial optimistic sample size of %d computed for contest %s.",
prefix, samples, contestName));
return samples;
}
Expand Down Expand Up @@ -530,7 +527,7 @@ public void recordDiscrepancy(final CVRAuditInfo theRecord, final int theType) {
// and the flag for indicating that a sample size recalculation is needed, *if* we did
// record a discrepancy against at least one of this audit's assertions.
if(recorded) {
super.removeDiscrepancy(theRecord, theType);
super.recordDiscrepancy(theRecord, theType);
}
LOGGER.debug(String.format("%s total number of overstatements (%f), optimistic sample " +
"recalculate needed (%s), estimated sample recalculate needed (%s),", prefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,32 @@ public Integer computeOptimisticSamplesToAudit(BigDecimal riskLimit) {
return optimisticSamplesToAudit;
}

/**
* For the given risk limit, compute the expected initial (optimistic) number of samples to audit
* for this assertion. This calculation calls Audit::optimistic() with zero's for each discrepancy
* count. This method does not change any of this assertion's internal sample size attributes.
*
* @param riskLimit The risk limit of the audit.
* @return The initial (optimistic) number of samples we expect we will need to sample to
* audit this assertion.
*/
public Integer computeInitialOptimisticSamplesToAudit(BigDecimal riskLimit){
final String prefix = "[computeInitialOptimisticSamplesToAudit]";

LOGGER.debug(String.format("%s Calling Audit::optimistic() with parameters: risk limit " +
"%f; diluted margin %f; gamma %f; two vote under count 0; one vote under count 0; " +
"one vote over count 0; two vote over count 0.", prefix, riskLimit, dilutedMargin, Audit.GAMMA));

// Call the colorado-rla audit math; update optimistic_samples_to_audit and return new value.
final int initialOptimistic = Audit.optimistic(riskLimit, dilutedMargin, Audit.GAMMA,
0, 0, 0, 0).intValue();

LOGGER.debug(String.format("%s Computed initial optimistic samples to audit for Assertion %d" +
" of %s ballots.", prefix, id, initialOptimistic));

return initialOptimistic;
}

/**
* Compute and return the estimated number of samples to audit for this assertion, given the
* number of ballots audited thus far and number of observed overstatements. This method takes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,28 @@ public static void checkComputeDiscrepancy(CastVoteRecord cvr, CastVoteRecord au
assertEquals(cvrDiscrepancies, a.cvrDiscrepancy);
}
}


/**
* Checks that the discrepancy counts in the given assertion 'a' are equal to the given
* parameters.
* @param a Assertion to check.
* @param oneOver Expected number of one vote overstatements.
* @param oneUnder Expected number of one vote understatements.
* @param twoOver Expected number of two vote overstatements.
* @param twoUnder Expected number of two vote understatements.
* @param other Expected number of other discrepancies.
* @param cvrDiscrepancy Expected internal map of CVR ID to discrepancy type.
*/
public static void checkCountsDiscrepancyMap(final Assertion a, int oneOver, int oneUnder,
int twoOver, int twoUnder, int other, final Map<Long,Integer> cvrDiscrepancy){

assertEquals(a.oneVoteOverCount.intValue(), oneOver);
assertEquals(a.oneVoteUnderCount.intValue(), oneUnder);
assertEquals(a.twoVoteOverCount.intValue(), twoOver);
assertEquals(a.twoVoteUnderCount.intValue(), twoUnder);
assertEquals(a.otherCount.intValue(), other);

assertEquals(a.cvrDiscrepancy, cvrDiscrepancy);
}
}
Loading

0 comments on commit 9348a78

Please sign in to comment.