test: add test for NetworkCoordinate::estimate_rtt

Signed-off-by: Stephen Waits <steve@waits.net>
This commit is contained in:
swaits committed 2023-02-07 21:43:35 -07:00
1 parent 81ffc119e5
commit 8f95ed8c9f
1 file changed
+14 -2
+14 -2
View File
@@ -258,8 +258,8 @@ mod tests {
// verify the initial error // verify the initial error
let error = let error =
(slc.error.powf(2.0) + nyc.error.powf(2.0) + lax.error.powf(2.0) + mad.error.powf(2.0)) (slc.error.powf(2.0) + nyc.error.powf(2.0) + lax.error.powf(2.0) + mad.error.powf(2.0))
.sqrt(); .sqrt();
assert_eq!(error, 400.0); assert_eq!(error, 400.0);
// iterate plenty of times to converge and minimize error // iterate plenty of times to converge and minimize error
@@ -304,4 +304,16 @@ mod tests {
let t = serde_json::to_string(&a); let t = serde_json::to_string(&a);
assert_eq!(t.as_ref().unwrap(), s); 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);
}
} }