Skip to content

Commit

Permalink
Fix error when checking floats returned true for NaN.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbeloglazov committed Feb 24, 2013
1 parent d59fb90 commit 35cb410
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_checker.py
Expand Up @@ -37,3 +37,5 @@ def test_checker_floats(self):
self.assertFalse(checker_floats(correct, output))
output = "1 or 0.4e-1"
self.assertTrue(checker_floats(correct, output, eps = 0.01))
# Check NaN
self.assertFalse(checker_floats("1", "nan"))
4 changes: 4 additions & 0 deletions tools/checkers.py
@@ -1,3 +1,5 @@
from math import isnan

"""Author: Andrey Malevich
This module contains different checkers which are used to test outputs of
programs.
Expand Down Expand Up @@ -71,6 +73,8 @@ def checker_floats(correct, output, eps = 1e-6):
try: #Otherwise we assume that they are floats
first = float(first)
second = float(second)
if isnan(first) or isnan(second):
return False
if first > second + eps or second > first + eps: #In case they differ in
# more than eps
return False
Expand Down

0 comments on commit 35cb410

Please sign in to comment.