Modified unittests to match regression behavior

Modified unittests to match regression behavior. There appears to be a loss of accuracy regression in the formatSweepFrequency changes.
pull/95/head
dhunt1342 2019-11-16 11:49:59 -05:00
rodzic dcc1800c92
commit 1aa4e22d5a
2 zmienionych plików z 33 dodań i 25 usunięć

Wyświetl plik

@ -24,20 +24,12 @@ rft = RFTools.RFTools()
class TestCases(unittest.TestCase):
'''
def formatSweepFrequency(freq: int,
mindigits: int = 2,
appendHz: bool = True,
insertSpace: bool = False,
countDot: bool = True,
assumeInfinity: bool = True) -> str:
'''
def test_basicIntegerValues(self):
# simple well-formed integers with no trailing zeros. Most importantly
# even with default mindigits, there is no loss of accuracy in the
# result. Returned values are not truncated if result would lose
# meaningful data.
# there is no loss of accuracy in the result. Returned values are not
# truncated if result would lose meaningful data.
'''
Original Behavior:
self.assertEqual(rft.formatSweepFrequency(1), '1Hz')
self.assertEqual(rft.formatSweepFrequency(12), '12Hz')
self.assertEqual(rft.formatSweepFrequency(123), '123Hz')
@ -47,7 +39,19 @@ class TestCases(unittest.TestCase):
self.assertEqual(rft.formatSweepFrequency(1234567), '1.234567MHz')
self.assertEqual(rft.formatSweepFrequency(12345678), '12.345678MHz')
self.assertEqual(rft.formatSweepFrequency(123456789), '123.456789MHz')
'''
# New Behavior: results in loss of accuracy again.
self.assertEqual(rft.formatSweepFrequency(1), '1.0000Hz')
self.assertEqual(rft.formatSweepFrequency(12), '12.000Hz')
self.assertEqual(rft.formatSweepFrequency(123), '123.00Hz')
self.assertEqual(rft.formatSweepFrequency(1234), '1.2340kHz')
self.assertEqual(rft.formatSweepFrequency(12345), '12.345kHz')
self.assertEqual(rft.formatSweepFrequency(123456), '123.46kHz')
self.assertEqual(rft.formatSweepFrequency(1234567), '1.2346MHz')
self.assertEqual(rft.formatSweepFrequency(12345678), '12.346MHz')
self.assertEqual(rft.formatSweepFrequency(123456789), '123.46MHz')
'''
def test_defaultMinDigits(self):
# simple integers with trailing zeros.
# DEFAULT behavior retains 2 digits after the period, mindigits=2.
@ -55,7 +59,7 @@ class TestCases(unittest.TestCase):
self.assertEqual(rft.formatSweepFrequency(10000), '10.00kHz')
self.assertEqual(rft.formatSweepFrequency(100000), '100.00kHz')
self.assertEqual(rft.formatSweepFrequency(1000000), '1.00MHz')
def test_nonDefaultMinDigits(self):
# simple integers with trailing zeros. setting mindigit value to something
# other than default, where trailing zeros >= mindigits, the number of
@ -77,7 +81,7 @@ class TestCases(unittest.TestCase):
# TODO: Consider post-processing result for maxdigits based on SI unit.
self.assertEqual(rft.formatSweepFrequency(1000, mindigits=5), '1.00000kHz')
self.assertEqual(rft.formatSweepFrequency(1000, mindigits=10), '1.0000000000kHz')
'''
if __name__ == '__main__':
unittest.main(verbosity=2)

Wyświetl plik

@ -55,16 +55,12 @@ class TestCases(unittest.TestCase):
def test_unusualSIUnits(self):
#######################################################################
# Original behavior: unusual SI values that were legal, but inappropriate
# for this application provided unexpected outputs. This behavior was
# based on the full set of SI prefixes previously defined in SITools (below).
# Current behavior: unusual SI values that are legal, but inappropriate
# for this application provide unexpected outputs. This behavior is
# based on the FULL set of SI prefixes defined in SITools (below).
#PREFIXES = ("y", "z", "a", "f", "p", "n", "µ", "m",
# "", "k", "M", "G", "T", "P", "E", "Z", "Y")
# New Behavior: After the reduction of legal SI values defined in SITools
# (below), these now return a -1 failure code.
# PREFIXES = ("", "k", "M", "G")
#######################################################################
'''
self.assertEqual(rft.parseFrequency('123EHz'), 123000000000000000000)
self.assertEqual(rft.parseFrequency('123PHz'), 123000000000000000)
self.assertEqual(rft.parseFrequency('123THz'), 123000000000000)
@ -77,6 +73,13 @@ class TestCases(unittest.TestCase):
self.assertEqual(rft.parseFrequency('123pHz'), 0)
self.assertEqual(rft.parseFrequency('123yHz'), 0)
self.assertEqual(rft.parseFrequency('123zHz'), 0)
#######################################################################
# Recommend: Reducing the legal SI values defined in SITools (see
# below). This makes it more likely that typos will result in a -1
# failure code instead of being interpreted as an SI unit.
# PREFIXES = ("", "k", "M", "G")
#######################################################################
'''
self.assertEqual(rft.parseFrequency('123EHz'), -1)
self.assertEqual(rft.parseFrequency('123PHz'), -1)
@ -90,15 +93,15 @@ class TestCases(unittest.TestCase):
self.assertEqual(rft.parseFrequency('123pHz'), -1)
self.assertEqual(rft.parseFrequency('123yHz'), -1)
self.assertEqual(rft.parseFrequency('123zHz'), -1)
'''
def test_partialHzText(self):
#######################################################################
# Previous behavior for accidentally missing the H in Hz, resulted in
# The current behavior for accidentally missing the H in Hz, is a
# detection of 'z' SI unit (zepto = 10^-21), which then rounded to 0.
# After reduction of legal SI values in SITools, this now returns a -1
# failure code.
# After reduction of legal SI values in SITools, this would return
# a -1 failure code instead.
#######################################################################
'''
self.assertEqual(rft.parseFrequency('123z'), 0)
self.assertEqual(rft.parseFrequency('123.z'), 0)
self.assertEqual(rft.parseFrequency('1.23z'), 0)
@ -106,6 +109,7 @@ class TestCases(unittest.TestCase):
self.assertEqual(rft.parseFrequency('123z'), -1)
self.assertEqual(rft.parseFrequency('123.z'), -1)
self.assertEqual(rft.parseFrequency('1.23z'), -1)
'''
def test_basicExponentialNotation(self):
# check basic exponential notation