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_multiples_of_six_and_seven(self, capsys): Prob3.print_multiples() captured = capsys.readouterr().out.rstrip() values = [int(n) for n in captured.split('\n')] for num in values: assert not ( num % 6 == 0 and num % 7 == 0 ), f"The number {num} was printed to the screen, but it is divisible by both 6 AND 7, and thus should not be printed."
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_count_mines_returns_proper_sized_array(self): to_check = [Prob3.mine_locations, self.alt_layout1, self.alt_layout2] sols = [[6, 6], [3, 3], [2, 3]] for array, sizes in zip(to_check, sols): student = Prob3.count_mines(array) assert len( student) == sizes[0], "Array seems to be the wrong height?" assert len( student[0]) == sizes[1], "Array seems to be the wrong width?"
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_something(self, capsys): Prob3.print_multiples() captured = capsys.readouterr().out.rstrip() assert len( captured ) > 0, "Is your code actually printing out anything from inside the function? It should be!"
def test_check_index_location(self): to_check = [[0, 0], [5, 5], [3, 0], [0, 3]] for point in to_check: student = Prob3.check_index_location(*point, Prob3.mine_locations) thissol = self.ml_sols[point[0]][point[1]] assert student == thissol, f"Should have returned {thissol} but instead returned {student} with inputs of check_index_location({*point, Prob3.mine_locations})."
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)
def test_count_mines_returns_correct_counts(self): to_check = [Prob3.mine_locations, self.alt_layout1, self.alt_layout2] sols = [self.ml_sols, self.alt1_sols, self.alt2_sols] for array, sol in zip(to_check, sols): student = Prob3.count_mines(array) assert student == sol, f"count_mines({array}) is giving {student} but it should be {sol}."
def test_all_evens(self, capsys): inputs = ['6', '-6', '18'] with mock.patch('builtins.input', side_effect=inputs): Prob3.big_odd_finder() cap = capsys.readouterr() assert cap.out == 'No odd numbers found.\n'
def test_multiples_of_six_or_seven(self, capsys): Prob3.print_multiples() captured = capsys.readouterr().out.rstrip() values = [int(n) for n in captured.split('\n')] for num in values: assert num % 6 == 0 or num % 7 == 0, f"The number {num} was printed to the screen but that is not divisible by either 6 or 7."
def test_two_odd(self, capsys): inputs = ['11', '7', '8'] with mock.patch('builtins.input', side_effect=inputs): Prob3.big_odd_finder() cap = capsys.readouterr() assert cap.out == '11\n'
def test_all_odds(self, capsys): inputs = ['3', '-7', '1'] with mock.patch('builtins.input', side_effect=inputs): Prob3.big_odd_finder() cap = capsys.readouterr() assert cap.out == '3\n'