1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::fmt;
#[cfg(test)]
use super::hand_rank::PokerHandRank;
use crate::{evaluate::meta::Meta, EvalClass};
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Eval(pub(crate) Meta);
impl Eval {
pub const BEST: Self = Self(Meta::BEST);
pub const WORST: Self = Self(Meta::WORST);
#[cfg(test)]
pub(crate) const fn hand_rank(self) -> PokerHandRank { self.0.hand_rank() }
pub const fn class(self) -> EvalClass { self.0.class() }
pub const fn is_high_card(self) -> bool { self.0.is_high_card() }
pub const fn is_pair(self) -> bool { self.0.is_pair() }
pub const fn is_two_pair(self) -> bool { self.0.is_two_pair() }
pub const fn is_three_of_a_kind(self) -> bool { self.0.is_three_of_a_kind() }
pub const fn is_straight(self) -> bool { self.0.is_straight() }
pub const fn is_flush(self) -> bool { self.0.is_flush() }
pub const fn is_full_house(self) -> bool { self.0.is_full_house() }
pub const fn is_four_of_a_kind(self) -> bool { self.0.is_four_of_a_kind() }
pub const fn is_straight_flush(self) -> bool { self.0.is_straight_flush() }
pub const fn is_royal_flush(self) -> bool { self.0.is_royal_flush() }
}
impl fmt::Display for Eval {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn eval_best() {
let result = Eval::BEST;
assert!(result.is_straight_flush());
assert!(result.is_royal_flush());
assert_eq!(result.to_string(), "Royal flush");
}
#[test]
fn eval_worst() {
let result = Eval::WORST;
assert!(result.is_high_card());
assert_eq!(result.to_string(), "High card, seven");
}
}