-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
129 lines (117 loc) · 4.66 KB
/
test.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "population.hpp"
// Verifica delle condizioni beta, gamma, sigma e mu
TEST_CASE("beta = 0") { // non ci si infetta
Population pop{0, 0.5, 0.5, 0.3, 100, 100}; // beta, gamma, sigma, mu, N, T
State initial_state{95, 0, 5, 0, 0}; // S, E, I, R, D
auto dati = pop.evolve(initial_state);
CHECK(pop.peak(dati) == 2);
CHECK(initial_state.S == 95);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("gamma = 0") { // non si può guarire/morire
Population pop{0.5, 0, 0.9, 0.7, 100, 100};
State initial_state{95, 0, 5, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.R == 0);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE(
"sigma = 0") { // tasso di latenza nullo, tempo di incubazione infinito
Population pop{0.5, 0.2, 0, 0.9, 100, 100};
State initial_state{95, 5, 0, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.R == 0);
CHECK(initial_state.D == 0);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("mu = 1") { // non si può sopravvivere
Population pop{0.8, 0.3, 0.3, 1, 100, 100};
State initial_state{95, 0, 5, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.R == 0);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("mu = 0") { // non si può morire, la malattia non genera sintomi
// gravi
Population pop{0.8, 0.3, 0.3, 0, 100, 100};
State initial_state{95, 0, 5, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.D == 0);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("favorevole") {
Population pop{0.2, 0.9, 0.9, 0.1, 100, 2000};
State initial_state{90, 0, 10, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.I < 0.5); // verifica che finisce la pandemia
CHECK(initial_state.S > (initial_state.R + initial_state.D));
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("favorevole ma pandemia ancora in corso") {
Population pop{0.2, 0.9, 0.9, 0.1, 100, 30};
State initial_state{90, 0, 10, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.I != 0);
CHECK(initial_state.S > initial_state.R);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("sfavorevole") {
Population pop{0.9, 0.2, 0.2, 0.9, 100, 100};
State initial_state{60, 0, 40, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.S < 0.5);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(100));
}
TEST_CASE("alta popolazione") {
Population pop{0.78, 0.27, 0.5, 0.5, 10000, 100};
State initial_state{9500, 0, 500, 0, 0};
pop.evolve(initial_state);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(10000));
}
TEST_CASE(
"La pandemia non comincia") { // non ho un picco. beta/gamma < 1, S circa N
Population pop{0.3, 0.5, 0.5, 0.5, 10000, 100};
State initial_state{9999, 0, 1, 0, 0};
auto dati = pop.evolve(initial_state);
CHECK(dati.size() <= 3);
}
TEST_CASE("Ho un picco") { // Dati COVID per emilia-romagna
Population pop{0.35, 0.14, 0.19, 0.009, 5.4e+07, 365};
State initial_state{53999980, 0, 20, 0, 0};
auto dati = pop.evolve(initial_state);
CHECK(pop.peak(dati) == 166);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(5.4e+07));
}
TEST_CASE("morti e rimossi decrescenti") { // controlla che morti e rimossi non
// diminuiscano
Population pop{0.78, 0.27, 0.5, 0.5, 10000, 100};
State initial_state{9500, 0, 400, 50, 50};
pop.evolve(initial_state);
CHECK(initial_state.D > 50);
CHECK(initial_state.R > 50);
CHECK(initial_state.S + initial_state.I + initial_state.R + initial_state.E +
initial_state.D ==
doctest::Approx(10000));
}