コード例 #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')
コード例 #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')
コード例 #3
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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')
コード例 #4
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)
コード例 #5
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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')
コード例 #6
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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')
コード例 #7
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testNoHash(self):
     "test guarded/int"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     x = A(2)
     self.assertRaises(NotImplementedError, hash, x)
コード例 #8
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)
コード例 #9
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)
コード例 #10
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testValueInitRational(self):
     "class Rational if arithmetic=rational"
     self.assertEqual(V.ArithmeticClass(Options(dict(arithmetic='rational'))), R)
コード例 #11
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testValueInitRationalDefault(self):
     "default class Guarded"
     self.assertEqual(V.ArithmeticClass(Options(dict(precision=8))), G)
コード例 #12
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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')
コード例 #13
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)
コード例 #14
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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))
コード例 #15
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testExact(self):
     "guarded is exact"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     self.assertEqual(A.exact, True)
コード例 #16
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def setUp(self):
     "initialize fixed class"
     V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=self.p, guard=self.g)))
コード例 #17
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def setUp(self):
     "initialize fixed point 0 places"
     self.A = V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=self.p, guard=self.g)))
コード例 #18
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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))
コード例 #19
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)')
コード例 #20
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testNe(self):
     "not equal"
     A = V.ArithmeticClass(Options(dict(arithmetic='guarded', precision=9)))
     self.assertFalse(A(1)!=A(1))
コード例 #21
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testFixedInteger(self):
     "fixed precision 0 means integer"
     V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=0)))
     self.assertEqual(F.tag(), 'integer')
コード例 #22
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testValueInitFixed(self):
     "class Fixed if arithmetic=fixed"
     self.assertEqual(V.ArithmeticClass(Options(dict(arithmetic='fixed', precision=8))), F)
コード例 #23
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)
コード例 #24
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 def testFixedIntegerP0(self):
     "fixed=integer yields precision 0"
     V.ArithmeticClass(Options(dict(arithmetic='integer')))
     self.assertEqual(F.precision, 0)
コード例 #25
0
ファイル: test_values.py プロジェクト: skidooesy/droop
 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)