ashish chaudhary
Python & AIMy function runs, but I am not sure whether it returns the correct answer. What is a simple first test?
def add(a, b):
return a - b
assert add(2, 3) == 5
CookieSensei starter Q&A · example discussion.
Loading…
My function runs, but I am not sure whether it returns the correct answer. What is a simple first test?
def add(a, b):
return a - b
assert add(2, 3) == 5
CookieSensei starter Q&A · example discussion.
Write down a few inputs and the results you expect before running the function. Here, an assertion checks that adding 2 and 3 gives 5. Also check cases such as zero or a negative number. If an assertion fails, inspect the function before changing the expected result. This is a small learning example; larger projects can use a test framework.
def add(a, b):
return a + b
assert add(2, 3) == 5
assert add(0, 0) == 0
assert add(-1, 1) == 0
print("3 checks passed")
CookieSensei starter Q&A · example discussion.