chess_lab/common/errors/chess960.rs
1use thiserror::Error;
2
3/// An error that occurs when an invalid Chess960 Starting Position ID is encountered
4///
5#[derive(Debug, Error, PartialEq)]
6#[error("Invalid Chess960 ID: {spid}, must be between 0 and 959")]
7pub struct Chess960SPIDError {
8 /// The Chess960 ID that caused the error
9 pub spid: u16,
10}
11
12impl Chess960SPIDError {
13 /// Creates a new [Chess960SPIDError] with the given Chess960 Starting Position ID
14 ///
15 /// # Arguments
16 /// * `spid` - The Chess960 Starting Position ID that caused the error
17 ///
18 /// # Example
19 /// ```
20 /// # use chess_lab::errors::Chess960SPIDError;
21 /// let error = Chess960SPIDError::new(960);
22 /// ```
23 ///
24 pub fn new(spid: u16) -> Self {
25 Chess960SPIDError { spid }
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_chess960_id_error_creation() {
35 let error = Chess960SPIDError::new(960);
36 assert_eq!(error.spid, 960);
37 assert_eq!(
38 error.to_string(),
39 "Invalid Chess960 ID: 960, must be between 0 and 959"
40 );
41 }
42}