aiee

Python modules for common command line interfacing utils
git clone git://git.defalsify.org/aiee.git
Info | Log | Files | Refs | LICENSE

test_numbers.py (879B)


      1 # standard imports
      2 import unittest
      3 
      4 # local imports
      5 from aiee.numbers import postfix_to_int
      6 
      7 
      8 class TestNumbers(unittest.TestCase):
      9 
     10     def test_postfix(self):
     11 
     12         for v in [
     13                 [42, 42, 0],
     14                 [1.0, 10, 1],
     15                 [3.14, 314, 2],
     16                 [0.667, 667, 3],
     17                 ]:
     18 
     19             s = str(v[0])
     20 
     21             for i, p in enumerate([
     22                 '',
     23                 'k',
     24                 'm',
     25                 'g',
     26                 't',
     27                 'p',
     28                 'e',
     29                 'z',
     30                 'y',
     31                 ]):
     32                 r = postfix_to_int(s + p)
     33                 x = v[1] * (10 ** ((i * 3) - v[2]))
     34                 self.assertEqual(int(x), r)
     35 
     36         r = postfix_to_int('42E11')
     37         x = 42 * (10 ** 11)
     38         self.assertEqual(x, r)
     39 
     40 
     41 if __name__ == '__main__':
     42     unittest.main()