File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -100,4 +100,36 @@ mod tests {
100
100
assert ! ( max < 0.01 ) ;
101
101
// panic!();
102
102
}
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
+ }
103
135
}
You can’t perform that action at this time.
0 commit comments