diff options
author | Daniel Schadt <kingdread@gmx.de> | 2024-08-26 18:31:01 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2024-08-26 18:31:01 +0200 |
commit | 01e68e3e7b0b5735f8a85a7b547fe14d50e9be7e (patch) | |
tree | d109cb9e0464c370543e41fa44c3cc752284457e | |
parent | 49b1a46e11dac1a2d8f3f04418381363cb6f39c9 (diff) | |
download | evtclib-01e68e3e7b0b5735f8a85a7b547fe14d50e9be7e.tar.gz evtclib-01e68e3e7b0b5735f8a85a7b547fe14d50e9be7e.tar.bz2 evtclib-01e68e3e7b0b5735f8a85a7b547fe14d50e9be7e.zip |
fix partial_cmp return value for equal items
-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] |