예제 #1
0
    def test_to_engstr(self):
        val = 123456789
        actual = misc.to_engstr(val)
        desired = "123.5e6"
        self.assertEqual(actual, desired)

        val = -98765e-8
        actual = misc.to_engstr(val)
        desired = "-987.7e-6"
        self.assertEqual(actual, desired)
예제 #2
0
    def test_to_engstr_digits(self):
        val = 123456

        digits = 2
        actual = misc.to_engstr(val, digits=digits)
        desired = "12e3"
        self.assertEqual(actual, desired)

        digits = 5
        actual = misc.to_engstr(val, digits=digits)
        desired = "123.46e3"
        self.assertEqual(actual, desired)
예제 #3
0
 def test_to_engstr_larger_than_milli(self):
     val = 123.456e-3
     actual = misc.to_engstr(val)
     desired = "0.1235"
     self.assertEqual(actual, desired)
예제 #4
0
 def test_to_engstr_smaller_than_kilo(self):
     val = 123.456
     actual = misc.to_engstr(val)
     desired = "123.5"
     self.assertEqual(actual, desired)
예제 #5
0
    def test_to_engstr_zero(self):
        eps = 1e-8
        vals = (0.0, 1e-1 * eps, -1e-1 * eps)

        for val in vals:
            self.assertEqual(misc.to_engstr(val, eps=eps), "0")