Skip to content

Commit

Permalink
Update test_validators.py
Browse files Browse the repository at this point in the history
Updated and fixed the float validator test case added by the user for the PR #384
  • Loading branch information
ashah-splunk committed Dec 13, 2021
1 parent 6b0d620 commit 7928675
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tests/searchcommands/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ def test(integer):

def test_float(self):
# Float validator test
import random

maxsize = sys.maxsize
minsize = -(sys.maxsize - 1)
maxsize = random.random() + 1
minsize = random.random() - 1

validator = validators.Float()

Expand Down Expand Up @@ -240,27 +241,25 @@ def test(float_val):
self.assertEqual(validator.__call__(0), 0)
self.assertEqual(validator.__call__(1.154), 1.154)
self.assertEqual(validator.__call__(888.51), 888.51)
self.assertEqual(validator.__call__(2 * maxsize), float(2 * maxsize))
self.assertEqual(validator.__call__(2 * maxsize), (2 * maxsize))
self.assertRaises(ValueError, validator.__call__, -1)
self.assertRaises(ValueError, validator.__call__, -1111.00578)
self.assertRaises(ValueError, validator.__call__, -0.005)

validator = validators.Float(minimum=1, maximum=maxsize)
self.assertEqual(validator.__call__(1), float(1))
self.assertEqual(validator.__call__(100.111), 100.111)
self.assertEqual(validator.__call__(9999.0), 9999.0)
self.assertEqual(validator.__call__(maxsize), float(maxsize))
self.assertEqual(validator.__call__(maxsize), maxsize)
self.assertRaises(ValueError, validator.__call__, 0)
self.assertRaises(ValueError, validator.__call__, 0.9999)
self.assertRaises(ValueError, validator.__call__, -199)
self.assertRaises(ValueError, validator.__call__, maxsize + 1)

validator = validators.Float(minimum=-1, maximum=1)
self.assertEqual(validator.__call__(0), float(0))
validator = validators.Float(minimum=minsize, maximum=maxsize)
self.assertEqual(validator.__call__(minsize), minsize)
self.assertEqual(validator.__call__(0.123456), 0.123456)
self.assertEqual(validator.__call__(0), float(0))
self.assertEqual(validator.__call__(-0.012), -0.012)
self.assertRaises(ValueError, validator.__call__, -1.1)
self.assertRaises(ValueError, validator.__call__, 100.123456)
self.assertEqual(validator.__call__(maxsize), maxsize)
self.assertRaises(ValueError, validator.__call__, minsize - 1)
self.assertRaises(ValueError, validator.__call__, maxsize + 1)

return
Expand Down

0 comments on commit 7928675

Please sign in to comment.