MCPcopy Create free account
hub / github.com/daniel-e/rustml / test_scan

Function test_scan

src/knn.rs:98–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96
97 #[test]
98 fn test_scan() {
99
100 let mut m = mat![
101 1.0, 2.0;
102 2.0, 2.0;
103 3.0, 3.0
104 ];
105
106 let a = scan(&m, &[1.0, 1.0, 2.0], 1, |x, y| Euclid::compute(x, y).unwrap());
107 assert!(a.is_none());
108
109 let mut label = scan(&m, &[1.0, 1.0], 1, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
110 assert_eq!(label, vec![0]);
111
112 label = scan(&m, &[1.0, 2.0], 1, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
113 assert_eq!(label, vec![0]);
114
115 label = scan(&m, &[2.0, 2.2], 1, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
116 assert_eq!(label, vec![1]);
117
118 label = scan(&m, &[5.0, 6.0], 1, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
119 assert_eq!(label, vec![2]);
120
121 // ---------------
122
123 m = mat![
124 1.0, 2.0;
125 1.3, 1.8;
126 1.2, 2.1;
127 2.0, 2.0
128 ];
129
130 label = scan(&m, &[1.1, 2.0], 1, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
131 assert_eq!(label, vec![0]);
132 label = scan(&m, &[1.1, 2.0], 2, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
133 assert_eq!(label, vec![0, 2]);
134 label = scan(&m, &[1.1, 2.0], 3, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
135 assert_eq!(label, vec![0, 2, 1]);
136 label = scan(&m, &[1.1, 2.0], 4, |x, y| Euclid::compute(x, y).unwrap()).unwrap();
137 assert_eq!(label, vec![0, 2, 1, 3]);
138 }
139}
140
141

Callers

nothing calls this directly

Calls 1

scanFunction · 0.85

Tested by

no test coverage detected