Пример #1
0
 def test_subtract_whole_numbers_negative_result(self):
     assert Fraction(3) - Fraction(5) == Fraction(-2)
Пример #2
0
 def test_can_subtract_fractions_with_same_denominator(self):
     assert Fraction(2, 3) - Fraction(1, 3) == Fraction(1, 3)
     assert Fraction(1, 5) - Fraction(3, 5) == Fraction(-2, 5)
Пример #3
0
 def test_add_like_normal_numbers_use_plus_operator(self):
     assert Fraction(1, 3) + Fraction(1, 2) == Fraction(5, 6)
Пример #4
0
 def test_add_fractions(self):
     assert Fraction(1, 3) + Fraction(1, 2) == Fraction(5, 6)
     assert Fraction(1, 6) + Fraction(1, 3) == Fraction(1, 2)
     assert Fraction(1, 2) + Fraction(1, 2) == Fraction(1, 1)
     assert Fraction(1, 12) + Fraction(2, 12) == Fraction(1, 4)
     assert Fraction(7, 9) + Fraction(5, 9) == Fraction(4, 3)
Пример #5
0
 def test_can_not_create_fraction_with_zero_denominator(self):
     with self.assertRaises(ZeroDenominatorError):
         Fraction(1, 0)
Пример #6
0
 def test_add_with_zeros(self):
     assert Fraction(0, 2) + Fraction(0, 2) == Fraction(0, 2)
     assert Fraction(0, 13) + Fraction(1, 2) == Fraction(1, 2)
Пример #7
0
 def test_initial_location_of_sign_does_not_matter_for_equality(self):
     assert Fraction(-1, 2) == Fraction(1, -2)
Пример #8
0
 def test_can_subtract_fractions(self):
     assert Fraction(2, 3) - Fraction(1, 3) is not None
Пример #9
0
 def test_inequality_of_fractions(self):
     assert Fraction(2, 3) != Fraction(4, 7)
Пример #10
0
 def test_fractions_as_if_reduced(self):
     assert Fraction(2, 3) == Fraction(4, 6)
Пример #11
0
 def test_equality_of_fractions(self):
     assert Fraction(2, 3) == Fraction(2, 3)
Пример #12
0
 def test_fractions_are_improper_and_not_mixed(self):
     assert str(Fraction(37, 17)) != '2 3/17'
     assert Fraction(37, 17) == Fraction(37, 17)
Пример #13
0
 def test_fractions_are_in_lowest_terms(self):
     assert Fraction(2, 3) == Fraction(2, 3)
     assert Fraction(4, 6) == Fraction(2, 3)
     assert Fraction(5, 4) == Fraction(5, 4)
     assert Fraction(15, 12) == Fraction(5, 4)
Пример #14
0
 def test_substract_will_return_fraction_in_lowest_terms(self):
     assert str(Fraction(7, 15) - Fraction(4, 15)) == '1/5'
     assert str(Fraction(4, 15) - Fraction(7, 15)) == '-1/5'
Пример #15
0
 def test_double_negative_equals_positive(self):
     assert Fraction(-1, -2) == Fraction(1, 2)
Пример #16
0
 def test_subtract_with_different_denominators(self):
     assert Fraction(3, 7) - Fraction(1, 4) == Fraction(5, 28)
     assert Fraction(2, 3) - Fraction(1, 5) == Fraction(7, 15)
Пример #17
0
 def test_can_create_fraction(self):
     f = Fraction(1, 2)
     assert f is not None
Пример #18
0
 def test_subtract_whole_numbers_positive_result(self):
     assert Fraction(5) - Fraction(3) == Fraction(2)
Пример #19
0
 def test_can_print_fraction(self):
     # this is useful in test output
     f = Fraction(1, 2)
     assert str(f) == '1/2'