open_pql/base/
rank_idx.rs1use super::{Display, Hash, Rank};
2
3#[derive(
4 Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Display, Default,
5)]
6pub struct RankIdx(u8);
7
8#[allow(unused)]
9impl RankIdx {
10 pub(crate) const fn new(value: u8) -> Self {
12 Self(value)
13 }
14
15 pub(crate) const fn to_u8(self) -> u8 {
17 self.0
18 }
19
20 pub(crate) const fn to_usize(self) -> usize {
22 self.0 as usize
23 }
24
25 pub(crate) fn to_rank(self) -> Rank {
27 Rank::from_u8(self.0)
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34 use crate::*;
35
36 #[test]
37 fn test_rank_idx_new() {
38 let rank_idx = RankIdx::new(5);
39 assert_eq!(rank_idx.0, 5);
40 }
41
42 #[test]
43 fn test_rank_idx_to_u8() {
44 let rank_idx = RankIdx::new(7);
45 assert_eq!(rank_idx.to_u8(), 7);
46 }
47
48 #[test]
49 fn test_rank_idx_to_usize() {
50 let rank_idx = RankIdx::new(3);
51 assert_eq!(rank_idx.to_usize(), 3);
52 }
53
54 #[test]
55 fn test_rank_idx_to_rank() {
56 let rank_idx = RankIdx::new(12);
57 let rank = rank_idx.to_rank();
58 assert_eq!(rank, Rank::from_u8(12));
59 }
60
61 #[test]
62 fn test_rank_idx_default() {
63 let rank_idx = RankIdx::default();
64 assert_eq!(rank_idx.to_u8(), 0);
65 }
66
67 #[test]
68 fn test_rank_idx_ordering() {
69 let rank_idx1 = RankIdx::new(3);
70 let rank_idx2 = RankIdx::new(5);
71 let rank_idx3 = RankIdx::new(7);
72
73 assert!(rank_idx1 < rank_idx2);
74 assert!(rank_idx2 < rank_idx3);
75 assert!(rank_idx1 < rank_idx3);
76 }
77}