Skip to content

Commit e7380ba

Browse files
committed
Add integration testing for default flags
1 parent 566770e commit e7380ba

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

src/core/haplotype.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ use super::fitness::FitnessProvider;
3535
pub static N_FITNESS_TABLES: OnceLock<usize> = OnceLock::new();
3636

3737
pub fn set_number_of_fitness_tables(value: usize) -> Result<(), usize> {
38+
if N_FITNESS_TABLES.get().is_some() {
39+
eprintln!("Trying to set `N_FITNESS_TABLES`, which has already been set.");
40+
}
3841
N_FITNESS_TABLES.set(value)
3942
}
4043

4144
fn make_fitness_cache() -> Vec<OnceLock<f64>> {
45+
// warn if the number of fitness providers has not been explicitly set at runtime
46+
if N_FITNESS_TABLES.get().is_none() {
47+
eprintln!("`N_FITNESS_TABLES` is not set, using default value of 1.");
48+
}
4249
std::iter::repeat_with(OnceLock::new)
4350
.take(*N_FITNESS_TABLES.get_or_init(|| 1))
4451
.collect()

src/main.rs

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,129 @@ use virolution::args::Args;
1010
use virolution::runner::Runner;
1111

1212
fn main() {
13+
let args = Args::parse();
14+
1315
if cfg!(feature = "parallel") {
1416
println!("Running in parallel mode.");
1517
} else {
1618
println!("Running in serial mode.");
1719
}
1820

19-
let args = Args::parse();
20-
2121
let mut runner = Runner::new(args).unwrap_or_else(|err| {
2222
eprintln!("Unable to init simulation: {err}.");
2323
std::process::exit(1);
2424
});
2525

2626
runner.start();
2727
}
28+
29+
/// TODO: These tests should run for multiple feature flags
30+
#[cfg(test)]
31+
mod tests {
32+
use std::process::Command;
33+
34+
struct Cleanup<'a> {
35+
dir: &'a str,
36+
}
37+
38+
impl<'a> Drop for Cleanup<'a> {
39+
fn drop(&mut self) {
40+
std::fs::remove_dir_all(self.dir).unwrap();
41+
}
42+
}
43+
44+
/// Test invocation of program for singlehost setup with 1 generation
45+
#[test]
46+
fn test_singlehost() {
47+
let tmp_dir = ".tmp_singlehost";
48+
let _cleanup = Cleanup { dir: tmp_dir };
49+
let output = Command::new("cargo")
50+
.args([
51+
"run",
52+
"--",
53+
"--disable-progress-bar",
54+
"--settings",
55+
"test/singlehost/singlehost.yaml",
56+
"--sequence",
57+
"test/singlehost/ref.fasta",
58+
"--generations",
59+
"1",
60+
"--n-compartments",
61+
"2",
62+
"--outdir",
63+
tmp_dir,
64+
])
65+
.output()
66+
.expect("Failed to execute command");
67+
68+
assert!(output.status.success());
69+
70+
// Check if output files are created
71+
assert!(std::path::Path::new(&format!("{}/fitness_table_0.npy", tmp_dir)).exists());
72+
assert!(std::path::Path::new(&format!("{}/virolution.log", tmp_dir)).exists());
73+
}
74+
75+
/// Test invocation of program for multihost setup with 1 generation
76+
#[test]
77+
fn test_multihost() {
78+
let tmp_dir = ".tmp_multihost";
79+
let _cleanup = Cleanup { dir: tmp_dir };
80+
81+
let output = Command::new("cargo")
82+
.args([
83+
"run",
84+
"--",
85+
"--disable-progress-bar",
86+
"--settings",
87+
"test/multihost/multihost.yaml",
88+
"--sequence",
89+
"test/multihost/ref.fasta",
90+
"--generations",
91+
"1",
92+
"--n-compartments",
93+
"2",
94+
"--outdir",
95+
tmp_dir,
96+
])
97+
.output()
98+
.expect("Failed to execute command");
99+
100+
assert!(output.status.success());
101+
102+
// Check if output files are created
103+
assert!(std::path::Path::new(&format!("{}/fitness_table_0.npy", tmp_dir)).exists());
104+
assert!(std::path::Path::new(&format!("{}/fitness_table_1.npy", tmp_dir)).exists());
105+
assert!(std::path::Path::new(&format!("{}/virolution.log", tmp_dir)).exists());
106+
}
107+
108+
/// Test invocation of program for epistasis setup with 1 generation
109+
#[test]
110+
fn test_epistasis() {
111+
let tmp_dir = ".tmp_epistasis";
112+
let output = Command::new("cargo")
113+
.args([
114+
"run",
115+
"--",
116+
"--disable-progress-bar",
117+
"--settings",
118+
"test/epistasis/epistasis.yaml",
119+
"--sequence",
120+
"test/epistasis/ref.fasta",
121+
"--generations",
122+
"1",
123+
"--n-compartments",
124+
"2",
125+
"--outdir",
126+
tmp_dir,
127+
])
128+
.output()
129+
.expect("Failed to execute command");
130+
131+
assert!(output.status.success());
132+
133+
// Check if output files are created
134+
assert!(std::path::Path::new(&format!("{}/fitness_table_0.npy", tmp_dir)).exists());
135+
assert!(std::path::Path::new(&format!("{}/epistasis_table_0.npy", tmp_dir)).exists());
136+
assert!(std::path::Path::new(&format!("{}/virolution.log", tmp_dir)).exists());
137+
}
138+
}

src/simulation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ impl Simulation for BasicSimulation {
194194
self.population = population;
195195
}
196196

197+
/// Set the parameters for the simulation
198+
///
199+
/// WARNING: Currently this method does only reinitialize part of the simulation. Do not use
200+
/// without revising its implementation.
197201
fn set_parameters(&mut self, parameters: Parameters) {
198202
self.parameters = parameters;
199203
self.mutation_sampler = Binomial::new(

0 commit comments

Comments
 (0)