def test_default_fraction_is_0_1(self): frac = Fraction() self.assertTrue(frac.is_equal(0, 1))
def test_sum_fraction_1_2_3_4(self): frac_1 = Fraction(1, 2) frac_2 = Fraction(3, 4) result = frac_1 + frac_2 self.assertTrue(result.is_equal(5, 4))
def test_create_fraction(self): frac = Fraction() self.assertTrue(isinstance(frac, Fraction))
def test_div_fraction(self): f1 = Fraction(1, 2) self.assertTrue((f1 / f1).is_equal(1, 1))
def test_multiply_fraction(self): frac_1 = Fraction(1, 2) frac_2 = Fraction(3, 4) result = frac_1 * frac_2 self.assertTrue(result.is_equal(3, 8))
def test_divide_two_same_fraction(self): frac_1 = Fraction(3, 5) frac_2 = Fraction(3, 5) result = frac_1 / frac_2 self.assertEqual(result.p, 1) self.assertEqual(result.q, 1)
def test_mul_fraction(self): f1 = Fraction(1, 2) f2 = Fraction(0, 3) self.assertTrue((f1 * f2).is_equal(0, 1))
def test_can_create_1_2_fraction(self): frac = Fraction(1, 2) self.assertTrue(frac.is_equal(1, 2))
def test_can_reduce_fraction(self): frac = Fraction(p=5, q=10) self.assertTrue(frac.is_equal(1, 2))
def test_can_create_fraction_isinstance(self): fraction = Fraction() self.assertTrue(isinstance(fraction, Fraction))
def test_multiply_fraction(self): frac_1 = Fraction(1, 3) frac_2 = Fraction(2, 5) result = frac_1 * frac_2 self.assertTrue(result.is_equal(2, 15))
def test_can_create_5_7_fraction_from_str(self): frac = Fraction.from_string('5/7') self.assertTrue(frac.is_equal(5, 7))
def test_can_return_decimal(self): fraction = Fraction(19, 5) self.assertTrue(fraction.to_decimal() == 3.8)
def test_can_return_integer(self): fraction = Fraction(19, 5) self.assertTrue(fraction.get_integer_part() == 3)
def test_can_convert_from_decimal_0_75(self): frac = Fraction.from_decimal(0.75) self.assertTrue(frac.is_equal(3, 4))
def test_can_create_str_from_fraction(self): frac = Fraction(p=3, q=4) self.assertEqual(str(frac), '3/4')
def test_can_convert_from_decimal_2_4(self): frac = Fraction.from_decimal(2.4) self.assertTrue(frac.is_equal(12, 5))
def test_multiply_by_1(self): frac_1 = Fraction(3, 10) frac_2 = Fraction(1, 1) result = frac_1 * frac_2 self.assertEqual(result.p, 3) self.assertEqual(result.q, 10)