From d901633c75773ffaa8a1eb01cc9539e3f79b3924613e5c89d5f4b0236acf5d7e Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Sun, 21 Apr 2024 00:00:00 +0000 Subject: Implement input validation --- src/hitomezashi.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/hitomezashi.rs') diff --git a/src/hitomezashi.rs b/src/hitomezashi.rs index 9ec8758..8e2a773 100644 --- a/src/hitomezashi.rs +++ b/src/hitomezashi.rs @@ -36,6 +36,10 @@ pub fn hitomezashi(width: usize, height: usize, skew: Option) { // skew=0.5 generates the most random-looking patterns let skew: f64 = skew.unwrap_or(0.5); + assert!(width >= 1, "Width must be a positive number!"); + assert!(height >= 1, "Height must be a positive number!"); + assert!(skew >= 0.0 && skew <= 1.0, "Skew must be between zero and one inclusive!"); + let mut rng = rand::thread_rng(); let brn = Bernoulli::new(skew).unwrap(); -- cgit v1.2.3