Skip to content

Commit

Permalink
Fixing bug in numeric comparator of recodex token judge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed Apr 5, 2019
1 parent 1a043b6 commit 362bda7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
6 changes: 5 additions & 1 deletion judges/recodex_token_judge/comparator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ template <typename CHAR = char, typename OFFSET = std::uint32_t> class TokenComp

double d1, d2;
if (tokenPair.tryGetFloats(d1, d2)) {
double err = std::abs(d1 - d2) / std::abs(d1 + d2);
// Divisor (normalizer) must not be zero, so we apply lower bound on it.
double divisorLimit = std::max(mFloatTolerance, 0.0001);
double divisor = std::max(std::abs(d1) + std::abs(d2), divisorLimit);

double err = std::abs(d1 - d2) / divisor;
return err <= mFloatTolerance;
}
}
Expand Down
2 changes: 1 addition & 1 deletion judges/recodex_token_judge/recodex-token-judge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char *argv[])
args.registerArg(bpp::make_unique<bpp::ProgramArguments::ArgBool>(
"numeric", "Tokens which appear to be integers or floats in decimal notation are compared as numbers."));
args.registerArg(bpp::make_unique<bpp::ProgramArguments::ArgFloat>("float-tolerance",
"Allowed maximal error for float number comparisons. The error of two numbers is |a-b|/|a+b|.",
"Allowed maximal error for float number comparisons. The error of two numbers is |a-b|/(|a|+|b|).",
false,
0.0001,
0.0,
Expand Down
2 changes: 1 addition & 1 deletion judges/recodex_token_judge/tests/05-numeric.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ load bats-shared
}

@test "numeric float tolerance" {
run $EXE_FILE --numeric --float-tolerance 0.01 $CORRECT_FILE $RESULT_FILE
run $EXE_FILE --numeric --float-tolerance 0.001 $CORRECT_FILE $RESULT_FILE
[ "$status" -eq 1 ]
}
1 change: 1 addition & 0 deletions judges/recodex_token_judge/tests/05.correct.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
some string tokens
followed by numeric tokens 42 1000000000 +54 -19 0012
and some float tokens 1.0 1.1 0.001 -0.0002 0.00003
0
12 changes: 7 additions & 5 deletions judges/recodex_token_judge/tests/05.error.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
0
-2: followed by numeric tokens 42 1000000000 +54 -19 0012
+2: followed by numeric tokens 42 +1000000000 0054 -19.0 12
-3: and some float tokens 1.0 1.1 0.001 -0.0002 0.00003
+3: and some float tokens +1.0 1.100 1e-03 -0.0002 0.000031
0
-2: followed by numeric tokens 42 1000000000 +54 -19 0012
+2: followed by numeric tokens 42 +1000000000 0054 -19.0 12
-3: and some float tokens 1.0 1.1 0.001 -0.0002 0.00003
+3: and some float tokens +1.0 1.100 1e-03 -0.0002 0.000031
-4: 0
+4: 0.00
1 change: 1 addition & 0 deletions judges/recodex_token_judge/tests/05.result.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
some string tokens
followed by numeric tokens 42 +1000000000 0054 -19.0 12
and some float tokens +1.0 1.100 1e-03 -0.0002 0.000031
0.00

0 comments on commit 362bda7

Please sign in to comment.