Skip to content

Commit d57026b

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

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/util/cdf.rs

+37
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,40 @@ 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_5d_ok() {
132+
let cdf: [[[[[u16; 4]; 2]; 1]; 1]; 1] =
133+
cdf_5d([[[[[1000, 2000], [3000, 4000]]]]]);
134+
assert_eq!(cdf, [[[[[31768, 30768, 0, 0], [29768, 28768, 0, 0],]]]])
135+
}
136+
}

0 commit comments

Comments
 (0)