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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
pub mod cards;
pub mod hand;
#[cfg(test)]
mod tests {
use std::time::Instant;
use crate::hand;
use crate::hand::Hand;
use crate::cards;
use crate::cards::Card;
use crate::cards::Suit;
use crate::cards::Value;
#[test]
fn full_hand() {
print_hand(&hand::Hand::full_deck() )
}
#[test]
fn stack_top() {
let bottom = Hand::from(
vec![
Card::new(Value::Ace, Suit::Spade),
Card::new(Value::Two, Suit::Spade),
Card::new(Value::Three, Suit::Spade),
]
);
let top = Hand::from(
vec![
Card::new(Value::Jack, Suit::Spade),
Card::new(Value::Queen, Suit::Spade),
Card::new(Value::King, Suit::Spade),
]
);
let stacked = bottom.stack_top(top);
print_hand(&stacked)
}
#[test]
fn stack_bottom() {
let top = Hand::from(
vec![
Card::new(Value::Ace, Suit::Spade),
Card::new(Value::Two, Suit::Spade),
Card::new(Value::Three, Suit::Spade),
]
);
let bottom = Hand::from(
vec![
Card::new(Value::Four, Suit::Spade),
Card::new(Value::Five, Suit::Spade),
Card::new(Value::Six, Suit::Spade),
]
);
let stacked = top.stack_bottom(bottom);
print_hand(&stacked)
}
#[test]
fn insert() {
let mut h = Hand::from(
vec![
Card::new(Value::Ace, Suit::Spade),
Card::new(Value::Three, Suit::Spade),
Card::new(Value::Four, Suit::Spade),
]
);
h = h.insert(1, Card::new(Value::Two, Suit::Spade));
print_hand(&h)
}
#[test]
fn random_cards() {
let now = Instant::now();
for _i in 0..100 {
println!("{}", cards::Card::random().string())
}
println!("{} ms", now.elapsed().as_millis())
}
fn print_hand(hand: &hand::Hand) {
for card in &hand.vec {
println!("{}", card.string())
}
}
}