diff --git a/includes/game.h b/includes/game.h index 3e902e8..a118040 100644 --- a/includes/game.h +++ b/includes/game.h @@ -1,7 +1,11 @@ #ifndef GAME_H #define GAME_H +#include + class Game { + std::vector rolls; + public: void roll(int pins); int score() const; diff --git a/sources/game.cpp b/sources/game.cpp index 78cb1aa..3badeeb 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -1,5 +1,13 @@ #include "../includes/game.h" -void Game::roll(int pins) {}; +void Game::roll(int pins) { rolls.push_back(pins); }; -int Game::score() const { return 0; } \ No newline at end of file +int Game::score() const { + int total; + + for (int roll : rolls) { + total += roll; + } + + return total; +} \ No newline at end of file diff --git a/tests/test_game.cpp b/tests/test_game.cpp index 0d2b828..933c058 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -6,4 +6,11 @@ TEST(GameTest, GutterGame) { for (int i = 0; i < 20; i++) game.roll(0); EXPECT_EQ(game.score(), 0); +} + +TEST(GameTest, AllOnes) { + Game game; + for (int i = 0; i < 20; i++) + game.roll(1); + EXPECT_EQ(game.score(), 20); } \ No newline at end of file