import final_22wi_solutions as f22wi def test_shared_values(): ''' Contains the tests in the problem definition. FEEL FREE TO ADD YOUR OWN. ''' # tuples of (given input, expected output) pairs test_cases = [ # Given Tests ([{1}, {1, 2}, {1, 2, 3}], {1}), ([], set()), ([{1, 2, 3}], {1, 2, 3}), # Some Additional Tests ([{1, 2, 3}, {2, 3}, {3}], {3}), ([{2, 6}, {2, 6}, {2}], {2}), ([{2, 6}, {7, 8}, {2}], set()), ([{2, 6, 3}, {7, 8}, {9, 10, 16}], set()), ([{1, 2, 3}, {2, 3}, {9, 100, 2, 3}], {2, 3}), ([{'one', 1, 'two', 2}, {'one', 1, 'three', 3}, {'one', 1}], {'one', 1}), ([{'abc', 'a', 'fed'}, {'def', 'abc'}, {'def', 'abc'}], {'abc'}), ([{-1000, 1000}, {-500, 1000}, {1000, -100000}], {1000}), ([{(0, 1), (1, 2), (2, 3), (6, 7)}, {(1, 2), (4, 5), (6, 7)}], {(1, 2), (6, 7)}), ([{1.2, 3.1415, 70.85, 2, "ten"}, {7.64, "ninety", "ten", 3.1415}], {3.1415, "ten"}), ] for input, expected in test_cases: actual = f22wi.shared_values(input) assert expected == actual, \ f'Failed: Expected {expected}, but received {actual}' def test_strongest_pokemon(): ''' Contains the tests in the problem definition. FEEL FREE TO ADD YOUR OWN. ''' test_cases = [ # -------- Test 1 -------- ([ {"name": "Pikachu", "strength": 40, "speed": 70, "defense": 5}, {"name": "Charizard", "strength": 120, "speed": 50, "defense": 80}, {"name": "Meowth", "strength": 30, "speed": 40, "defense": 10} ], { "strength": ("Charizard", 120), "speed": ("Pikachu", 70), "defense": ("Charizard", 80) }), # -------- Test 2 -------- ([ {"name": "Onix", "strength": 40, "speed": 70, "defense": 1000}, {"name": "Jigglypuff", "strength": 40, "speed": 70, "defense": 1000}, ], { "strength": ("Onix", 40), "speed": ("Onix", 70), "defense": ("Onix", 1000) }), # -------- Test 3 -------- ([ {"name": "Onix", "strength": 40, "speed": 70, "defense": 1000}, {"name": "Jigglypuff", "strength": 2, "speed": 90, "defense": 80}, ], { "strength": ("Onix", 40), "speed": ("Jigglypuff", 90), "defense": ("Onix", 1000) }), # -------- Test 4 -------- ([ {"name": "Magikarp", "strength": -5, "speed": -7, "defense": -8} ], { "strength": ("Magikarp", -5), "speed": ("Magikarp", -7), "defense": ("Magikarp", -8) }), ] for input, expected in test_cases: actual = f22wi.strongest_pokemon(input) assert expected == actual, \ f'Failed: Expected {expected}, but received {actual}' def test_best_veggie_value(): ''' Contains the tests in the problem definition. FEEL FREE TO ADD YOUR OWN. ''' example_market = { "Paul's Produce": { "bulk_discount_quantity": 10, "bulk_discount_percent": 0.15, "bananas": 1.25, "carrots": 3.25, "potatoes": 80.0 }, "Gretchen's Groceries": { "bulk_discount_quantity": 15, "bulk_discount_percent": 0.30, "bananas": 1.05, "carrots": 4.0 }, } example_market_2 = { "Paul's Produce": { "bulk_discount_quantity": 10, "bulk_discount_percent": 0.75, "bananas": 1.25, "carrots": 3.25, "potatoes": 80.0, }, "Gretchen's Groceries": { "bulk_discount_quantity": 15, "bulk_discount_percent": 0.30, "bananas": 1.05, "carrots": 4.0, }, } example_market_3 = { "Paul's Produce": { "bulk_discount_quantity": 10, "bulk_discount_percent": 0.75, }, "Gretchen's Groceries": { "bulk_discount_quantity": 15, "bulk_discount_percent": 0.30, }, } example_quantities = { "bananas": 10, "carrots": 50, "potatoes": 2 } example_quantities_2 = { "bananas": 10, "carrots": 10, "potatoes": 50, } example_quantities_3 = { "bananas": 9, } expected_3 = { "Gretchen's Groceries": ['bananas'] } expected = { "Gretchen's Groceries": ["bananas"], "Paul's Produce": ["carrots", "potatoes"] } actual = f22wi.best_veggie_value(example_market, example_quantities) assert expected == actual, \ f'Failed: Expected {expected}, but received {actual}' actual = f22wi.best_veggie_value(example_market_3, example_quantities_2) assert {} == actual, \ f'Failed: Expected {expected}, but received {actual}' actual = f22wi.best_veggie_value(example_market_2, {"toffee": 9}) assert {} == actual, \ f'Failed: Expected {expected}, but received {actual}' actual = f22wi.best_veggie_value(example_market_2, example_quantities_3) assert expected_3 == actual, \ f'Failed: Expected {expected}, but received {actual}' def main(): test_shared_values() test_strongest_pokemon() test_best_veggie_value() if __name__ == '__main__': main()