| 1 | //! The following is a series of tests that check conversions between every combination of sample |
| 2 | //! types available within this crate. |
| 3 | //! |
| 4 | //! We assert that each sample type's minimum, maximum and centre are correctly converted to the |
| 5 | //! min, max and centre of every other available sample type. |
| 6 | |
| 7 | /// Expands to an `assert_eq` for each pre-conversion and post-conversion pair. |
| 8 | /// |
| 9 | /// Literals that must be wrapped by a custom sample type are wrapped using $T/$U::new_unchecked. |
| 10 | macro_rules! conv_cmp { |
| 11 | ($fn_name:ident, $pre_conv:expr, $post_conv:expr) => { |
| 12 | assert_eq!($fn_name($pre_conv), $post_conv); |
| 13 | }; |
| 14 | ($fn_name:ident: $U:ident, $pre_conv:expr, $post_conv:expr) => { |
| 15 | assert_eq!($fn_name($pre_conv), $U::new_unchecked($post_conv)); |
| 16 | }; |
| 17 | ($T:ident; $fn_name:ident, $pre_conv:expr, $post_conv:expr) => { |
| 18 | assert_eq!($fn_name($T::new_unchecked($pre_conv)), $post_conv); |
| 19 | }; |
| 20 | ($T:ident; $fn_name:ident: $U:ident, $pre_conv:expr, $post_conv:expr) => { |
| 21 | assert_eq!( |
| 22 | $fn_name($T::new_unchecked($pre_conv)), |
| 23 | $U::new_unchecked($post_conv) |
| 24 | ); |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | /// Expands to a list of `assert_eq` statements. |
| 29 | macro_rules! conv_cmps { |
| 30 | ($fn_name:ident, $pre_conv:expr, $post_conv:expr; $($rest:tt)*) => { |
| 31 | conv_cmp!($fn_name, $pre_conv, $post_conv); |
| 32 | conv_cmps!($fn_name, $($rest)*); |
| 33 | }; |
| 34 | ($fn_name:ident: $U:ident, $pre_conv:expr, $post_conv:expr; $($rest:tt)*) => { |
| 35 | conv_cmp!($fn_name:$U, $pre_conv, $post_conv); |
| 36 | conv_cmps!($fn_name:$U, $($rest)*); |
| 37 | }; |
| 38 | ($T:ident; $fn_name:ident, $pre_conv:expr, $post_conv:expr; $($rest:tt)*) => { |
| 39 | conv_cmp!($T; $fn_name, $pre_conv, $post_conv); |
| 40 | conv_cmps!($T; $fn_name, $($rest)*); |
| 41 | }; |
| 42 | ($T:ident; $fn_name:ident: $U:ident, $pre_conv:expr, $post_conv:expr; $($rest:tt)*) => { |
| 43 | conv_cmp!($T; $fn_name:$U, $pre_conv, $post_conv); |
| 44 | conv_cmps!($T; $fn_name:$U, $($rest)*); |
| 45 | }; |
| 46 | ($fn_name:ident,) => {}; |
| 47 | ($fn_name:ident: $U:ident,) => {}; |
| 48 | ($T:ident; $fn_name:ident,) => {}; |
| 49 | ($T:ident; $fn_name:ident: $U:ident,) => {}; |
| 50 | } |
| 51 | |
| 52 | /// Expands to a test function for the given test function name. |
| 53 | /// |
| 54 | /// We must use one for each as: |
| 55 | /// 1. There is no concat-idents macro for constructing unique names from other identifiers and |
| 56 | /// 2. We need to check for functions that convert to custom sample types (i.e. to_i24 converts to |
| 57 | /// `I24`). |
| 58 | macro_rules! test_fn { |
| 59 | |
| 60 | (to_i8 { $($conv_cmps:tt)* }) => { |
| 61 | #[test] |
| 62 | fn test_to_i8() { |
| 63 | conv_cmps!(to_i8, $($conv_cmps)*); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | (to_i16 { $($conv_cmps:tt)* }) => { |
| 68 | #[test] |
| 69 | fn test_to_i16() { |
| 70 | conv_cmps!(to_i16, $($conv_cmps)*); |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | (to_i24 { $($conv_cmps:tt)* }) => { |
| 75 | #[test] |
| 76 | fn test_to_i24() { |
| 77 | conv_cmps!(to_i24: I24, $($conv_cmps)*); |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | (to_i32 { $($conv_cmps:tt)* }) => { |
| 82 | #[test] |
| 83 | fn test_to_i32() { |
| 84 | conv_cmps!(to_i32, $($conv_cmps)*); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | (to_i48 { $($conv_cmps:tt)* }) => { |
| 89 | #[test] |
| 90 | fn test_to_i48() { |
| 91 | conv_cmps!(to_i48: I48, $($conv_cmps)*); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | (to_i64 { $($conv_cmps:tt)* }) => { |
| 96 | #[test] |
| 97 | fn test_to_i64() { |
| 98 | conv_cmps!(to_i64, $($conv_cmps)*); |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | (to_u8 { $($conv_cmps:tt)* }) => { |
| 103 | #[test] |
| 104 | fn test_to_u8() { |
| 105 | conv_cmps!(to_u8, $($conv_cmps)*); |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | (to_u16 { $($conv_cmps:tt)* }) => { |
| 110 | #[test] |
| 111 | fn test_to_u16() { |
| 112 | conv_cmps!(to_u16, $($conv_cmps)*); |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | (to_u24 { $($conv_cmps:tt)* }) => { |
| 117 | #[test] |
| 118 | fn test_to_u24() { |
| 119 | conv_cmps!(to_u24: U24, $($conv_cmps)*); |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | (to_u32 { $($conv_cmps:tt)* }) => { |
| 124 | #[test] |
| 125 | fn test_to_u32() { |
| 126 | conv_cmps!(to_u32, $($conv_cmps)*); |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | (to_u48 { $($conv_cmps:tt)* }) => { |
| 131 | #[test] |
| 132 | fn test_to_u48() { |
| 133 | conv_cmps!(to_u48: U48, $($conv_cmps)*); |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | (to_u64 { $($conv_cmps:tt)* }) => { |
| 138 | #[test] |
| 139 | fn test_to_u64() { |
| 140 | conv_cmps!(to_u64, $($conv_cmps)*); |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | (to_f32 { $($conv_cmps:tt)* }) => { |
| 145 | #[test] |
| 146 | fn test_to_f32() { |
| 147 | conv_cmps!(to_f32, $($conv_cmps)*); |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | (to_f64 { $($conv_cmps:tt)* }) => { |
| 152 | #[test] |
| 153 | fn test_to_f64() { |
| 154 | conv_cmps!(to_f64, $($conv_cmps)*); |
| 155 | } |
| 156 | }; |
| 157 | |
| 158 | // Test functions for wrapper sample types. |
| 159 | |
| 160 | ($T:ident: to_i8 { $($conv_cmps:tt)* }) => { |
| 161 | #[test] |
| 162 | fn test_to_i8() { |
| 163 | conv_cmps!($T; to_i8, $($conv_cmps)*); |
| 164 | } |
| 165 | }; |
| 166 | |
| 167 | ($T:ident: to_i16 { $($conv_cmps:tt)* }) => { |
| 168 | #[test] |
| 169 | fn test_to_i16() { |
| 170 | conv_cmps!($T; to_i16, $($conv_cmps)*); |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | ($T:ident: to_i24 { $($conv_cmps:tt)* }) => { |
| 175 | #[test] |
| 176 | fn test_to_i24() { |
| 177 | conv_cmps!($T; to_i24: I24, $($conv_cmps)*); |
| 178 | } |
| 179 | }; |
| 180 | |
| 181 | ($T:ident: to_i32 { $($conv_cmps:tt)* }) => { |
| 182 | #[test] |
| 183 | fn test_to_i32() { |
| 184 | conv_cmps!($T; to_i32, $($conv_cmps)*); |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | ($T:ident: to_i48 { $($conv_cmps:tt)* }) => { |
| 189 | #[test] |
| 190 | fn test_to_i48() { |
| 191 | conv_cmps!($T; to_i48: I48, $($conv_cmps)*); |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | ($T:ident: to_i64 { $($conv_cmps:tt)* }) => { |
| 196 | #[test] |
| 197 | fn test_to_i64() { |
| 198 | conv_cmps!($T; to_i64, $($conv_cmps)*); |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | ($T:ident: to_u8 { $($conv_cmps:tt)* }) => { |
| 203 | #[test] |
| 204 | fn test_to_u8() { |
| 205 | conv_cmps!($T; to_u8, $($conv_cmps)*); |
| 206 | } |
| 207 | }; |
| 208 | |
| 209 | ($T:ident: to_u16 { $($conv_cmps:tt)* }) => { |
| 210 | #[test] |
| 211 | fn test_to_u16() { |
| 212 | conv_cmps!($T; to_u16, $($conv_cmps)*); |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | ($T:ident: to_u24 { $($conv_cmps:tt)* }) => { |
| 217 | #[test] |
| 218 | fn test_to_u24() { |
| 219 | conv_cmps!($T; to_u24: U24, $($conv_cmps)*); |
| 220 | } |
| 221 | }; |
| 222 | |
| 223 | ($T:ident: to_u32 { $($conv_cmps:tt)* }) => { |
| 224 | #[test] |
| 225 | fn test_to_u32() { |
| 226 | conv_cmps!($T; to_u32, $($conv_cmps)*); |
| 227 | } |
| 228 | }; |
| 229 | |
| 230 | ($T:ident: to_u48 { $($conv_cmps:tt)* }) => { |
| 231 | #[test] |
| 232 | fn test_to_u48() { |
| 233 | conv_cmps!($T; to_u48: U48, $($conv_cmps)*); |
| 234 | } |
| 235 | }; |
| 236 | |
| 237 | ($T:ident: to_u64 { $($conv_cmps:tt)* }) => { |
| 238 | #[test] |
| 239 | fn test_to_u64() { |
| 240 | conv_cmps!($T; to_u64, $($conv_cmps)*); |
| 241 | } |
| 242 | }; |
| 243 | |
| 244 | ($T:ident: to_f32 { $($conv_cmps:tt)* }) => { |
| 245 | #[test] |
| 246 | fn test_to_f32() { |
| 247 | conv_cmps!($T; to_f32, $($conv_cmps)*); |
| 248 | } |
| 249 | }; |
| 250 | |
| 251 | ($T:ident: to_f64 { $($conv_cmps:tt)* }) => { |
| 252 | #[test] |
| 253 | fn test_to_f64() { |
| 254 | conv_cmps!($T; to_f64, $($conv_cmps)*); |
| 255 | } |
| 256 | }; |
| 257 | } |
| 258 | |
| 259 | /// Expands to a list of test functions. |
| 260 | macro_rules! test_fns { |
| 261 | ($fn_name:tt { $($conv_cmps:tt)* } $($rest:tt)*) => { |
| 262 | test_fn!($fn_name { $($conv_cmps)* }); |
| 263 | test_fns!($($rest)*); |
| 264 | }; |
| 265 | ($T:ident: $fn_name:tt { $($conv_cmps:tt)* } $($rest:tt)*) => { |
| 266 | test_fn!($T: $fn_name { $($conv_cmps)* }); |
| 267 | test_fns!($T: $($rest)*); |
| 268 | }; |
| 269 | () => {}; |
| 270 | ($T:ident:) => {}; |
| 271 | } |
| 272 | |
| 273 | /// Expands to a unique test module containing a list of test functions. |
| 274 | macro_rules! tests { |
| 275 | ($T:ident { $($rest:tt)* }) => { |
| 276 | pub mod $T { |
| 277 | use dasp_sample::conv::$T::*; |
| 278 | use dasp_sample::types::{I24, U24, I48, U48}; |
| 279 | test_fns!($($rest)*); |
| 280 | } |
| 281 | }; |
| 282 | ($T:ident: $mod_name:ident { $($rest:tt)* }) => { |
| 283 | pub mod $mod_name { |
| 284 | use dasp_sample::conv::$mod_name::*; |
| 285 | use dasp_sample::types::{I24, U24, I48, U48}; |
| 286 | test_fns!($T: $($rest)*); |
| 287 | } |
| 288 | }; |
| 289 | } |
| 290 | |
| 291 | tests!(i8 { |
| 292 | to_i16 { -128, -32_768; 0, 0; 127, 32_512; } |
| 293 | to_i24 { -128, -8_388_608; 0, 0; 127, 8_323_072; } |
| 294 | to_i32 { -128, -2_147_483_648; 0, 0; 127, 2_130_706_432; } |
| 295 | to_i48 { -128, -140_737_488_355_328; 0, 0; 127, 139_637_976_727_552; } |
| 296 | to_i64 { -128, -9_223_372_036_854_775_808; 0, 0; 127, 9_151_314_442_816_847_872; } |
| 297 | to_u8 { -128, 0; 0, 128; 127, 255; } |
| 298 | to_u16 { -128, 0; 0, 32_768; 127, 65_280; } |
| 299 | to_u24 { -128, 0; 0, 8_388_608; 127, 16_711_680; } |
| 300 | to_u32 { -128, 0; 0, 2_147_483_648; 127, 4_278_190_080; } |
| 301 | to_u48 { -128, 0; 0, 140_737_488_355_328; 127, 280_375_465_082_880; } |
| 302 | to_u64 { -128, 0; 0, 9_223_372_036_854_775_808; 127, 18_374_686_479_671_623_680; } |
| 303 | to_f32 { -128, -1.0; 0, 0.0; } |
| 304 | to_f64 { -128, -1.0; 0, 0.0; } |
| 305 | }); |
| 306 | |
| 307 | tests!(i16 { |
| 308 | to_i8 { -32_768, -128; 0, 0; 32_767, 127; } |
| 309 | to_i24 { -32_768, -8_388_608; 0, 0; 32_767, 8_388_352; } |
| 310 | to_i32 { -32_768, -2_147_483_648; 0, 0; 32_767, 2_147_418_112; } |
| 311 | to_i48 { -32_768, -140_737_488_355_328; 0, 0; 32_767, 140_733_193_388_032; } |
| 312 | to_i64 { -32_768, -9_223_372_036_854_775_808; 0, 0; 32_767, 9_223_090_561_878_065_152; } |
| 313 | to_u8 { -32_768, 0; 0, 128; 32_767, 255; } |
| 314 | to_u16 { -32_768, 0; 0, 32_768; 32_767, 65_535; } |
| 315 | to_u24 { -32_768, 0; 0, 8_388_608; 32_767, 16_776_960; } |
| 316 | to_u32 { -32_768, 0; 0, 2_147_483_648; 32_767, 4_294_901_760; } |
| 317 | to_u48 { -32_768, 0; 0, 140_737_488_355_328; 32_767, 281_470_681_743_360; } |
| 318 | to_u64 { -32_768, 0; 0, 9_223_372_036_854_775_808; 32_767, 18_446_462_598_732_840_960; } |
| 319 | to_f32 { -32_768, -1.0; 0, 0.0; } |
| 320 | to_f64 { -32_768, -1.0; 0, 0.0; } |
| 321 | }); |
| 322 | |
| 323 | tests!(I24: i24 { |
| 324 | to_i8 { -8_388_608, -128; 0, 0; 8_388_607, 127; } |
| 325 | to_i16 { -8_388_608, -32_768; 0, 0; 8_388_607, 32_767; } |
| 326 | to_i32 { -8_388_608, -2_147_483_648; 0, 0; 8_388_607, 2_147_483_392; } |
| 327 | to_i48 { -8_388_608, -140_737_488_355_328; 0, 0; 8_388_607, 140_737_471_578_112; } |
| 328 | to_i64 { -8_388_608, -9_223_372_036_854_775_808; 0, 0; 8_388_607, 9_223_370_937_343_148_032; } |
| 329 | to_u8 { -8_388_608, 0; 0, 128; 8_388_607, 255; } |
| 330 | to_u16 { -8_388_608, 0; 0, 32_768; 8_388_607, 65_535; } |
| 331 | to_u24 { -8_388_608, 0; 0, 8_388_608; 8_388_607, 16_777_215; } |
| 332 | to_u32 { -8_388_608, 0; 0, 2_147_483_648; 8_388_607, 4_294_967_040; } |
| 333 | to_u48 { -8_388_608, 0; 0, 140_737_488_355_328; 8_388_607, 281_474_959_933_440; } |
| 334 | to_u64 { -8_388_608, 0; 0, 9_223_372_036_854_775_808; 8_388_607, 18_446_742_974_197_923_840; } |
| 335 | to_f32 { -8_388_608, -1.0; 0, 0.0; } |
| 336 | to_f64 { -8_388_608, -1.0; 0, 0.0; } |
| 337 | }); |
| 338 | |
| 339 | tests!(i32 { |
| 340 | to_i8 { -2_147_483_648, -128; 0, 0; 2_147_483_647, 127; } |
| 341 | to_i16 { -2_147_483_648, -32_768; 0, 0; 2_147_483_647, 32_767; } |
| 342 | to_i24 { -2_147_483_648, -8_388_608; 0, 0; 2_147_483_647, 8_388_607; } |
| 343 | to_i48 { -2_147_483_648, -140_737_488_355_328; 0, 0; 2_147_483_647, 140_737_488_289_792; } |
| 344 | to_i64 { -2_147_483_648, -9_223_372_036_854_775_808; 0, 0; 2_147_483_647, 9_223_372_032_559_808_512; } |
| 345 | to_u8 { -2_147_483_648, 0; 0, 128; 2_147_483_647, 255; } |
| 346 | to_u16 { -2_147_483_648, 0; 0, 32_768; 2_147_483_647, 65_535; } |
| 347 | to_u24 { -2_147_483_648, 0; 0, 8_388_608; 2_147_483_647, 16_777_215; } |
| 348 | to_u32 { -2_147_483_648, 0; 0, 2_147_483_648; 2_147_483_647, 4_294_967_295; } |
| 349 | to_u48 { -2_147_483_648, 0; 0, 140_737_488_355_328; 2_147_483_647, 281_474_976_645_120; } |
| 350 | to_u64 { -2_147_483_648, 0; 0, 9_223_372_036_854_775_808; 2_147_483_647, 18_446_744_069_414_584_320; } |
| 351 | to_f32 { -2_147_483_648, -1.0; 0, 0.0; } |
| 352 | to_f64 { -2_147_483_648, -1.0; 0, 0.0; } |
| 353 | }); |
| 354 | |
| 355 | tests!(I48: i48 { |
| 356 | to_i8 { -140_737_488_355_328, -128; 0, 0; 140_737_488_355_327, 127; } |
| 357 | to_i16 { -140_737_488_355_328, -32_768; 0, 0; 140_737_488_355_327, 32_767; } |
| 358 | to_i24 { -140_737_488_355_328, -8_388_608; 0, 0; 140_737_488_355_327, 8_388_607; } |
| 359 | to_i32 { -140_737_488_355_328, -2_147_483_648; 0, 0; 140_737_488_355_327, 2_147_483_647; } |
| 360 | to_i64 { -140_737_488_355_328, -9_223_372_036_854_775_808; 0, 0; 140_737_488_355_327, 9_223_372_036_854_710_272; } |
| 361 | to_u8 { -140_737_488_355_328, 0; 0, 128; 140_737_488_355_327, 255; } |
| 362 | to_u16 { -140_737_488_355_328, 0; 0, 32_768; 140_737_488_355_327, 65_535; } |
| 363 | to_u24 { -140_737_488_355_328, 0; 0, 8_388_608; 140_737_488_355_327, 16_777_215; } |
| 364 | to_u32 { -140_737_488_355_328, 0; 0, 2_147_483_648; 140_737_488_355_327, 4_294_967_295; } |
| 365 | to_u48 { -140_737_488_355_328, 0; 0, 140_737_488_355_328; 140_737_488_355_327, 281_474_976_710_655; } |
| 366 | to_u64 { -140_737_488_355_328, 0; 0, 9_223_372_036_854_775_808; 140_737_488_355_327, 18_446_744_073_709_486_080; } |
| 367 | }); |
| 368 | |
| 369 | tests!(i64 { |
| 370 | to_i8 { -9_223_372_036_854_775_808, -128; 0, 0; 9_223_372_036_854_775_807, 127; } |
| 371 | to_i16 { -9_223_372_036_854_775_808, -32_768; 0, 0; 9_223_372_036_854_775_807, 32_767; } |
| 372 | to_i24 { -9_223_372_036_854_775_808, -8_388_608; 0, 0; 9_223_372_036_854_775_807, 8_388_607; } |
| 373 | to_i32 { -9_223_372_036_854_775_808, -2_147_483_648; 0, 0; 9_223_372_036_854_775_807, 2_147_483_647; } |
| 374 | to_i48 { -9_223_372_036_854_775_808, -140_737_488_355_328; 0, 0; 9_223_372_036_854_775_807, 140_737_488_355_327; } |
| 375 | to_u8 { -9_223_372_036_854_775_808, 0; 0, 128; 9_223_372_036_854_775_807, 255; } |
| 376 | to_u16 { -9_223_372_036_854_775_808, 0; 0, 32_768; 9_223_372_036_854_775_807, 65_535; } |
| 377 | to_u24 { -9_223_372_036_854_775_808, 0; 0, 8_388_608; 9_223_372_036_854_775_807, 16_777_215; } |
| 378 | to_u32 { -9_223_372_036_854_775_808, 0; 0, 2_147_483_648; 9_223_372_036_854_775_807, 4_294_967_295; } |
| 379 | to_u48 { -9_223_372_036_854_775_808, 0; 0, 140_737_488_355_328; 9_223_372_036_854_775_807, 281_474_976_710_655; } |
| 380 | to_u64 { -9_223_372_036_854_775_808, 0; 0, 9_223_372_036_854_775_808; 9_223_372_036_854_775_807, 18_446_744_073_709_551_615; } |
| 381 | to_f32 { -9_223_372_036_854_775_808, -1.0; 0, 0.0; } |
| 382 | to_f64 { -9_223_372_036_854_775_808, -1.0; 0, 0.0; } |
| 383 | }); |
| 384 | |
| 385 | tests!(u8 { |
| 386 | to_i8 { 0, -128; 128, 0; 255, 127; } |
| 387 | to_i16 { 0, -32_768; 128, 0; 255, 32_512; } |
| 388 | to_i24 { 0, -8_388_608; 128, 0; 255, 8_323_072; } |
| 389 | to_i32 { 0, -2_147_483_648; 128, 0; 255, 2_130_706_432; } |
| 390 | to_i48 { 0, -140_737_488_355_328; 128, 0; 255, 139_637_976_727_552; } |
| 391 | to_i64 { 0, -9_223_372_036_854_775_808; 128, 0; 255, 9_151_314_442_816_847_872; } |
| 392 | to_u16 { 0, 0; 128, 32_768; 255, 65_280; } |
| 393 | to_u24 { 0, 0; 128, 8_388_608; 255, 16_711_680; } |
| 394 | to_u32 { 0, 0; 128, 2_147_483_648; 255, 4_278_190_080; } |
| 395 | to_u48 { 0, 0; 128, 140_737_488_355_328; 255, 280_375_465_082_880; } |
| 396 | to_u64 { 0, 0; 128, 9_223_372_036_854_775_808; 255, 18_374_686_479_671_623_680; } |
| 397 | to_f32 { 0, -1.0; 128, 0.0; } |
| 398 | to_f64 { 0, -1.0; 128, 0.0; } |
| 399 | }); |
| 400 | |
| 401 | tests!(u16 { |
| 402 | to_i8 { 0, -128; 32_768, 0; 65_535, 127; } |
| 403 | to_i16 { 0, -32_768; 32_768, 0; 65_535, 32_767; } |
| 404 | to_i24 { 0, -8_388_608; 32_768, 0; 65_535, 8_388_352; } |
| 405 | to_i32 { 0, -2_147_483_648; 32_768, 0; 65_535, 2_147_418_112; } |
| 406 | to_i48 { 0, -140_737_488_355_328; 32_768, 0; 65_535, 140_733_193_388_032; } |
| 407 | to_i64 { 0, -9_223_372_036_854_775_808; 32_768, 0; 65_535, 9_223_090_561_878_065_152; } |
| 408 | to_u8 { 0, 0; 32_768, 128; 65_535, 255; } |
| 409 | to_u24 { 0, 0; 32_768, 8_388_608; 65_535, 16_776_960; } |
| 410 | to_u32 { 0, 0; 32_768, 2_147_483_648; 65_535, 4_294_901_760; } |
| 411 | to_u48 { 0, 0; 32_768, 140_737_488_355_328; 65_535, 281_470_681_743_360; } |
| 412 | to_u64 { 0, 0; 32_768, 9_223_372_036_854_775_808; 65_535, 18_446_462_598_732_840_960; } |
| 413 | to_f32 { 0, -1.0; 32_768, 0.0; } |
| 414 | to_f64 { 0, -1.0; 32_768, 0.0; } |
| 415 | }); |
| 416 | |
| 417 | tests!(U24: u24 { |
| 418 | to_i8 { 0, -128; 8_388_608, 0; 16_777_215, 127; } |
| 419 | to_i16 { 0, -32_768; 8_388_608, 0; 16_777_215, 32_767; } |
| 420 | to_i24 { 0, -8_388_608; 8_388_608, 0; 16_777_215, 8_388_607; } |
| 421 | to_i32 { 0, -2_147_483_648; 8_388_608, 0; 16_777_215, 2_147_483_392; } |
| 422 | to_i48 { 0, -140_737_488_355_328; 8_388_608, 0; 16_777_215, 140_737_471_578_112; } |
| 423 | to_i64 { 0, -9_223_372_036_854_775_808; 8_388_608, 0; 16_777_215, 9_223_370_937_343_148_032; } |
| 424 | to_u8 { 0, 0; 8_388_608, 128; 16_777_215, 255; } |
| 425 | to_u16 { 0, 0; 8_388_608, 32_768; 16_777_215, 65_535; } |
| 426 | to_u32 { 0, 0; 8_388_608, 2_147_483_648; 16_777_215, 4_294_967_040; } |
| 427 | to_u48 { 0, 0; 8_388_608, 140_737_488_355_328; 16_777_215, 281_474_959_933_440; } |
| 428 | to_u64 { 0, 0; 8_388_608, 9_223_372_036_854_775_808; 16_777_215, 18_446_742_974_197_923_840; } |
| 429 | to_f32 { 0, -1.0; 8_388_608, 0.0; } |
| 430 | to_f64 { 0, -1.0; 8_388_608, 0.0; } |
| 431 | }); |
| 432 | |
| 433 | tests!(u32 { |
| 434 | to_i8 { 0, -128; 2_147_483_648, 0; 4_294_967_295, 127; } |
| 435 | to_i16 { 0, -32_768; 2_147_483_648, 0; 4_294_967_295, 32_767; } |
| 436 | to_i24 { 0, -8_388_608; 2_147_483_648, 0; 4_294_967_295, 8_388_607; } |
| 437 | to_i32 { 0, -2_147_483_648; 2_147_483_648, 0; 4_294_967_295, 2_147_483_647; } |
| 438 | to_i48 { 0, -140_737_488_355_328; 2_147_483_648, 0; 4_294_967_295, 140_737_488_289_792; } |
| 439 | to_i64 { 0, -9_223_372_036_854_775_808; 2_147_483_648, 0; 4_294_967_295, 9_223_372_032_559_808_512; } |
| 440 | to_u8 { 0, 0; 2_147_483_648, 128; 4_294_967_295, 255; } |
| 441 | to_u16 { 0, 0; 2_147_483_648, 32_768; 4_294_967_295, 65_535; } |
| 442 | to_u24 { 0, 0; 2_147_483_648, 8_388_608; 4_294_967_295, 16_777_215; } |
| 443 | to_u48 { 0, 0; 2_147_483_648, 140_737_488_355_328; 4_294_967_295, 281_474_976_645_120; } |
| 444 | to_u64 { 0, 0; 2_147_483_648, 9_223_372_036_854_775_808; 4_294_967_295, 18_446_744_069_414_584_320; } |
| 445 | to_f32 { 0, -1.0; 2_147_483_648, 0.0; } |
| 446 | to_f64 { 0, -1.0; 2_147_483_648, 0.0; } |
| 447 | }); |
| 448 | |
| 449 | tests!(U48: u48 { |
| 450 | to_i8 { 0, -128; 140_737_488_355_328, 0; 281_474_976_710_655, 127; } |
| 451 | to_i16 { 0, -32_768; 140_737_488_355_328, 0; 281_474_976_710_655, 32_767; } |
| 452 | to_i24 { 0, -8_388_608; 140_737_488_355_328, 0; 281_474_976_710_655, 8_388_607; } |
| 453 | to_i32 { 0, -2_147_483_648; 140_737_488_355_328, 0; 281_474_976_710_655, 2_147_483_647; } |
| 454 | to_i48 { 0, -140_737_488_355_328; 140_737_488_355_328, 0; 281_474_976_710_655, 140_737_488_355_327; } |
| 455 | to_i64 { 0, -9_223_372_036_854_775_808; 140_737_488_355_328, 0; 281_474_976_710_655, 9_223_372_036_854_710_272; } |
| 456 | to_u8 { 0, 0; 140_737_488_355_328, 128; 281_474_976_710_655, 255; } |
| 457 | to_u16 { 0, 0; 140_737_488_355_328, 32_768; 281_474_976_710_655, 65_535; } |
| 458 | to_u24 { 0, 0; 140_737_488_355_328, 8_388_608; 281_474_976_710_655, 16_777_215; } |
| 459 | to_u32 { 0, 0; 140_737_488_355_328, 2_147_483_648; 281_474_976_710_655, 4_294_967_295; } |
| 460 | to_u64 { 0, 0; 140_737_488_355_328, 9_223_372_036_854_775_808; 281_474_976_710_655, 18_446_744_073_709_486_080; } |
| 461 | to_f32 { 0, -1.0; 140_737_488_355_328, 0.0; } |
| 462 | to_f64 { 0, -1.0; 140_737_488_355_328, 0.0; } |
| 463 | }); |
| 464 | |
| 465 | tests!(u64 { |
| 466 | to_i8 { 0, -128; 9_223_372_036_854_775_808, 0; 18_446_744_073_709_551_615, 127; } |
| 467 | to_i16 { 0, -32_768; 9_223_372_036_854_775_808, 0; 18_446_744_073_709_551_615, 32_767; } |
| 468 | to_i24 { 0, -8_388_608; 9_223_372_036_854_775_808, 0; 18_446_744_073_709_551_615, 8_388_607; } |
| 469 | to_i32 { 0, -2_147_483_648; 9_223_372_036_854_775_808, 0; 18_446_744_073_709_551_615, 2_147_483_647; } |
| 470 | to_i48 { 0, -140_737_488_355_328; 9_223_372_036_854_775_808, 0; 18_446_744_073_709_551_615, 140_737_488_355_327; } |
| 471 | to_i64 { 0, -9_223_372_036_854_775_808; 9_223_372_036_854_775_808, 0; 18_446_744_073_709_551_615, 9_223_372_036_854_775_807; } |
| 472 | to_u8 { 0, 0; 9_223_372_036_854_775_808, 128; 18_446_744_073_709_551_615, 255; } |
| 473 | to_u16 { 0, 0; 9_223_372_036_854_775_808, 32_768; 18_446_744_073_709_551_615, 65_535; } |
| 474 | to_u24 { 0, 0; 9_223_372_036_854_775_808, 8_388_608; 18_446_744_073_709_551_615, 16_777_215; } |
| 475 | to_u32 { 0, 0; 9_223_372_036_854_775_808, 2_147_483_648; 18_446_744_073_709_551_615, 4_294_967_295; } |
| 476 | to_u48 { 0, 0; 9_223_372_036_854_775_808, 140_737_488_355_328; 18_446_744_073_709_551_615, 281_474_976_710_655; } |
| 477 | to_f32 { 0, -1.0; 9_223_372_036_854_775_808, 0.0; } |
| 478 | to_f64 { 0, -1.0; 9_223_372_036_854_775_808, 0.0; } |
| 479 | }); |
| 480 | |
| 481 | tests!(f32 { |
| 482 | to_i8 { -1.0, -128; 0.0, 0; } |
| 483 | to_i16 { -1.0, -32_768; 0.0, 0; } |
| 484 | to_i24 { -1.0, -8_388_608; 0.0, 0; } |
| 485 | to_i32 { -1.0, -2_147_483_648; 0.0, 0; } |
| 486 | to_i48 { -1.0, -140_737_488_355_328; 0.0, 0; } |
| 487 | to_i64 { -1.0, -9_223_372_036_854_775_808; 0.0, 0; } |
| 488 | to_u8 { -1.0, 0; 0.0, 128; } |
| 489 | to_u16 { -1.0, 0; 0.0, 32_768; } |
| 490 | to_u24 { -1.0, 0; 0.0, 8_388_608; } |
| 491 | to_u32 { -1.0, 0; 0.0, 2_147_483_648; } |
| 492 | to_u48 { -1.0, 0; 0.0, 140_737_488_355_328; } |
| 493 | to_u64 { -1.0, 0; 0.0, 9_223_372_036_854_775_808; } |
| 494 | to_f64 { -1.0, -1.0; 0.0, 0.0; } |
| 495 | }); |
| 496 | |
| 497 | tests!(f64 { |
| 498 | to_i8 { -1.0, -128; 0.0, 0; } |
| 499 | to_i16 { -1.0, -32_768; 0.0, 0; } |
| 500 | to_i24 { -1.0, -8_388_608; 0.0, 0; } |
| 501 | to_i32 { -1.0, -2_147_483_648; 0.0, 0; } |
| 502 | to_i48 { -1.0, -140_737_488_355_328; 0.0, 0; } |
| 503 | to_i64 { -1.0, -9_223_372_036_854_775_808; 0.0, 0; } |
| 504 | to_u8 { -1.0, 0; 0.0, 128; } |
| 505 | to_u16 { -1.0, 0; 0.0, 32_768; } |
| 506 | to_u24 { -1.0, 0; 0.0, 8_388_608; } |
| 507 | to_u32 { -1.0, 0; 0.0, 2_147_483_648; } |
| 508 | to_u48 { -1.0, 0; 0.0, 140_737_488_355_328; } |
| 509 | to_u64 { -1.0, 0; 0.0, 9_223_372_036_854_775_808; } |
| 510 | to_f32 { -1.0, -1.0; 0.0, 0.0; } |
| 511 | }); |