Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nishizaki
committed
Nov 12, 2022
1 parent
ed43bb6
commit be0879a
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
cxx_cmake_ninja/lib/bowling_game/test/gtest/bowling_game_test_gtest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} |