use num::{Float, FromPrimitive};
pub fn mccorminck<T: Float + FromPrimitive>(param: &[T]) -> T {
assert!(param.len() == 2);
let (x1, x2) = (param[0], param[1]);
(x1 + x2).sin() + (x1 - x2).powi(2) - T::from_f64(1.5).unwrap() * x1
+ T::from_f64(2.5).unwrap() * x2
+ T::from_f64(1.0).unwrap()
}
mod tests {
#[test]
fn test_mccorminck_optimum() {
assert!(
(::mccorminck(&[-0.54719_f32, -1.54719_f32]) + 1.9132228_f32).abs()
< ::std::f32::EPSILON
);
}
#[test]
#[should_panic]
fn test_mccorminck_param_length() {
::mccorminck(&[0.0_f32, -1.0_f32, 0.1_f32]);
}
}