def testGR(self): "basic equalities" r1 = R(1) r2 = R(2) r3 = R(3) r7 = R(7) g1 = G(1) g2 = G(2) g3 = G(3) g7 = G(7) self.assertEqual(str(R(r1)), str(g1)) self.assertEqual(str(R(r1/r3)), str(g1/g3)) self.assertEqual(str(R(r2/r3)), str(g2/g3)) self.assertEqual(str(R(R.mul(r2, r3))), str(G.mul(g2, g3))) self.assertEqual(str(R(R.div(r2, r3))), str(G.div(g2, g3))) self.assertEqual(str(R(R.muldiv(r2, r3, r7))), str(G.muldiv(g2, g3, g7)))
class ValueTestRational(unittest.TestCase): "rational-specific unit tests" R.initialize(Options(dict())) f13 = R(1)/R(3) f15 = R(1)/R(5) f17 = R(1)/R(7) def testRat1(self): "no loss of precision" self.assertEqual(self.f13 * R(3), R(1)) def testMulDiv(self): "rational muldiv is the same as multiply followed by divide" self.assertEqual(R.muldiv(self.f13, self.f15, self.f17), self.f13*self.f15/self.f17)
def testMulDiv(self): "rational muldiv is the same as multiply followed by divide" self.assertEqual(R.muldiv(self.f13, self.f15, self.f17), self.f13*self.f15/self.f17)
def setUp(self): "initialize guarded and rational" R.initialize(Options(dict(arithmetic='rational', display=self.p))) G.initialize(Options(dict(arithmetic='guarded', precision=self.p, guard=self.g)))