From 2650fb547658e245024335761e01399e9a7d45fb Mon Sep 17 00:00:00 2001 From: mos Date: Sat, 11 Jan 2025 14:01:09 +0100 Subject: [PATCH] handle erroneous epop max size --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index db3e89a..b12e235 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ pub enum ReadError { pub enum Error { Read(ReadError), BadPopSize, + BadEpopMax, BadMut, BadCrossRatio, BadMove(Pos), @@ -87,6 +88,7 @@ impl std::fmt::Display for Error { match self { Error::Read(e) => write!(f, "{e}"), Error::BadPopSize => write!(f, "population size cannot be 0"), + Error::BadEpopMax => write!(f, "elite population size must be less than pop size"), Error::BadMut => write!(f, "mutation length too large"), Error::BadCrossRatio => write!(f, "crossover ratio cannot be 0"), Error::BadMove(pos) => write!(f, "invalid move ({pos})"), @@ -552,6 +554,10 @@ pub fn run(config: Config, rle: Option) -> Result<()> { return Err(Error::BadPopSize); } + if config.epop_max >= config.pop_size { + return Err(Error::BadEpopMax); + } + if config.mut_max > config.dna_size { return Err(Error::BadMut); }