Skip to content

Commit 6535fa7

Browse files
committed
Add tests for cdf helper functions
1 parent 14d4df2 commit 6535fa7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/util/cdf.rs

+43
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,46 @@ pub const fn cdf_5d<
9797

9898
out
9999
}
100+
101+
#[cfg(test)]
102+
mod test {
103+
use super::*;
104+
105+
#[test]
106+
fn cdf_len_ok() {
107+
let _: [u16; 5] = cdf([]);
108+
let _: [u16; 5] = cdf([1]);
109+
let _: [u16; 5] = cdf([1, 2, 3, 4]);
110+
}
111+
112+
#[test]
113+
#[should_panic]
114+
fn cdf_len_panics() {
115+
let _: [u16; 5] = cdf([1, 2, 3, 4, 5]);
116+
}
117+
118+
#[test]
119+
#[should_panic]
120+
fn cdf_val_panics() {
121+
let _: [u16; 5] = cdf([40000]);
122+
}
123+
124+
#[test]
125+
fn cdf_vals_ok() {
126+
let cdf: [u16; 5] = cdf([2000, 10000, 32768, 0]);
127+
assert_eq!(cdf, [30768, 22768, 0, 32768, 0]);
128+
}
129+
130+
#[test]
131+
fn cdf_2d_ok() {
132+
let cdf: [[u16; 4]; 2] = cdf_2d([
133+
[1000, 2000],
134+
[3000, 4000],
135+
]);
136+
137+
assert_eq!(cdf, [
138+
[31768, 30768, 0, 0],
139+
[29768, 28768, 0, 0],
140+
])
141+
}
142+
}

0 commit comments

Comments
 (0)