Example #1
0
 def test_invert(self):
     self.assertEqual(self.f12.__invert__(), fracs.Frac(2, 1))
Example #2
0
 def setUp(self):
     self.f12 = fracs.Frac(1, 2)
     self.f12prim = fracs.Frac(1, 2)
     self.f13 = fracs.Frac(1, 3)
Example #3
0
 def test_pos(self):
     self.assertEqual(fracs.Frac(-1, -2).__pos__(), self.f12)
     self.assertEqual(fracs.Frac(-1, 2).__pos__(), self.f12)
     self.assertEqual(fracs.Frac(1, -2).__pos__(), self.f12)
Example #4
0
 def test_neg(self):
     self.assertEqual(fracs.Frac(-1, -2).__neg__(), fracs.Frac(-1, 2))
     self.assertEqual(fracs.Frac(-1, 2).__neg__(), fracs.Frac(1, 2))
     self.assertEqual(fracs.Frac(1, -2).__neg__(), fracs.Frac(1, 2))
     self.assertEqual(fracs.Frac(1, 2).__neg__(), fracs.Frac(-1, 2))
Example #5
0
 def test_div(self):
     self.assertEqual(self.f12 / self.f13, fracs.Frac(3, 2))
     self.assertEqual(self.f12 / 2, fracs.Frac(1, 4))
     self.assertEqual(2 / self.f12, fracs.Frac(4, 1))
Example #6
0
 def test_mul(self):
     self.assertEqual(self.f12 * self.f13, fracs.Frac(1, 6))
     self.assertEqual(self.f12 * 2, fracs.Frac(1, 1))
     self.assertEqual(2 * self.f12, fracs.Frac(1, 1))
Example #7
0
 def test_sub(self):
     self.assertEqual(1 - self.f12, fracs.Frac(1, 2))
     self.assertEqual(self.f12 - 1, fracs.Frac(-1, 2))
Example #8
0
 def test_add(self):
     self.assertEqual(1 + self.f12, fracs.Frac(3, 2))
     self.assertEqual(self.f13 + 1, fracs.Frac(4, 3))
Example #9
0
    def test_str(self):
        self.assertEqual(str(fracs.Frac(2, 1)), '2')
        self.assertEqual(str(fracs.Frac(1, 2)), '1/2')

        with self.assertRaises(ValueError):
            fracs.Frac(2, 0)