From 2b3fb7f57a043a9d8aab6a5e78802caee522def8 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 7 May 2026 17:25:02 +0500 Subject: [PATCH 1/2] test: spare calculating scenario --- tests/test_game.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index 901420a..bf73c5e 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -48,4 +48,15 @@ TEST(GameTest, TripleStrike) { for (int i = 0; i < 16; i++) game.roll(0); EXPECT_EQ(game.score(), 86); +} + +TEST(GameTest, Spare) { + Game game; + game.roll(7); + game.roll(3); + game.roll(4); + game.roll(2); + for (int i = 0; i < 16; i++) + game.roll(0); + EXPECT_EQ(game.score(), 20); } \ No newline at end of file From 3f7ee76fb299cc3411ad81445563c732a3187c35 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 7 May 2026 17:27:26 +0500 Subject: [PATCH 2/2] feat: calculating spare and next one after --- sources/game.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sources/game.cpp b/sources/game.cpp index 0ee7b67..2f33bee 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -9,6 +9,9 @@ int Game::score() const { if (rolls[rollIndex] == 10) { total += 10 + rolls[rollIndex + 1] + rolls[rollIndex + 2]; rollIndex++; + } else if (rolls[rollIndex] + rolls[rollIndex + 1] == 10) { + total += 10 + rolls[rollIndex + 2]; + rollIndex += 2; } else { total += rolls[rollIndex] + rolls[rollIndex + 1]; rollIndex += 2;