Skip to content

Instantly share code, notes, and snippets.

@jamesfe
Created June 8, 2021 00:15
Show Gist options
  • Select an option

  • Save jamesfe/18b8f3d20789d561a919d4723d9e62bc to your computer and use it in GitHub Desktop.

Select an option

Save jamesfe/18b8f3d20789d561a919d4723d9e62bc to your computer and use it in GitHub Desktop.
def good_stick_three_character_strings_together(x, y):
"""Should return x, a space, then y; for example:
x = dog
y = cat
returns "dog cat"
"""
assert type(x) == str and type(y) == str
assert len(x) == 3 and len(y) == 3
return x + ' ' + y
def bad_stick_three_character_strings_together(x, y):
"""Should return x, a space, then y; for example:
x = dog
y = cat
returns "dog cat"
"""
assert len(x) == 3 and len(y) == 3
assert type(x) == str and type(y) == str
return x + ' ' + y
print('some cases that work')
print(good_stick_three_character_strings_together('dog', 'cat'))
print(bad_stick_three_character_strings_together('dog', 'cat'))
print('cases that will break; we want an AssertionError, not a TypeError')
# this first one gives us a nice error
try:
print(good_stick_three_character_strings_together(99, 'cat'))
except AssertionError:
print('got an assertion error')
# this one gives us an ugly error
try:
print(bad_stick_three_character_strings_together(99, 'cat'))
except AssertionError:
print('got an assertion error')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment