Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Round to the hundredths place, not the thousandths place! #293.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfly committed Apr 9, 2016
1 parent 15ed084 commit 54b7603
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion both/lib/wca.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ wca.computeSolvesStatistics = function(solves, roundFormatCode) {
} else {
var average;
if(isTimed) {
average = Math.round(sum / countingSolvesCount);
average = Math.round(sum / countingSolvesCount / 10) * 10;
averageSolveTime = {
millis: average,
decimals: 2,
Expand Down
11 changes: 10 additions & 1 deletion tests/mocha/server/WcaTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ MochaWeb.testOnly(function() {
expectBestWorstIndex(stats, 1, 3);
});

it('simple average with rounding', function() {
// Luke Tycksen 2x2 Round 1 at Atomic Cubing 2016
let solves = [time(6030), time(4570), time(3880), time(3510), time(3250)];
let stats = wca.computeSolvesStatistics(solves, roundFormatCode);
expect(stats.average).to.deep.equal(time(3990));
expectBestWorstIndex(stats, 4, 0);
});

it('average with DNF', function() {
let solves = [time(555), time(1200), time(1200), dnf(), time(1200)];
let stats = wca.computeSolvesStatistics(solves, roundFormatCode);
Expand Down Expand Up @@ -79,7 +87,8 @@ MochaWeb.testOnly(function() {
it('average with 5 identical times', function() {
let solves = [time(555), time(555), time(555), time(555), time(555)];
let stats = wca.computeSolvesStatistics(solves, roundFormatCode);
expect(stats.average).to.deep.equal(time(555));
// Kind of tricky, but since WCA only handles hundredths, we round 0.555 to 0.56
expect(stats.average).to.deep.equal(time(560));
// We don't particularly care which of these 5 identical solves is
// best or worst, but we do care that they are different solves.
expect(stats.bestIndex).to.not.equal(stats.worstIndex);
Expand Down

0 comments on commit 54b7603

Please sign in to comment.