use super::NUMBER_OF_CLASSES;
use crate::DominoError;
use std::cmp::Ordering;
use std::fmt::Display;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub struct ComplexityClass(pub usize);
impl ComplexityClass {
pub fn new(class: usize) -> Result<ComplexityClass, DominoError> {
if class == 0 || class > NUMBER_OF_CLASSES {
let err_msg = format!(
"The complexity class provided is not valid: {}.\nIt should be in the range [1, {}]",
class, NUMBER_OF_CLASSES
);
return Err(DominoError::InvalidClass(err_msg));
}
Ok(Self(class))
}
}
impl Display for ComplexityClass {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl Into<f32> for ComplexityClass {
fn into(self) -> f32 {
self.0 as f32
}
}
impl PartialEq<f32> for ComplexityClass {
fn eq(&self, other: &f32) -> bool {
(self.0 as f32) == *other
}
}
impl PartialOrd<f32> for ComplexityClass {
fn partial_cmp(&self, other: &f32) -> Option<Ordering> {
(self.0 as f32).partial_cmp(other)
}
}
impl PartialEq<usize> for ComplexityClass {
fn eq(&self, other: &usize) -> bool {
self.0 == *other
}
}
impl PartialOrd<usize> for ComplexityClass {
fn partial_cmp(&self, other: &usize) -> Option<Ordering> {
self.0.partial_cmp(other)
}
}