kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
better test coverage
rodzic
33aa3a758c
commit
3bed63cd9c
|
@ -17,9 +17,7 @@
|
|||
import unittest
|
||||
|
||||
# Import targets to be tested
|
||||
from NanoVNASaver.RFTools import \
|
||||
norm_to_impedance, impedance_to_norm, \
|
||||
reflection_coefficient, gamma_to_impedance
|
||||
from NanoVNASaver.RFTools import *
|
||||
|
||||
|
||||
class TestRFTools(unittest.TestCase):
|
||||
|
@ -61,3 +59,8 @@ class TestRFTools(unittest.TestCase):
|
|||
self.assertEqual(gamma_to_impedance(0), 50)
|
||||
self.assertAlmostEqual(gamma_to_impedance(0.2), 75)
|
||||
# TODO: insert more test values here
|
||||
|
||||
def test_clamp_value(self):
|
||||
self.assertEqual(clamp_value(1, 0, 10), 1)
|
||||
self.assertEqual(clamp_value(1, 2, 10), 2)
|
||||
self.assertEqual(clamp_value(1, -10, -1), -1)
|
||||
|
|
|
@ -18,6 +18,8 @@ import unittest
|
|||
|
||||
# Import targets to be tested
|
||||
from NanoVNASaver.SITools import Format, Value
|
||||
from decimal import Decimal
|
||||
from math import inf
|
||||
|
||||
F_DEFAULT = Format()
|
||||
|
||||
|
@ -28,7 +30,8 @@ F_ASSERT_OFFSET_2 = Format(max_offset=9)
|
|||
F_ASSERT_OFFSET_3 = Format(min_offset=9)
|
||||
F_ASSERT_CLAMP = Format(parse_clamp_min=10, parse_clamp_max=9)
|
||||
|
||||
F_DIGITS_3 = Format(max_nr_digits=3)
|
||||
F_DIGITS_3 = Format(max_nr_digits=3, min_offset=-2,
|
||||
max_offset=2, assume_infinity=False)
|
||||
F_DIGITS_4 = Format(max_nr_digits=4)
|
||||
F_DIGITS_31 = Format(max_nr_digits=31)
|
||||
|
||||
|
@ -46,6 +49,11 @@ class TestTSIToolsValue(unittest.TestCase):
|
|||
self.assertRaises(AssertionError, Value, fmt=F_ASSERT_OFFSET_3)
|
||||
self.assertRaises(AssertionError, Value, fmt=F_ASSERT_CLAMP)
|
||||
|
||||
def test_representation(self):
|
||||
a = Value(1)
|
||||
b = eval(repr(a))
|
||||
self.assertEqual(repr(a), repr(b))
|
||||
|
||||
def test_default_format(self):
|
||||
self.assertEqual(str(Value(0)), "0.00000")
|
||||
self.assertEqual(str(Value(1)), "1.00000")
|
||||
|
@ -95,9 +103,11 @@ class TestTSIToolsValue(unittest.TestCase):
|
|||
self.assertEqual(str(v.parse("1e3")), "1k")
|
||||
self.assertEqual(str(v.parse("1e4")), "10k")
|
||||
self.assertEqual(str(v.parse("1e5")), "100k")
|
||||
self.assertEqual(str(v.parse("1e9")), "1000M")
|
||||
self.assertEqual(str(v.parse("1e-1")), "100m")
|
||||
self.assertEqual(str(v.parse("1e-2")), "10m")
|
||||
self.assertEqual(str(v.parse("1e-3")), "1m")
|
||||
self.assertEqual(str(v.parse("1e-9")), "0")
|
||||
|
||||
def test_format_digits_4(self):
|
||||
v = Value(fmt=F_DIGITS_4)
|
||||
|
|
Ładowanie…
Reference in New Issue