From 8f95ed8c9f172f381f137ca11b597bc9d6f4e2f7 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 7 Feb 2023 21:43:35 -0700 Subject: [PATCH] test: add test for NetworkCoordinate::estimate_rtt Signed-off-by: Stephen Waits --- src/network_coordinate.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/network_coordinate.rs b/src/network_coordinate.rs index 12798c3..47c76c2 100644 --- a/src/network_coordinate.rs +++ b/src/network_coordinate.rs @@ -258,8 +258,8 @@ mod tests { // verify the initial error let error = - (slc.error.powf(2.0) + nyc.error.powf(2.0) + lax.error.powf(2.0) + mad.error.powf(2.0)) - .sqrt(); + (slc.error.powf(2.0) + nyc.error.powf(2.0) + lax.error.powf(2.0) + mad.error.powf(2.0)) + .sqrt(); assert_eq!(error, 400.0); // iterate plenty of times to converge and minimize error @@ -304,4 +304,16 @@ mod tests { let t = serde_json::to_string(&a); assert_eq!(t.as_ref().unwrap(), s); } + + #[test] + fn test_estimated_rtt() { + // start with JSON, deserialize it + let s = "{\"position\":[{\"inner\":[1.5,0.5,2.0]},25.0],\"error\":1.0}"; + let a: NetworkCoordinate<3> = serde_json::from_str(s).unwrap(); + let s = "{\"position\":[{\"inner\":[-1.5,-0.5,-2.0]},50.0],\"error\":1.0}"; + let b: NetworkCoordinate<3> = serde_json::from_str(s).unwrap(); + + let estimate = a.estimated_rtt(&b); + assert_approx_eq!(estimate.as_secs_f32(), 0.080_099); + } }