Debian Codegraph @

.cargo/vendor/transpose/tests/test_transpose.rs

raw
1 extern crate transpose;
2
3 fn gen_data(width: usize, height: usize) -> Vec<usize> {
4 (0..width*height).collect()
5 }
6
7 const BLOCK_SIZE: usize = 16;
8
9 #[test]
10 fn test_out_of_place_transpose() {
11 let sizes = [
12 0, 1, 2,
13 BLOCK_SIZE - 1, BLOCK_SIZE, BLOCK_SIZE + 1,
14 BLOCK_SIZE * 4 - 1, BLOCK_SIZE * 5, BLOCK_SIZE * 4 + 1
15 ];
16
17 for &width in &sizes {
18 for &height in &sizes {
19 let input = gen_data(width, height);
20 let mut output = vec![0; width * height];
21
22 transpose::transpose(&input, &mut output, width, height);
23
24 for x in 0..width {
25 for y in 0..height {
26 assert_eq!(input[x + y * width], output[y + x * height], "x = {}, y = {}", x, y);
27 }
28 }
29 }
30 }
31 }
32
33 #[test]
34 fn test_transpose_inplace() {
35
36 for width in 1..10 {
37 for height in 1..10 {
38 let input = gen_data(width, height);
39 let mut output = input.clone();
40 let mut scratch = vec![usize::default(); std::cmp::max(width, height)];
41
42 transpose::transpose_inplace(&mut output, &mut scratch, width, height);
43
44 for x in 0..width {
45 for y in 0..height {
46 assert_eq!(input[x + y * width], output[y + x * height], "x = {}, y = {}", x, y);
47 }
48 }
49 }
50 }
51 }