Test cols/rows

This commit is contained in:
eraden 2024-09-17 05:49:55 +02:00
parent e63383570e
commit 7a68f5ad19

View File

@ -502,8 +502,8 @@ impl<const X: usize, const Y: usize, const SIZE: usize> BinaryMap<X, Y, SIZE> {
}
}
pub fn lines(&self) -> impl Iterator<Item = &[MazePart]> {
self.0.windows(X)
pub fn rows(&self) -> impl Iterator<Item = &[MazePart]> {
self.0.windows(X).step_by(X)
}
/// 0 1 2
@ -539,7 +539,22 @@ mod column_iter_tests {
use super::*;
#[test]
fn check() {
fn rows() {
let grid = [
1, 2, 3, //
4, 5, 6, //
7, 8, 9, //
10, 11, 12, //
];
let mut it = grid.windows(3).step_by(3);
assert_eq!(it.next().map(Vec::from), Some(vec![1, 2, 3]));
assert_eq!(it.next().map(Vec::from), Some(vec![4, 5, 6]));
assert_eq!(it.next().map(Vec::from), Some(vec![7, 8, 9]));
assert_eq!(it.next().map(Vec::from), Some(vec![10, 11, 12]));
assert_eq!(it.next(), None);
}
#[test]
fn cols() {
let grid = [
1, 2, 3, //
4, 5, 6, //