Exemplo n.º 1
0
 def testReprFixed0(self):
     "repr is the underlying _value"
     A = V.ArithmeticClass(
         Options(dict(arithmetic='fixed', precision=self.p)))
     self.assertEqual(repr(A(1)), '1')
     A = V.ArithmeticClass(Options(dict(arithmetic='integer')))
     self.assertEqual(repr(A(1)), '1')
Exemplo n.º 2
0
 def testFixedDisplay3(self):
     "fixed display < precision rounds properly"
     V.ArithmeticClass(
         Options(dict(arithmetic='fixed', precision=6, display=6)))
     self.assertEqual(str(F(20) / F(3)), '6.666666')
     V.ArithmeticClass(
         Options(dict(arithmetic='fixed', precision=7, display=6)))
     self.assertEqual(str(F(20) / F(3)), '6.666667')
Exemplo n.º 3
0
 def testBigDisplay(self):
     "display is limited to precision+guard"
     p = 5
     g = 6
     d = p + g + 1
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=p, guard=g, display=d)))
     self.assertEqual(A.display, p+g)
     self.assertEqual(str(A(20)/A(3)), '6.66666_666666')
Exemplo n.º 4
0
 def testUnaryOps(self):
     "test unary + and -"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=4)))
     x = A(1)
     y = A(2)
     self.assertEqual(x-y, -x)
     self.assertEqual(y-x, +x)
     self.assertEqual(abs(x-y), x)
Exemplo n.º 5
0
 def testMulDiv(self):
     "guarded muldiv"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     f13 = A(1)/A(3)
     f15 = A(1)/A(5)
     f17 = A(1)/A(7)
     self.assertEqual(A.muldiv(f13, f15, f17), f13*f15/f17)
     self.assertEqual(str(f13*f15/f17), '0.466666667')
     self.assertEqual(str(A.muldiv(f13, f15, f17)), '0.466666667')
Exemplo n.º 6
0
 def testMulDiv0(self):
     "guarded muldiv with g=0"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9, guard=0)))
     f13 = A(1)/A(3)
     f15 = A(1)/A(5)
     f17 = A(1)/A(7)
     self.assertEqual(A.muldiv(f13, f15, f17)._value, (f13*f15/f17)._value+5)
     self.assertEqual(A.muldiv(f13, f15, f17, round='down')._value, (f13*f15/f17)._value+5)
     self.assertEqual(A.muldiv(f13, f15, f17, round='up')._value, (f13*f15/f17)._value+6)
     self.assertEqual(str(f13*f15/f17), '0.466666664')
     self.assertEqual(str(A.muldiv(f13, f15, f17)), '0.466666669')
Exemplo n.º 7
0
 def testNoHash(self):
     "test guarded/int"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     x = A(2)
     self.assertRaises(NotImplementedError, hash, x)
Exemplo n.º 8
0
 def testMulInt(self):
     "test guarded*int"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     x = A(2)
     y = A(3)
     self.assertEqual(x*y, x*3)
Exemplo n.º 9
0
 def testFixedDisplay2(self):
     "fixed display != precision gets a mention in info"
     V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=6, display=5)))
     self.assertTrue(F.info.find('display') > 0)
Exemplo n.º 10
0
 def testValueInitRational(self):
     "class Rational if arithmetic=rational"
     self.assertEqual(V.ArithmeticClass(Options(dict(arithmetic='rational'))), R)
Exemplo n.º 11
0
 def testValueInitRationalDefault(self):
     "default class Guarded"
     self.assertEqual(V.ArithmeticClass(Options(dict(precision=8))), G)
Exemplo n.º 12
0
 def testDisplay(self):
     "display defaults to precision"
     p = 5
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=p)))
     self.assertEqual(A.display, p)
     self.assertEqual(str(A(20)/A(3)), '6.66667')
Exemplo n.º 13
0
 def testGeps(self):
     "geps is a function of guard"
     p = 9
     g = p
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=p)))
     self.assertEqual(A._Guarded__geps, 10**g/2)
Exemplo n.º 14
0
 def testScale(self):
     "scale is a function of precision and guard"
     p = 9
     g = p
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=p)))
     self.assertEqual(A._Guarded__scale, 10**(p+g))
Exemplo n.º 15
0
 def testExact(self):
     "guarded is exact"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     self.assertEqual(A.exact, True)
Exemplo n.º 16
0
 def setUp(self):
     "initialize fixed class"
     V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=self.p, guard=self.g)))
Exemplo n.º 17
0
 def setUp(self):
     "initialize fixed point 0 places"
     self.A = V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=self.p, guard=self.g)))
Exemplo n.º 18
0
 def testSetvalFixed6(self):
     "set a fixed value directly"
     A = V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=6)))
     f = A(123456, True)
     self.assertEqual(repr(A(f)), 'Fixed(123456,True)')
     self.assertEqual(A(1000000, True), A(1))
Exemplo n.º 19
0
 def testRepr(self):
     "repr is the underlying _value"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     self.assertEqual(repr(A(1)), 'Guarded(1000000000000000000,True)')
Exemplo n.º 20
0
 def testNe(self):
     "not equal"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     self.assertFalse(A(1)!=A(1))
Exemplo n.º 21
0
 def testFixedInteger(self):
     "fixed precision 0 means integer"
     V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=0)))
     self.assertEqual(F.tag(), 'integer')
Exemplo n.º 22
0
 def testValueInitFixed(self):
     "class Fixed if arithmetic=fixed"
     self.assertEqual(V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=8))), F)
Exemplo n.º 23
0
 def testDivInt(self):
     "test guarded/int"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     x = A(2)
     y = A(3)
     self.assertEqual(x/y, x/3)
Exemplo n.º 24
0
 def testFixedIntegerP0(self):
     "fixed=integer yields precision 0"
     V.ArithmeticClass(Options(dict(arithmetic='integer')))
     self.assertEqual(F.precision, 0)
Exemplo n.º 25
0
 def testFixedDisplay1(self):
     "fixed display must be <= precision"
     V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=6, display=7)))
     self.assertEqual(F.display, 6)
     self.assertTrue(F.info.find('display') < 0)