-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobo_jkr_adapters_test.cpp
180 lines (151 loc) · 4.32 KB
/
jobo_jkr_adapters_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "jobo_jkr_adapters.h"
#include <cassert>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <boost/test/unit_test.hpp>
#include "file_to_vector.h"
#include "is_regular_file.h"
#include "jkr_experiment.h"
#include "jobo_ancestry_graph.h"
#include "jobo_parameters.h"
#include "jobo_results.h"
#include "jobo_simulation.h"
#include "seperate_string.h"
// Boost.Test does not play well with -Weffc++
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
using namespace jobo;
//Short version, do not use
void delete_file(const std::string& filename)
{
assert(is_regular_file(filename));
std::remove(filename.c_str());
assert(!is_regular_file(filename));
}
BOOST_AUTO_TEST_CASE(test_jobo_jkr_adapters_test)
{
const parameters p = create_test_parameters_1();
jkr::do_experiment<
jobo::parameters,
jobo::simulation,
jobo::results,
jobo::ancestry_graph
>(p);
//Clean up
delete_file(get_ltt_plot_filename(p));
delete_file(get_nltt_plot_filename(p));
}
BOOST_AUTO_TEST_CASE(test_jobo_create_next_population)
{
const parameters p = create_test_parameters_1();
const simulation s = create_simulation(p);
std::mt19937 rng_engine(get_rng_seed(p));
const individuals next_population = create_next_population(s, rng_engine);
BOOST_CHECK_EQUAL(p.get_population_size(), static_cast<int>(next_population.size()));
}
BOOST_AUTO_TEST_CASE(test_jobo_create_ltt_plot_filename)
{
const parameters d = create_test_parameters_1();
const std::string f1 = get_ltt_plot_filename(d);
const std::string f2 = d.get_ltt_plot_filename_vi();
BOOST_CHECK_EQUAL(f1, f2);
}
BOOST_AUTO_TEST_CASE(test_jobo_jkr_adapters_save_ltt_plot_should_produce_a_file)
{
const parameters p = create_test_parameters_1();
//Ensure there is no output file yet
if (is_regular_file(get_ltt_plot_filename(p)))
{
delete_file(get_ltt_plot_filename(p));
}
assert(!is_regular_file(get_ltt_plot_filename(p)));
jkr::do_experiment<
jobo::parameters,
jobo::simulation,
jobo::results,
jobo::ancestry_graph
>(p);
BOOST_CHECK(is_regular_file(get_ltt_plot_filename(p)));
//Clean up
delete_file(get_ltt_plot_filename(p));
delete_file(get_nltt_plot_filename(p));
}
BOOST_AUTO_TEST_CASE(test_jobo_jkr_adapters_save_ltt_plot_should_produce_a_file_with_content)
{
const parameters p = create_test_parameters_1();
//Ensure there is no output file yet
if (is_regular_file(get_ltt_plot_filename(p)))
{
delete_file(get_ltt_plot_filename(p));
}
assert(!is_regular_file(get_ltt_plot_filename(p)));
jkr::do_experiment<
jobo::parameters,
jobo::simulation,
jobo::results,
jobo::ancestry_graph
>(p);
assert(is_regular_file(get_ltt_plot_filename(p)));
const std::vector<std::string> text = file_to_vector(get_ltt_plot_filename(p));
assert(text.size() == 1);
const std::vector<std::string> words = seperate_string(text[0], ',');
BOOST_CHECK_EQUAL(words.size(),p.get_generations());
//Clean up
delete_file(get_ltt_plot_filename(p));
delete_file(get_nltt_plot_filename(p));
}
BOOST_AUTO_TEST_CASE(jobo_population_becomes_inviable)
{
const int population_size{10};
const int seed{42};
const double mutation_rate{0.2};
const int n_generations{100};
const int n_loci{12};
const parameters p(
population_size,
seed,
mutation_rate,
n_generations,
n_loci
);
const auto f = [&p]() {
jkr::do_experiment<
jobo::parameters,
jobo::simulation,
jobo::results,
jobo::ancestry_graph
>(p);
};
simulation s(p);
BOOST_CHECK_THROW(f(), std::runtime_error);
}
BOOST_AUTO_TEST_CASE(jobo_simulation_gives_two_output_files)
{
const int population_size{100};
const int seed{42};
const double mutation_rate{0.1};
const int n_generations{100};
const int n_loci{20};
const parameters p(
population_size,
seed,
mutation_rate,
n_generations,
n_loci
);
jkr::do_experiment<
jobo::parameters,
jobo::simulation,
jobo::results,
jobo::ancestry_graph
>(p);
assert(get_ltt_plot_filename(p) != get_nltt_plot_filename(p));
BOOST_CHECK(is_regular_file(get_ltt_plot_filename(p)));
BOOST_CHECK(is_regular_file(get_nltt_plot_filename(p)));
//Clean up
delete_file(get_ltt_plot_filename(p));
delete_file(get_nltt_plot_filename(p));
}
#pragma GCC diagnostic pop