-
Notifications
You must be signed in to change notification settings - Fork 0
/
bowling_game_test_gtest.cpp
89 lines (73 loc) · 2.02 KB
/
bowling_game_test_gtest.cpp
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
#include "bowling_game.hpp"
#include "gtest/gtest.h"
namespace my {
namespace project {
namespace {
// The fixture for testing class bowling_game.
class bowling_game_test : public ::testing::Test {
protected:
// You can remove any or all of the following functions if their bodies would
// be empty.
bowling_game_test() {
// You can do set-up work for each test here.
}
~bowling_game_test() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
}
// Class members declared here can be used by all tests in the test suite
// for bowling_game.
static void roll_many(bowling_game* pGame, int n, int pins){
int i;
for(i=0; i<n; i++){
pGame->roll(pins);
}
}
};
TEST_F(bowling_game_test, gutter_game) {
bowling_game game;
roll_many(&game, 20, 0);
EXPECT_EQ(0, game.score());
}
TEST_F(bowling_game_test, all_ones) {
bowling_game game;
roll_many(&game, 20, 1);
EXPECT_EQ(20, game.score());
}
TEST_F(bowling_game_test, one_spare) {
bowling_game game;
game.roll(5);
game.roll(5); /* spare */
game.roll(3);
roll_many(&game, 17, 0);
EXPECT_EQ(16, game.score());
}
TEST_F(bowling_game_test, one_strike) {
bowling_game game;
game.roll(10);
game.roll(3);
game.roll(4);
roll_many(&game, 16, 0);
EXPECT_EQ(24, game.score());
}
TEST_F(bowling_game_test, perfect_game) {
bowling_game game;
roll_many(&game, 12, 10);
EXPECT_EQ(300, game.score());
}
} // namespace
} // namespace project
} // namespace my
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}