Пример #1
0
 def __radd__(self, other):
     import pdb
     pdb.set_trace()
     if type(other) == int or type(other) == float:
         Fraction((self.convert(other)), self.val)._add_()
     else:
         Fraction(other, self.val)._add_()
def main():
    print(Fraction(2, 4))
    a = Fraction(1, 2)
    b = Fraction(2, 4)

    # print(a == b) # True

    print(a + b)  # 1
    print(a - b)  # 0
Пример #3
0
    def test_fraction_addition(self):

        fr1 = Fraction(1, 2)
        fr2 = Fraction(2, 3)

        result = fr1 + fr2
        expected = Fraction(7, 6)

        self.assertEqual(result, expected)
Пример #4
0
    def test_fraction_sorting(self):
        fr1 = Fraction(1, 2)
        fr2 = Fraction(1, 3)
        fr3 = Fraction(2, 3)

        fractions = [fr1, fr2, fr3]

        result = sorted(fractions)
        expected = [fr2, fr1, fr3]

        self.assertEqual(result, expected)
Пример #5
0
    def test_for_valid_input(self):

        err = None

        try:
            test = Fraction(4, 0)
        except Exception as e:
            err = e

        self.assertIsNotNone(err)
Пример #6
0
    def test_fraction_simplification(self):

        result = Fraction(10, 12).simplify()
        expected = Fraction(5, 6)

        self.assertEqual(result, expected)
Пример #7
0
    def test_string_casting(self):

        result = str(Fraction(3, 4))
        expected = '3/4'

        self.assertEqual(result, expected)
Пример #8
0
 def __add__(self, other):
     Fraction(self.val, other)._add_()