@@ 633,6 633,38 @@ mod tests {
}
#[test]
+ fn test_verify_solution() {
+ let mut rng = rand::rng();
+ let rng = &mut rng;
+ let mut chromosome = NodePermutation::<Const<6>> {
+ permutation: SVector::from_vec(vec![0, 1, 2, 3, 4, 5])
+ };
+
+ for _ in 0..100 {
+ chromosome.permutation.as_mut_slice().shuffle(rng);
+ assert!(TSPInstance::verify_solution(&chromosome));
+ }
+
+ // Out of bounds
+ chromosome.permutation[0] = 6;
+ assert!(!TSPInstance::verify_solution(&chromosome));
+ chromosome.permutation[0] = 7;
+ assert!(!TSPInstance::verify_solution(&chromosome));
+ chromosome.permutation[0] = 8;
+ assert!(!TSPInstance::verify_solution(&chromosome));
+
+ // Repeating
+ chromosome.permutation[0] = 5;
+ chromosome.permutation[1] = 5;
+ assert!(!TSPInstance::verify_solution(&chromosome));
+
+ let chromosome = NodePermutation::<Const<6>> {
+ permutation: SVector::from_vec(vec![0, 1, 2, 3, 1, 5])
+ };
+ assert!(!TSPInstance::verify_solution(&chromosome));
+ }
+
+ #[test]
fn test_binary_string_representation() {
// x 0 1 2 3 4 5
// 0 0 0 0 0 0 0