#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Basic assertions are the simplest form of testing. They are native python, and are easily debuggable. """ from typing import List # %% testing with mere standard assert def sum_arr(x: List[float]) -> float: """ simple sum. If you want to debug these with a debugger, you can set a breakpoint within the function you want to test, or just step into the function in main. """ return sum(x) # These tests will crash if your program is not right # One of these is wrong; which one? # Put your tests in their own main (or their own file), # and run it occasionally, or automatically in gitlab-CI. if __name__ == "__main__": assert sum_arr([1, 2, 3]) == 6, "Should be 6" assert sum_arr([-1, -2, -2]) == -5, "Should be -5" # This test is wrong (the function is good): assert sum_arr([1, 2, 2]) == 6, "Should be 5"