@@ 1,4 1,5 @@
use std::str::FromStr;
+#[cfg(test)]
use crate::test_infra::{load_test_file, DataArrOfReals};
use rand::Rng;
@@ 167,6 168,7 @@ fn test_binary_string_to_real_single() {
);
}
+#[cfg(test)]
fn test_binary_string_to_real(file_name: &str, bounds: Vec<Bounds>) {
let data = load_test_file::<i8, DataArrOfReals>(file_name);
@@ 189,7 191,7 @@ fn test_binary_string_to_real(file_name: &str, bounds: Vec<Bounds>) {
}
#[test]
-fn test_binary_string_to_real_1D_1() {
+fn test_binary_string_to_real_1d_1() {
test_binary_string_to_real(
"tests/Bin2Real_1D_1.txt",
vec![Bounds::new(0.0, 1.0)]
@@ 197,7 199,7 @@ fn test_binary_string_to_real_1D_1() {
}
#[test]
-fn test_binary_string_to_real_1D_2() {
+fn test_binary_string_to_real_1d_2() {
test_binary_string_to_real(
"tests/Bin2Real_1D_2.txt",
vec![Bounds::new(0.0, 4095.0)]
@@ 205,7 207,7 @@ fn test_binary_string_to_real_1D_2() {
}
#[test]
-fn test_binary_string_to_real_1D_3() {
+fn test_binary_string_to_real_1d_3() {
test_binary_string_to_real(
"tests/Bin2Real_1D_3.txt",
vec![Bounds::new(-5.0, 5.0)]
@@ 213,7 215,7 @@ fn test_binary_string_to_real_1D_3() {
}
#[test]
-fn test_binary_string_to_real_2D_1() {
+fn test_binary_string_to_real_2d_1() {
test_binary_string_to_real(
"tests/Bin2Real_2D_1.txt",
vec![Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0)]
@@ 221,7 223,7 @@ fn test_binary_string_to_real_2D_1() {
}
#[test]
-fn test_binary_string_to_real_2D_2() {
+fn test_binary_string_to_real_2d_2() {
test_binary_string_to_real(
"tests/Bin2Real_2D_2.txt",
vec![Bounds::new(0.0, 63.0), Bounds::new(-32.0, 31.0)]
@@ 229,7 231,7 @@ fn test_binary_string_to_real_2D_2() {
}
#[test]
-fn test_binary_string_to_real_2D_3() {
+fn test_binary_string_to_real_2d_3() {
test_binary_string_to_real(
"tests/Bin2Real_2D_3.txt",
vec![Bounds::new(-5.0, 5.0), Bounds::new(0.0, 10.0)]
@@ 237,7 239,7 @@ fn test_binary_string_to_real_2D_3() {
}
#[test]
-fn test_binary_string_to_real_3D_1() {
+fn test_binary_string_to_real_3d_1() {
test_binary_string_to_real(
"tests/Bin2Real_3D_1.txt",
vec![Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0)]
@@ 245,7 247,7 @@ fn test_binary_string_to_real_3D_1() {
}
#[test]
-fn test_binary_string_to_real_3D_2() {
+fn test_binary_string_to_real_3d_2() {
test_binary_string_to_real(
"tests/Bin2Real_3D_2.txt",
vec![Bounds::new(0.0, 15.0), Bounds::new(-8.0, 7.0), Bounds::new(-8.0, 8.0)]
@@ 253,7 255,7 @@ fn test_binary_string_to_real_3D_2() {
}
#[test]
-fn test_binary_string_to_real_4D_1() {
+fn test_binary_string_to_real_4d_1() {
test_binary_string_to_real(
"tests/Bin2Real_4D_1.txt",
vec![Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0)]
@@ 261,7 263,7 @@ fn test_binary_string_to_real_4D_1() {
}
#[test]
-fn test_binary_string_to_real_4D_2() {
+fn test_binary_string_to_real_4d_2() {
test_binary_string_to_real(
"tests/Bin2Real_4D_2.txt",
vec![Bounds::new(0.0, 7.0), Bounds::new(-4.0, 3.0), Bounds::new(-4.0, 4.0), Bounds::new(-8.0, 0.0)]
@@ 269,7 271,7 @@ fn test_binary_string_to_real_4D_2() {
}
#[test]
-fn test_binary_string_to_real_6D_1() {
+fn test_binary_string_to_real_6d_1() {
test_binary_string_to_real(
"tests/Bin2Real_6D_1.txt",
vec![Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0), Bounds::new(0.0, 1.0)]
@@ 277,7 279,7 @@ fn test_binary_string_to_real_6D_1() {
}
#[test]
-fn test_binary_string_to_real_6D_2() {
+fn test_binary_string_to_real_6d_2() {
test_binary_string_to_real(
"tests/Bin2Real_6D_2.txt",
(0..=5).map(|x| Bounds::new(x as f64, (2 * (x + 1)) as f64)).collect::<Vec<_>>()
@@ 1,19 1,21 @@
use std::convert::Infallible;
-use crate::{binary_string::BinaryString, test_infra::load_test_file};
+#[cfg(test)]
+use crate::test_infra::load_test_file;
+use crate::binary_string::BinaryString;
use super::FitnessFunction;
pub struct LABS;
impl LABS {
- fn new() -> Self {
+ pub fn new() -> Self {
LABS
}
- fn Ck(k: usize, S: &Vec<i32>) -> i32 {
- let D = S.len();
- S.iter()
- .take(D - k)
- .zip(S.iter().skip(k))
+ fn ck(k: usize, s: &Vec<i32>) -> i32 {
+ let d = s.len();
+ s.iter()
+ .take(d - k)
+ .zip(s.iter().skip(k))
.map(|(x, y)| x * y)
.sum()
}
@@ 25,20 27,20 @@ impl FitnessFunction for LABS {
type Err = Infallible;
fn fit(self: &Self, chromosome: &BinaryString) -> Result<i32, Infallible> {
- let S: Vec<i32> = chromosome
+ let s: Vec<i32> = chromosome
.into_iter()
.map(|c| (*c as i32) * 2 - 1)
.collect();
- let D = S.len();
+ let d = s.len();
- Ok((1..=D-1)
- .map(|k| LABS::Ck(k, &S).pow(2))
+ Ok((1..=d-1)
+ .map(|k| LABS::ck(k, &s).pow(2))
.sum())
}
}
#[test]
-fn test_LABS() {
+fn test_labs() {
let data = load_test_file::<i8, i32>("tests/labs.txt");
for test in data {
@@ 1,10 1,23 @@
-use crate::binary_string::{BinaryString, Bounds};
+use crate::binary_string::BinaryString;
+#[cfg(test)]
+use crate::binary_string::Bounds;
+#[cfg(test)]
use crate::fitness::one_max::OneMax;
+#[cfg(test)]
use crate::fitness::sphere::Sphere;
-use crate::terminating::{AndTerminatingConditions, EqualTerminatingCondition, NoBetterForCyclesTerminatingCondition, TerminatingCondition};
-use crate::perturbation::{BinaryStringBitPerturbation, PerturbationOperator};
-use crate::comparison::{BetterThanOperator, MinimizingOperator};
-use crate::fitness::{FitnessFunction, BinaryFitnessWrapper};
+#[cfg(test)]
+use crate::terminating::{AndTerminatingConditions, EqualTerminatingCondition, NoBetterForCyclesTerminatingCondition};
+#[cfg(test)]
+use crate::perturbation::BinaryStringBitPerturbation;
+#[cfg(test)]
+use crate::comparison:: MinimizingOperator;
+#[cfg(test)]
+use crate::fitness::BinaryFitnessWrapper;
+
+use crate::fitness::FitnessFunction;
+use crate::terminating::TerminatingCondition;
+use crate::perturbation::PerturbationOperator;
+use crate::comparison::BetterThanOperator;
// Functions
#[derive(Debug, Clone, PartialEq)]