forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

tests.rs86 lines, 2.3 KiBHistoryRawDownload
1use super::*;
2use super::vectors::VECTORS;
3
4#[test]
5fn matches_reference_derivation_on_500_configurations() {
6 let mut mismatches = 0;
7 for &(
8 rate,
9 start_freq,
10 stop_freq,
11 freq_scale,
12 alter_scale,
13 noise_bands,
14 xover_band,
15 expected,
16 ) in VECTORS.iter().flat_map(|part| part.iter())
17 {
18 let got = freq_tables(
19 rate,
20 start_freq,
21 stop_freq,
22 freq_scale,
23 alter_scale,
24 xover_band,
25 noise_bands,
26 );
27 let ok = match (&got, expected) {
28 (None, None) => true,
29 (Some(t), Some((n_master, n_high, n_low, n_q, f_high, f_low, f_noise))) => {
30 t.n_master == n_master
31 && t.n_high == n_high
32 && t.n_low == n_low
33 && t.n_q == n_q
34 && t.f_high == f_high
35 && t.f_low == f_low
36 && t.f_noise == f_noise
37 }
38 _ => false,
39 };
40 if !ok {
41 mismatches += 1;
42 if mismatches <= 10 {
43 eprintln!(
44 "mismatch rate={rate} start={start_freq} stop={stop_freq} scale={freq_scale} \
45 alter={alter_scale} noise={noise_bands} xover={xover_band}: got {got:?} want {expected:?}"
46 );
47 }
48 }
49 }
50 assert_eq!(
51 mismatches, 0,
52 "{mismatches}/500 configurations disagreed with the reference derivation"
53 );
54}
55
56#[test]
57fn bands_are_monotonic_when_present() {
58 for &(
59 rate,
60 start_freq,
61 stop_freq,
62 freq_scale,
63 alter_scale,
64 noise_bands,
65 xover_band,
66 expected,
67 ) in VECTORS.iter().flat_map(|part| part.iter())
68 {
69 if expected.is_none() {
70 continue;
71 }
72 let t = freq_tables(
73 rate,
74 start_freq,
75 stop_freq,
76 freq_scale,
77 alter_scale,
78 xover_band,
79 noise_bands,
80 )
81 .expect("vector says Some");
82 assert!(t.f_high.windows(2).all(|w| w[0] < w[1]));
83 assert!(t.f_low.windows(2).all(|w| w[0] < w[1]));
84 assert!(t.f_noise.windows(2).all(|w| w[0] < w[1]));
85 }
86}