https://medium.com/indonesia-sehat-mental/test-driven-development-is-it-really-necessary-5a527874b190
def sum(a, b):
return a + b
def test__sum(a, b):
assert sum(1, 1) == 2
Source
Test
You should aim for 100% test coverage
Every single function must have a unit test.
If you try to test your code now, it's going to be hard
def run_simulation():
data = pd.read_csv("file.csv")
# do some data manipulation...
simulator = Simulator()...
# setup simulator ...
results = simulator.run()
# do some plotting ...
Common bad function
Each function does one thing only
Preferably no side effects
def does_thing_1():
pass
def does_thing_2():
pass
def does_thing_3():
pass
def do_all_things():
thing_1 = does_thing_1()
thing_2 = does_thing_2()
thing_3 = does_thing_3()
return ...
def test__does_thing_1():
pass
def test__does_thing_2():
pass
def test__does_thing_3():
pass
def test__do_all_things():
thing_1 = does_thing_1()
thing_2 = does_thing_2()
thing_3 = does_thing_3()
return ...
Source
Test
Very important:
TEST NEEDS TO BE WRITTEN FIRST!
This ensures our function can be tested
+
our code is easier to use by design
https://medium.com/indonesia-sehat-mental/test-driven-development-is-it-really-necessary-5a527874b190
icemobile.com/test-driven-development
pytest
This should only contain source files.
Not scripts, example runs, data, etc.
This should only contain source files.
Not scripts, example runs, data, etc.
(or how to add new features to the code)