Skip to content

Commit 52a1be7

Browse files
committed
fix: partial compare implementation
1 parent e93dd42 commit 52a1be7

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

src/entities/question.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ impl Hash for Model {
4848

4949
impl PartialOrd for Model {
5050
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
51-
match self
52-
.frontend_question_id
53-
.parse::<i32>()
54-
.unwrap()
55-
.partial_cmp(&other.frontend_question_id.parse::<i32>().unwrap())
56-
{
57-
Some(core::cmp::Ordering::Equal) => Some(core::cmp::Ordering::Equal),
58-
ord => ord,
59-
}
51+
Some(self.cmp(other))
6052
}
6153
}
6254

@@ -82,3 +74,42 @@ impl Related<super::topic_tag::Entity> for Entity {
8274
}
8375

8476
impl ActiveModelBehavior for ActiveModel {}
77+
78+
#[cfg(test)]
79+
mod tests {
80+
use super::*;
81+
82+
#[test]
83+
fn test() {
84+
let m1 = Model {
85+
ac_rate: None,
86+
difficulty: None,
87+
freq_bar: None,
88+
frontend_question_id: "1".to_string(),
89+
is_favor: None,
90+
paid_only: None,
91+
status: None,
92+
title: None,
93+
title_slug: None,
94+
has_solution: None,
95+
has_video_solution: None,
96+
};
97+
98+
let m2 = Model {
99+
ac_rate: None,
100+
difficulty: None,
101+
freq_bar: None,
102+
frontend_question_id: "2".to_string(),
103+
is_favor: None,
104+
paid_only: None,
105+
status: None,
106+
title: None,
107+
title_slug: None,
108+
has_solution: None,
109+
has_video_solution: None,
110+
};
111+
112+
assert!(m1 < m2);
113+
assert!(m1 == m1);
114+
}
115+
}

0 commit comments

Comments
 (0)