Skip to content

Commit

Permalink
Add test for float to tobool and rename one test case
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTheBear committed Jun 19, 2020
1 parent 3cb3ba7 commit e74598f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion machinestate.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def tobool(value):
if isinstance(value, int):
return bool(value)
elif isinstance(value, float):
return bool(int(math.floor(value)))
return value != 0.0
elif isinstance(value, str):
if re.match(r"\d+", value):
return bool(int(value))
Expand Down
13 changes: 8 additions & 5 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,17 @@ def test_toboolIntTrue1(self):
def test_toboolIntTrue2(self):
out = machinestate.tobool(2)
self.assertEqual(out, True)
def test_toboolIntFalse(self):
def test_toboolIntTrueNeg4(self):
out = machinestate.tobool(-4)
self.assertEqual(out, True)
def test_toboolFloatFalse(self):
out = machinestate.tobool(0.0)
self.assertEqual(out, False)
def test_toboolIntTrue1(self):
out = machinestate.tobool(1.0)
def test_toboolFloatTruePos(self):
out = machinestate.tobool(1.2)
self.assertEqual(out, True)
def test_toboolIntTrue2(self):
out = machinestate.tobool(2.0)
def test_toboolFloatTrueNeg(self):
out = machinestate.tobool(-12.2)
self.assertEqual(out, True)
def test_toboolStrOn(self):
out = machinestate.tobool("on")
Expand Down

0 comments on commit e74598f

Please sign in to comment.