From 2630c9b6ea669eb138dc84aba8f2259e3578fc53 Mon Sep 17 00:00:00 2001 From: TheVeryDarkness <3266343194@qq.com> Date: Sun, 11 Aug 2024 15:54:26 +0800 Subject: [PATCH] Update tests and add `is_empty` for `Mat`. --- src/mat.rs | 4 ++++ tests/stdin.rs | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/mat.rs b/src/mat.rs index 9f9e8e3..b918105 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -18,6 +18,10 @@ impl Mat { 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 Mat { diff --git a/tests/stdin.rs b/tests/stdin.rs index f7c31d2..22149c9 100644 --- a/tests/stdin.rs +++ b/tests/stdin.rs @@ -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}, @@ -24,9 +24,25 @@ fn dot_product() { } #[test] -fn read_0() { +fn read_n_0() { let s1: Vec = read_n(0); let s2: Vec = try_read_n(0).unwrap(); assert!(s1.is_empty()); assert!(s2.is_empty()); } + +#[test] +fn read_m_n_0_0() { + let s1: Mat = read_m_n(0, 1); + let s2: Mat = 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()); +}