Skip to content

Commit

Permalink
Update tests and add is_empty for Mat.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Aug 11, 2024
1 parent b1fa186 commit 2630c9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl<T> Mat<T> {
assert_eq!(vec.len(), m * n);
Self { m, n, inner: vec }
}
/// Check if the [Mat] is empty.
pub fn is_empty(&self) -> bool {
self.m == 0 || self.n == 0
}
}

impl<T> Mat<T> {
Expand Down
20 changes: 18 additions & 2 deletions tests/stdin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iof::{read_n, try_read_n};
use iof::{read_array, read_m_n, read_n, try_read_array, try_read_m_n, try_read_n, Mat};
use std::{
io::Write,
process::{Command, Stdio},
Expand All @@ -24,9 +24,25 @@ fn dot_product() {
}

#[test]
fn read_0() {
fn read_n_0() {
let s1: Vec<usize> = read_n(0);
let s2: Vec<char> = try_read_n(0).unwrap();
assert!(s1.is_empty());
assert!(s2.is_empty());
}

#[test]
fn read_m_n_0_0() {
let s1: Mat<usize> = read_m_n(0, 1);
let s2: Mat<char> = try_read_m_n(1, 0).unwrap();
assert!(s1.is_empty());
assert!(s2.is_empty());
}

#[test]
fn read_array_0() {
let s1: [usize; 0] = *read_array();
let s2: [char; 0] = *try_read_array().unwrap();
assert!(s1.is_empty());
assert!(s2.is_empty());
}

0 comments on commit 2630c9b

Please sign in to comment.