1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#![cfg(feature = "ndarray")]
use ndarray::{arr2, Array, Array2};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use smawk::monge::is_monge;
mod random_monge;
use random_monge::{random_monge_matrix, MongePrim};
#[test]
fn random_monge() {
let mut rng = ChaCha20Rng::seed_from_u64(0);
let matrix: Array2<u8> = random_monge_matrix(5, 5, &mut rng);
assert!(is_monge(&matrix));
assert_eq!(
matrix,
arr2(&[
[2, 3, 4, 4, 5],
[5, 5, 6, 6, 7],
[3, 3, 4, 4, 5],
[5, 2, 3, 3, 4],
[5, 2, 3, 3, 4]
])
);
}
#[test]
fn monge_constant_rows() {
let mut rng = ChaCha20Rng::seed_from_u64(0);
let matrix: Array2<u8> = MongePrim::ConstantRows.to_matrix(5, 4, &mut rng);
assert!(is_monge(&matrix));
for row in matrix.rows() {
let elem = row[0];
assert_eq!(row, Array::from_elem(matrix.ncols(), elem));
}
}
#[test]
fn monge_constant_cols() {
let mut rng = ChaCha20Rng::seed_from_u64(0);
let matrix: Array2<u8> = MongePrim::ConstantCols.to_matrix(5, 4, &mut rng);
assert!(is_monge(&matrix));
for column in matrix.columns() {
let elem = column[0];
assert_eq!(column, Array::from_elem(matrix.nrows(), elem));
}
}
#[test]
fn monge_upper_right_ones() {
let mut rng = ChaCha20Rng::seed_from_u64(1);
let matrix: Array2<u8> = MongePrim::UpperRightOnes.to_matrix(5, 4, &mut rng);
assert!(is_monge(&matrix));
assert_eq!(
matrix,
arr2(&[
[0, 0, 1, 1],
[0, 0, 1, 1],
[0, 0, 1, 1],
[0, 0, 0, 0],
[0, 0, 0, 0]
])
);
}
#[test]
fn monge_lower_left_ones() {
let mut rng = ChaCha20Rng::seed_from_u64(1);
let matrix: Array2<u8> = MongePrim::LowerLeftOnes.to_matrix(5, 4, &mut rng);
assert!(is_monge(&matrix));
assert_eq!(
matrix,
arr2(&[
[0, 0, 0, 0],
[0, 0, 0, 0],
[1, 1, 0, 0],
[1, 1, 0, 0],
[1, 1, 0, 0]
])
);
}
|