Skip to content

Instantly share code, notes, and snippets.

@yuvipanda
Created January 24, 2018 08:12
Show Gist options
  • Save yuvipanda/1eb7c39e2db93058449c5410cb661e36 to your computer and use it in GitHub Desktop.
Save yuvipanda/1eb7c39e2db93058449c5410cb661e36 to your computer and use it in GitHub Desktop.
"""
The tests will be checked in order, and the first one to fail will have
its docstring (in markdown) shown to the user.
The user submitted notebook has already been executed, and the contents of
the global namespace there is passed in as `ns` to each function.
You can use `@scored` decorator to specify that if a student gets all the
tests right, up to that test, they can be awarded that score.
You can test this locally by running:
py.test <name-of-this-file> --notebook <path-to-notebook>.ipynb
"""
QUESTION = "q1"
def test_is_defined(ns):
"""
It looks like you have not defined a function called is_odd!
You can go to [somelink](https://google.com) to learn how to define functions if you need a refresher!",
"""
assert 'is_odd' in ns and callable(ns['is_odd'])
def test_returns_bool(ns):
"""
Your function should return only a boolean True or False based on number input
"""
assert type(ns['is_odd'](3)) is bool
def test_3_odd(ns):
"""
Your function thinks 3 is not an odd number, but it definitely yes! Check if you are using the modulus operator correctly?
"""
assert ns['is_odd'](3) == True
@scored(score=10)
def test_a_bunch(ns):
is_odd = ns['is_odd']
for i in range(1000):
assert is_odd(i) == (i % 2 != 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment