3 ### Testing rational arithmetic functionality
5 ### (c) 2019 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to Catacomb.
12 ### Catacomb/Python is free software: you can redistribute it and/or
13 ### modify it under the terms of the GNU General Public License as
14 ### published by the Free Software Foundation; either version 2 of the
15 ### License, or (at your option) any later version.
17 ### Catacomb/Python is distributed in the hope that it will be useful, but
18 ### WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with Catacomb/Python. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 ###--------------------------------------------------------------------------
34 ###--------------------------------------------------------------------------
35 class TestRat (U.TestCase):
40 ## Check that exact true division in the base ring gives base-ring
42 a, b, c = R(19), R(5), R(8)
45 me.assertEqual(type(q), R)
48 ## Check that inexact division gives a fraction.
50 me.assertNotEqual(type(f), R)
51 me.assertNotEqual(f, a)
53 me.assertEqual(b*r, c)
55 ## More complicated arithmetic.
57 me.assertEqual((u + v)*(b*c), a*(b + c))
58 me.assertEqual((u - v)*(b*c), a*(c - b))
62 me.assertTrue(b/a < c/a)
63 me.assertFalse(c/a < b/a)
64 me.assertTrue(b/a <= c/a)
65 me.assertFalse(c/a <= b/a)
66 me.assertFalse(b/a >= c/a)
67 me.assertTrue(c/a >= b/a)
68 me.assertFalse(b/a > c/a)
69 me.assertTrue(c/a > b/a)
72 me.check_rat(C.IntRat)
74 ## Check string conversions.
76 me.assertEqual(str(u), "5/4")
77 me.assertEqual(repr(u), "IntRat(5, 4)")
82 ## Check string conversions.
84 me.assertEqual(str(u), "0x5/0x4")
85 me.assertEqual(repr(u), "GFRat(0x5, 0x4)")
90 me.assertRaises(TypeError, T.add, u, v)
92 ###----- That's all, folks --------------------------------------------------
94 if __name__ == "__main__": U.main()