2 from ion
.n
.fixed
import *
3 from ion
.n
.powers
import *
6 class KnownValues(unittest
.TestCase
):
10 ( "65535/256", 255.99609375, 255),
11 ( "65535/16", 4095.93750000, 4095),
12 ( "65535/4", 16383.75000000, 16383),
13 ( "65535/2", 32767.50000000, 32767)
18 for value
,fval
,ival
in self
.knownvalues
:
19 result
= float(fixed(value
))
20 self
.assertAlmostEqual(result
, fval
, 2)
24 for value
, fval
, ival
in self
.knownvalues
:
25 result
= int(fixed(value
))
26 self
.assertEqual(result
, ival
, 2)
28 def testUnFloat(self
):
30 for value
, fval
, ival
in self
.knownvalues
:
31 #extract the scale from the value string
32 bits
= value
.find("/")
36 result
= str(fixed(fval
,intToExponent(bits
)))
37 self
.assertEqual(result
, value
)
41 for value
, fval
, ival
in self
.knownvalues
:
42 bits
= value
.find("/")
45 result
= str(fixed(ival
,intToExponent(bits
)))
46 self
.assertEqual(result
, "%s/%s" % (ival
,bits
) , 2)
49 #class Arithmetic(unittest.TestCase):
58 if __name__
== "__main__":