From e1d03f3b3ec10828c4eceb36ff015ca06bf6b5ec Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 6 May 2026 16:02:53 +0500 Subject: [PATCH 1/2] test: every throw equal one point --- tests/test_game.cpp | 7 +++++++ 1 file changed, 7 insertions(+) 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 From 8f19118de7fe68d03b047f93031efdbee2c2e8ac Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 6 May 2026 16:13:27 +0500 Subject: [PATCH 2/2] feat: added total score functional, rolls collecting every roll --- includes/game.h | 4 ++++ sources/game.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) 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