Monkey trouble
#
# monkey_trouble.py
#
# This exercise is from CodingBat by Nick Parlante
# https://codingbat.com/prob/p181646
# We have two monkeys, a and b, and the parameters aSmile and
# bSmile indicate if each is smiling. We are in trouble if they are
# both smiling or if neither of them is smiling. Return true if we
# are in trouble.
# monkey_trouble() is the function you want to test.
def monkey_trouble(aSmile, bSmile):
return aSmile == bSmile
# test_monkey_trouble() is the unit test function, with arguments
# for given input and the expected output.
def test_monkey_trouble(aSmile, bSmile, expected):
= monkey_trouble(aSmile, bSmile)
result
print(f"aSmile: {aSmile}, bSmile: {bSmile}, "
f"expected: {expected}, result: {result}")
if result == expected:
print("PASSED")
else:
print("FAILED")
# We run several tests, varying the input parameters and checking
# that we get the output we expect from monkey_trouble().
True, True, True)
test_monkey_trouble(False, False, True)
test_monkey_trouble(True, False, False)
test_monkey_trouble(
# Named arguments can help the readability of your code.
=False, bSmile=True, expected=False)
test_monkey_trouble(aSmile
Output:
aSmile: True, bSmile: True, expected: True, result: True
PASSED
aSmile: False, bSmile: False, expected: True, result: True
PASSED
aSmile: True, bSmile: False, expected: False, result: False
PASSED
aSmile: False, bSmile: True, expected: False, result: False
PASSED