1 use crate::algorithms::SettingFitnessDistanceErrorKind; 2 3 use super::*; 4 5 mod basic { 6 use super::*; 7 8 mod zero_distance { 9 use super::*; 10 11 generate_value_constraint_tests!( 12 tests: [ 13 { 14 name: string_setting, 15 settings: String => &[Some("foo".to_owned())], 16 }, 17 ], 18 constraints: String => &[ 19 ResolvedValueSequenceConstraint { 20 exact: None, 21 ideal: None, 22 }, 23 ResolvedValueSequenceConstraint { 24 exact: None, 25 ideal: Some(vec!["foo".to_owned()]), 26 }, 27 ], 28 expected: Ok(0.0) 29 ); 30 } 31 32 mod one_distance { 33 use super::*; 34 35 generate_value_constraint_tests!( 36 tests: [ 37 { 38 name: string_setting, 39 settings: String => &[None, Some("bar".to_owned())], 40 }, 41 ], 42 constraints: String => &[ResolvedValueSequenceConstraint { 43 exact: None, 44 ideal: Some(vec!["foo".to_owned()]), 45 }], 46 expected: Ok(1.0) 47 ); 48 } 49 } 50 51 mod required { 52 use super::*; 53 54 mod zero_distance { 55 use super::*; 56 57 // A constraint that does apply for a type of setting, 58 // is expected to return a fitness distance of `0`, 59 // iff the setting matches the constraint: 60 generate_value_constraint_tests!( 61 tests: [ 62 { 63 name: string_setting, 64 settings: String => &[Some("foo".to_owned())], 65 }, 66 ], 67 constraints: String => &[ResolvedValueSequenceConstraint { 68 exact: Some(vec!["foo".to_owned()]), 69 ideal: None, 70 }], 71 expected: Ok(0.0) 72 ); 73 } 74 75 mod inf_distance { 76 use super::*; 77 78 mod missing { 79 use super::*; 80 81 generate_value_constraint_tests!( 82 tests: [ 83 { 84 name: string_setting, 85 settings: String => &[None], 86 }, 87 ], 88 constraints: String => &[ 89 ResolvedValueSequenceConstraint { 90 exact: Some(vec!["foo".to_owned(), "bar".to_owned(), "baz".to_owned()]), 91 ideal: None, 92 }, 93 ResolvedValueSequenceConstraint { 94 exact: Some(vec!["foo".to_owned(), "bar".to_owned(), "baz".to_owned()]), 95 ideal: Some(vec!["foo".to_owned()]), 96 }, 97 ], 98 expected: Err(SettingFitnessDistanceError { 99 kind: SettingFitnessDistanceErrorKind::Missing, 100 constraint: "(x == [\"foo\", \"bar\", \"baz\"])".to_owned(), 101 setting: None, 102 }) 103 ); 104 } 105 106 mod mismatch { 107 use super::*; 108 109 generate_value_constraint_tests!( 110 tests: [ 111 { 112 name: string_setting, 113 settings: String => &[Some("blee".to_owned())], 114 }, 115 ], 116 constraints: String => &[ 117 ResolvedValueSequenceConstraint { 118 exact: Some(vec!["foo".to_owned(), "bar".to_owned(), "baz".to_owned()]), 119 ideal: None, 120 }, 121 ResolvedValueSequenceConstraint { 122 exact: Some(vec!["foo".to_owned(), "bar".to_owned(), "baz".to_owned()]), 123 ideal: Some(vec!["foo".to_owned()]), 124 }, 125 ], 126 expected: Err(SettingFitnessDistanceError { 127 kind: SettingFitnessDistanceErrorKind::Mismatch, 128 constraint: "(x == [\"foo\", \"bar\", \"baz\"])".to_owned(), 129 setting: Some("\"blee\"".to_owned()), 130 }) 131 ); 132 } 133 } 134 } 135