def test_reduces_proper_mutability(self): A = Prob3.Fraction(4, 8) B = Prob3.Fraction(4, 8) C = B.reduce() assert str(A) == str( B ), 'In the process of reducing you changed the value of your Fraction. You want to return a NEW FRACTION without changing anything in place!'
def test_divide_by_fraction(self): vals = { ((1, 2), (1, 2)): '2/2', ((3, 4), (1, 2)): '6/4', ((6, 3), (1, 8)): '48/3', } for key in vals: A = Prob3.Fraction(*key[0]) B = Prob3.Fraction(*key[1]) assert str(A / B) == vals[ key], f'Dividing Fraction{key[0]} by Fraction{key[1]} should equal {vals[key]} but is equaling {str(A/B)}' assert isinstance( A * B, Prob3.Fraction ), 'Dividing a fraction by another fraction should return an object of type Fraction.'
def test_multiply_fractions(self): vals = { ((1, 2), (1, 2)): '1/4', ((3, 4), (1, 2)): '3/8', ((6, 3), (1, 8)): '6/24', } for key in vals: A = Prob3.Fraction(*key[0]) B = Prob3.Fraction(*key[1]) assert str(A * B) == vals[ key], f'Multiplying Fraction{key[0]} by Fraction{key[1]} should equal {vals[key]} but is equaling {str(A*B)}' assert isinstance( A * B, Prob3.Fraction ), 'Multiplying two fractions should return an object of type Fraction.'
def test_inverse(self): vals = {(3, 2): '2/3', (1, 8): '8/1', (2, 16): '16/2'} for key in vals: A = Prob3.Fraction(*key) assert str(A.inverse()) == vals[ key], f'The inverse is not correct. Should be {vals[key]} but is getting a printed value of {str(A.inverse())}' assert isinstance( A.inverse(), Prob3.Fraction ), 'You should be returning a Fraction object type.'
def test_float_conversion(self): vals = { (4, 5): float(4 / 5), (2, 3): float(2 / 3), (7, 1): float(7 / 1), } for key in vals: A = Prob3.Fraction(*key) assert float(A) == vals[ key], f'Conversion to a float is not equaling the desired value of {vals[key]} for Fraction{key}.'
def test_multiply_fraction_by_integer(self): vals = {((1, 2), 3): '3/2', ((3, 4), 2): '6/4', ((8, 5), 10): '80/5'} for key in vals: A = Prob3.Fraction(*key[0]) B = key[1] assert str(A * B) == vals[ key], f'Multiplying Fraction{key[0]} by {key[1]} should give {vals[key]} but instead gives {str(A*B)}.' assert str(B * A) == vals[ key], f'Multiplying {key[1]} by Fraction{key[0]} should give {vals[key]} but instead gives {str(A*B)}.' assert isinstance( A * B, Prob3.Fraction ), 'Multiplying a fraction by an integer should return an object of type Fraction.'
def test_reduces_proper_value(self): vals = { (1, 2): '1/2', (3, 6): '1/2', (8, 24): '1/3', (10, 100): '1/10' } for key in vals: A = Prob3.Fraction(*key) assert str(A.reduce()) == vals[ key], f'The fraction of Fraction{key} did not properly reduce to a printed value of {vals[key]}.' assert isinstance( A.reduce(), Prob3.Fraction ), 'You should still be returning a Fraction type object, but you are not.'
def test_divide_by_integer(self): vals = { ((1, 2), 3): '1/6', ((3, 4), 4): '3/16', ((6, 3), 2): '6/6', } for key in vals: A = Prob3.Fraction(*key[0]) B = key[1] assert str(A / B) == vals[ key], f'Dividing Fraction{key[0]} by {key[1]} should equal {vals[key]} but is equaling {str(A/B)}' assert isinstance( A * B, Prob3.Fraction ), 'Dividing a fraction by an integer should return an object of type Fraction.'
def test_prints_nicely(self): vals = {(1, 2): '1/2', (5, 2): '5/2', (4, 8): '4/8', (9, 3): '9/3'} for key in vals: A = Prob3.Fraction(*key) assert str(A) == vals[ key], f'The fraction of Fraction{key} did not print properly as {vals[key]}'
def test_can_create_instance(self): A = Prob3.Fraction(1, 2) assert isinstance(A, Prob3.Fraction)