-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_test_starter.py
More file actions
46 lines (35 loc) · 1.25 KB
/
unit_test_starter.py
File metadata and controls
46 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Notes on Unit Testing
# UNIT TEST - test if a function works on its own.
# INTEGRATION TEST - test if a function works with other functions (possibly in a main section of code)
# simple interest function
# simple interest formula is i = p * r * t
# i = interest
# p = principal
# r = rate of return
# t = time
# ...
# compound interest function
# when designing unit tests:
# - test more than one thing
# - test the upper and lower bounds
# - consider unexpected cases (negatives, types, etc.)
# NOTE: you may have to deal with the imprecision of floating point values when testing numbers, in which case you want to test if teh expected value is 'close enough'
# simple unit tests
print("Actual: ", simple_interest(100, .10, 2))
print("Expected: ", 20.0)
print()
result = simple_interest(5500, .07, 5)
print("Actual:", result)
print("Expected:", 1925.0)
print("Pass test?", result - 1925.0 < 0.001)
# compound interest unit tests
print()
result = compound_interest(1000, .10, 5, 4)
print("Actual:", result)
print("Expected:", 638.62)
print("Pass test?", result - 638.62 < 0.005)
print()
result = compound_interest(5000, .20, 4, 2)
print("Actual:", result)
print("Expected:", 5717.94)
print("Pass test?", result - 5717.94 < 0.005)