forked from ProgrammingCCC/blackjack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
67 lines (55 loc) · 1.66 KB
/
test.cpp
File metadata and controls
67 lines (55 loc) · 1.66 KB
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
#include "utils.h"
#include "logic.hpp"
class BlackjackTestHarness : public AbstractTestHarness {
private:
int sum_test()
{
Blackjack b = Blackjack(17);
std::vector<Card> test_hand = { Card('K', 'S'), Card('4', 'H'), Card('A', 'C') };
return b.get_sum(test_hand);
}
bool shuffle_test()
{
Blackjack b = Blackjack(17);
bool shuffled = false;
for (size_t i = 0; i < b.size() - 2; ++i) {
if (b.get_deck(i)->get_at(0) != b.get_deck(i + 1)->get_at(0)) {
shuffled = true;
}
}
return shuffled;
}
bool presence_test()
{
Blackjack b = Blackjack(17);
std::vector<Card> test_hand = {};
bool decks_empty = true;
for (int i = 0; i < GAME_SIZE * DECK_SIZE; ++i) {
test_hand.push_back(b.take_random());
}
for (int i = 0; i < GAME_SIZE; ++i) {
if (!b.get_deck(i)->empty()) { decks_empty = false; }
}
return decks_empty;
}
public:
BlackjackTestHarness()
{
register_test_func("1: Summing Values",
[this]() -> void { assert_equal(25, sum_test()); });
register_test_func("2: Deck Shuffling",
[this]() -> void { assert_equal(true, shuffle_test()); });
register_test_func("3: Card Presence",
[this]() -> void { assert_equal(true, presence_test()); });
}
};
class GlobalTestManager : public TestManager {
public:
GlobalTestManager() { add_test("Blackjack Tests", BlackjackTestHarness()); }
};
int main()
{
srand(time(NULL));
auto tr = GlobalTestManager();
tr.execute();
}