diff options
-rw-r--r-- | src/gamedata.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/gamedata.rs b/src/gamedata.rs index a956478..a608346 100644 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -2,6 +2,7 @@ use num_derive::FromPrimitive; use num_traits::FromPrimitive; use std::{ + cmp::Ordering, fmt::{self, Display, Formatter}, str::FromStr, }; @@ -372,11 +373,17 @@ macro_rules! ordering_group { /// Future versions might extend this order to introduce inter-wing comparisons or a full [`Ord`] /// instance. impl PartialOrd for Encounter { - fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { // Keep in mind that this is a partial order, not a weak order! In particular, we cannot // have bosses compare as equal if they are not the same (even if that would be nice for // Wing 5/Wing 7). use Encounter::*; + + // Ensure that a == b <=> a.partial_cmp(b) == Equal holds + if *self == *other { + return Some(Ordering::Equal); + } + ordering_group!(*self, *other; // Raids [ValeGuardian, Gorseval, Sabetha]; @@ -391,6 +398,7 @@ impl PartialOrd for Encounter { // Nightmare CM [MAMA, Siax, Ensolyss]; ); + None } } @@ -1204,6 +1212,10 @@ mod tests { assert!(Qadim > TwinLargos); assert!(Ankka.partial_cmp(&Dragonvoid).is_none()); + + assert_eq!(ValeGuardian.partial_cmp(&ValeGuardian), Some(Ordering::Equal)); + assert_eq!(Slothasor.partial_cmp(&Slothasor), Some(Ordering::Equal)); + assert_eq!(Ai.partial_cmp(&Ai), Some(Ordering::Equal)); } #[test] |