float-values: Refactor tests to be less verbose

The goal is to be more concise thus more readable, as well as consistent
with most other tests.
This commit is contained in:
Adrien Vergé 2022-07-08 17:08:36 +02:00
parent e6af957131
commit dc2d0991e0

View File

@ -20,36 +20,14 @@ class FloatValuesTestCase(RuleTestCase):
rule_id = 'float-values' rule_id = 'float-values'
def test_disabled(self): def test_disabled(self):
conf = ( conf = 'float-values: disable\n'
'float-values: disable\n' self.check('---\n'
'new-line-at-end-of-file: disable\n' '- 0.0\n'
'document-start: disable\n' '- .NaN\n'
) '- .INF\n'
self.check('angle: 0.0', conf) '- .1\n'
self.check('angle: .NaN', conf) '- 10e-6\n',
self.check('angle: .INF', conf) conf)
self.check('angle: .1', conf)
self.check('angle: 10e-6', conf)
self.check(
'- &angle .0\n'
'- *angle\n',
conf,
)
self.check(
'- &angle 10e6\n'
'- *angle\n',
conf,
)
self.check(
'- &angle .nan\n'
'- *angle\n',
conf,
)
self.check(
'- &angle .inf\n'
'- *angle\n',
conf,
)
def test_numeral_before_decimal(self): def test_numeral_before_decimal(self):
conf = ( conf = (
@ -57,25 +35,19 @@ class FloatValuesTestCase(RuleTestCase):
' require-numeral-before-decimal: true\n' ' require-numeral-before-decimal: true\n'
' forbid-scientific-notation: false\n' ' forbid-scientific-notation: false\n'
' forbid-nan: false\n' ' forbid-nan: false\n'
' forbid-inf: false\n' ' forbid-inf: false\n')
'new-line-at-end-of-file: disable\n' self.check('---\n'
'document-start: disable\n' '- 0.0\n'
) '- .1\n'
self.check('angle: .1', conf, problem=(1, 8)) '- \'.1\'\n'
self.check('angle: 0.0', conf) '- !custom_tag .2\n'
self.check('angle: \'.1\'', conf) '- &angle1 0.0\n'
self.check('angle: !custom_tag 0.0', conf) '- *angle1\n'
self.check( '- &angle2 .3\n'
'- &angle 0.0\n' '- *angle2\n',
'- *angle\n', conf,
conf problem1=(3, 3),
) problem2=(8, 11))
self.check(
'- &angle .0\n'
'- *angle\n',
conf,
problem=(1, 10)
)
def test_scientific_notation(self): def test_scientific_notation(self):
conf = ( conf = (
@ -83,32 +55,24 @@ class FloatValuesTestCase(RuleTestCase):
' require-numeral-before-decimal: false\n' ' require-numeral-before-decimal: false\n'
' forbid-scientific-notation: true\n' ' forbid-scientific-notation: true\n'
' forbid-nan: false\n' ' forbid-nan: false\n'
' forbid-inf: false\n' ' forbid-inf: false\n')
'new-line-at-end-of-file: disable\n' self.check('---\n'
'document-start: disable\n' '- 10e6\n'
) '- 10e-6\n'
self.check('angle: 10e6', conf, problem=(1, 8)) '- 0.00001\n'
self.check('angle: 10e-6', conf, problem=(1, 8)) '- \'10e-6\'\n'
self.check('angle: 0.00001', conf) '- !custom_tag 10e-6\n'
self.check('angle: \'10e-6\'', conf) '- &angle1 0.000001\n'
self.check('angle: !custom_tag 10e-6', conf) '- *angle1\n'
self.check( '- &angle2 10e-6\n'
'- &angle 0.000001\n' '- *angle2\n'
'- *angle\n', '- &angle3 10e6\n'
conf '- *angle3\n',
) conf,
self.check( problem1=(2, 3),
'- &angle 10e-6\n' problem2=(3, 3),
'- *angle\n', problem3=(9, 11),
conf, problem4=(11, 11))
problem=(1, 10)
)
self.check(
'- &angle 10e6\n'
'- *angle\n',
conf,
problem=(1, 10)
)
def test_nan(self): def test_nan(self):
conf = ( conf = (
@ -116,20 +80,18 @@ class FloatValuesTestCase(RuleTestCase):
' require-numeral-before-decimal: false\n' ' require-numeral-before-decimal: false\n'
' forbid-scientific-notation: false\n' ' forbid-scientific-notation: false\n'
' forbid-nan: true\n' ' forbid-nan: true\n'
' forbid-inf: false\n' ' forbid-inf: false\n')
'new-line-at-end-of-file: disable\n' self.check('---\n'
'document-start: disable\n' '- .NaN\n'
) '- .NAN\n'
self.check('angle: .NaN', conf, problem=(1, 8)) '- \'.NaN\'\n'
self.check('angle: .NAN', conf, problem=(1, 8)) '- !custom_tag .NaN\n'
self.check('angle: \'.NaN\'', conf) '- &angle .nan\n'
self.check('angle: !custom_tag .NaN', conf) '- *angle\n',
self.check( conf,
'- &angle .nan\n' problem1=(2, 3),
'- *angle\n', problem2=(3, 3),
conf, problem3=(6, 10))
problem=(1, 10)
)
def test_inf(self): def test_inf(self):
conf = ( conf = (
@ -137,25 +99,22 @@ class FloatValuesTestCase(RuleTestCase):
' require-numeral-before-decimal: false\n' ' require-numeral-before-decimal: false\n'
' forbid-scientific-notation: false\n' ' forbid-scientific-notation: false\n'
' forbid-nan: false\n' ' forbid-nan: false\n'
' forbid-inf: true\n' ' forbid-inf: true\n')
'new-line-at-end-of-file: disable\n' self.check('---\n'
'document-start: disable\n' '- .inf\n'
) '- .INF\n'
self.check('angle: .inf', conf, problem=(1, 8)) '- -.inf\n'
self.check('angle: .INF', conf, problem=(1, 8)) '- -.INF\n'
self.check('angle: -.inf', conf, problem=(1, 8)) '- \'.inf\'\n'
self.check('angle: -.INF', conf, problem=(1, 8)) '- !custom_tag .inf\n'
self.check('angle: \'.inf\'', conf) '- &angle .inf\n'
self.check('angle: !custom_tag .inf', conf) '- *angle\n'
self.check( '- &angle -.inf\n'
'- &angle .inf\n' '- *angle\n',
'- *angle\n', conf,
conf, problem1=(2, 3),
problem=(1, 10) problem2=(3, 3),
) problem3=(4, 3),
self.check( problem4=(5, 3),
'- &angle -.inf\n' problem5=(8, 10),
'- *angle\n', problem6=(10, 10))
conf,
problem=(1, 10)
)