1use super::Set;
6
7impl<T: PartialEq, const N: usize, const M: usize> PartialEq<Set<T, M>> for Set<T, N> {
8 #[inline]
25 fn eq(&self, other: &Set<T, M>) -> bool {
26 self.map.eq(&other.map)
27 }
28}
29
30impl<T: Eq, const N: usize> Eq for Set<T, N> {}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn compares_two_sets() {
38 let mut s1: Set<i32, 1> = Set::new();
39 s1.insert(1);
40 let mut s2: Set<i32, 1> = Set::new();
41 s2.insert(1);
42 assert_eq!(s1, s2);
43 }
44
45 #[test]
46 fn compares_sets_with_different_order() {
47 let mut s1: Set<i32, 3> = Set::new();
48 s1.insert(1);
49 s1.insert(2);
50 s1.insert(3);
51 let mut s2: Set<i32, 3> = Set::new();
52 s2.insert(3);
53 s2.insert(2);
54 s2.insert(1);
55 assert_eq!(s1, s2);
56 }
57
58 #[test]
59 fn compares_sets_with_different_lengths() {
60 let mut s1: Set<i32, 3> = Set::new();
61 s1.insert(1);
62 s1.insert(2);
63 let mut s2: Set<i32, 3> = Set::new();
64 s2.insert(1);
65 assert_ne!(s1, s2);
66 }
67
68 #[test]
69 fn compares_sets_with_different_elements() {
70 let mut s1: Set<i32, 1> = Set::new();
71 s1.insert(1);
72 let mut s2: Set<i32, 1> = Set::new();
73 s2.insert(2);
74 assert_ne!(s1, s2);
75 }
76
77 #[test]
78 fn compares_sets_with_char_elements() {
79 let mut s1: Set<char, 2> = Set::new();
80 s1.insert('a');
81 s1.insert('b');
82 let mut s2: Set<char, 3> = Set::new();
83 s2.insert('a');
84 s2.insert('b');
85 assert_eq!(s1, s2);
86 }
87}