@ -1,74 +1,36 @@
#[ cfg(test) ]
#[ cfg(test) ]
mod tests {
mod tests {
use dubins_path ::* ;
use dubins_path ::* ;
use float_cmp ::approx_eq ;
const ERROR : f64 = 0.000000000000001 ;
fn circle_in_error_margin (
fn circle_in_error_margin (
result : CircleVector ,
result : CircleVector ,
expected_result : CircleVector ,
expected_result : CircleVector ,
) -> Result < ( ) , ( ) > {
) -> Result < ( ) , ( ) > {
if result . center . x - expected_result . center . x > ERROR {
assert! ( approx_eq ! ( f64 , result . center . x , expected_result . center . x ) ) ;
return Err ( ( ) ) ;
assert! ( approx_eq ! ( f64 , result . center . x , expected_result . center . x ) ) ;
}
assert! ( approx_eq ! ( f64 , result . center . y , expected_result . center . y ) ) ;
if result . center . x - expected_result . center . x < - ERROR {
assert! ( approx_eq ! ( f64 , result . center . y , expected_result . center . y ) ) ;
return Err ( ( ) ) ;
assert! ( approx_eq ! ( f64 , result . radius , expected_result . radius ) ) ;
}
assert! ( approx_eq ! ( f64 , result . radius , expected_result . radius ) ) ;
if result . center . y - expected_result . center . y > ERROR {
assert! ( approx_eq ! ( f64 , result . angle . radians , expected_result . angle . radians ) | |
return Err ( ( ) ) ;
approx_eq ! ( f64 , result . angle . signed ( ) . radians , expected_result . angle . signed ( ) . radians ) ) ;
}
assert! ( approx_eq ! ( f64 , result . angle . radians , expected_result . angle . radians ) | |
if result . center . y - expected_result . center . y < - ERROR {
approx_eq ! ( f64 , result . angle . signed ( ) . radians , expected_result . angle . signed ( ) . radians ) ) ;
return Err ( ( ) ) ;
}
if result . radius - expected_result . radius > ERROR {
return Err ( ( ) ) ;
}
if result . radius - expected_result . radius < - ERROR {
return Err ( ( ) ) ;
}
if result . angle . radians - expected_result . angle . radians > ERROR
& & result . angle . signed ( ) . radians - expected_result . angle . signed ( ) . radians > ERROR
{
return Err ( ( ) ) ;
}
if result . angle . radians - expected_result . angle . radians < - ERROR
& & result . angle . signed ( ) . radians - expected_result . angle . signed ( ) . radians < - ERROR
{
return Err ( ( ) ) ;
}
Ok ( ( ) )
Ok ( ( ) )
}
}
fn vector_in_error_margin ( result : Vector , expected_result : Vector ) -> Result < ( ) , ( ) > {
fn vector_in_error_margin ( result : Vector , expected_result : Vector ) -> Result < ( ) , ( ) > {
if result . origin . x - expected_result . origin . x > ERROR {
assert! ( approx_eq ! ( f64 , result . origin . x , expected_result . origin . x ) ) ;
return Err ( ( ) ) ;
assert! ( approx_eq ! ( f64 , result . origin . x , expected_result . origin . x ) ) ;
}
assert! ( approx_eq ! ( f64 , result . origin . y , expected_result . origin . y ) ) ;
if result . origin . x - expected_result . origin . x < - ERROR {
assert! ( approx_eq ! ( f64 , result . origin . y , expected_result . origin . y ) ) ;
return Err ( ( ) ) ;
assert! ( approx_eq ! ( f64 , result . angle . radians , expected_result . angle . radians ) | |
}
approx_eq ! ( f64 , result . angle . signed ( ) . radians , expected_result . angle . signed ( ) . radians ) ) ;
if result . origin . y - expected_result . origin . y > ERROR {
assert! ( approx_eq ! ( f64 , result . angle . radians , expected_result . angle . radians ) | |
return Err ( ( ) ) ;
approx_eq ! ( f64 , result . angle . signed ( ) . radians , expected_result . angle . signed ( ) . radians ) ) ;
}
assert! ( approx_eq ! ( f64 , result . magnitude , expected_result . magnitude ) ) ;
if result . origin . y - expected_result . origin . y < - ERROR {
assert! ( approx_eq ! ( f64 , result . magnitude , expected_result . magnitude ) ) ;
return Err ( ( ) ) ;
}
if result . angle . radians - expected_result . angle . radians > ERROR
| | result . angle . signed ( ) . radians - expected_result . angle . signed ( ) . radians > ERROR
{
return Err ( ( ) ) ;
}
if result . angle . radians - expected_result . angle . radians < - ERROR
| | result . angle . signed ( ) . radians - expected_result . angle . signed ( ) . radians < - ERROR
{
return Err ( ( ) ) ;
}
if result . magnitude - expected_result . magnitude > ERROR {
return Err ( ( ) ) ;
}
if result . magnitude - expected_result . magnitude < - ERROR {
return Err ( ( ) ) ;
}
Ok ( ( ) )
Ok ( ( ) )
}
}