-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_lotka_volterra.py
63 lines (56 loc) · 1.57 KB
/
test_lotka_volterra.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import unittest
from math_model import Lotka_Volterra
class LotkaVolterraTestCase(unittest.TestCase):
def test_lotka_volterra_initialization(self):
iv_x = 10
iv_y = 2
alpha = 2
beta = 1
dt = 0.01
time = 1000
L = Lotka_Volterra(iv_x, iv_y, alpha, beta, dt, time)
assert L.alpha == alpha
assert L.beta == beta
assert L.dt == dt
assert L.time == time
def test_logistic_sys(self):
iv_x = 10
iv_y = 2
alpha = 2
beta = 1
dt = 0.01
time = 1000
L = Lotka_Volterra(iv_x, iv_y, alpha, beta, dt, time)
L.initial_value(iv_x, iv_y)
L.logistic_sys()
assert L.x[0] == 10
assert L.y[0] == 2
def test_plots(self):
iv_x = 10
iv_y = 2
alpha = 2
beta = 1
dt = 0.01
time = 1000
L = Lotka_Volterra(iv_x, iv_y, alpha, beta, dt, time)
L.initial_value(iv_x, iv_y)
L.logistic_sys()
L.plot_system()
assert os.path.exists("./Dynamic Systems and Phase Plot.png")
def test_equilibrium(self):
iv_x = 10
iv_y = 2
alpha = 2
beta = 1
dt = 0.01
time = 1000
L = Lotka_Volterra(iv_x, iv_y, alpha, beta, dt, time)
L.initial_value(iv_x, iv_y)
L.logistic_sys()
equilibria = L.find_equilibrium(10)
assert type(equilibria) is list
assert len(equilibria) == 3
assert equilibria == [(0, 0), (1, 1), (2, 0)]
if __name__ == '__main__':
unittest.main()