Skip to content

Commit 1b863ba

Browse files
committed
gps: wire: msl resolution test
1 parent e981a7c commit 1b863ba

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sfy-buoy/src/gps/wire.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,36 @@ mod tests {
100100
assert!(max < 0.01);
101101
// panic!();
102102
}
103+
104+
#[test]
105+
fn round_trip_msl() {
106+
let mut max: f32 = 0.0;
107+
let mut avg: f32 = 0.0;
108+
109+
const N: i32 = 1000000i32;
110+
111+
for i in 0..N {
112+
let v = (i as f32) * MSL_RANGE / N as f32;
113+
let u = scale_f32_to_u16(MSL_RANGE, v);
114+
let fu = scale_u16_to_f32(MSL_RANGE, u);
115+
116+
let uu = Msl16::from_f32(v);
117+
let fuu = uu.to_f32();
118+
119+
assert_eq!(u, uu.to_u16());
120+
assert_eq!(fu, fuu);
121+
122+
let d = (v - fu).abs();
123+
max = max.max(d);
124+
avg = avg + d;
125+
}
126+
127+
avg = avg / N as f32;
128+
println!("msl range: {}", MSL_RANGE);
129+
println!("msl u16 avg diff: {}", avg);
130+
println!("msl u16 max diff: {}", max);
131+
132+
assert!(max < 0.01);
133+
// panic!();
134+
}
103135
}

0 commit comments

Comments
 (0)