From 4c87ed57e95ab6635665642351a24194e383eeab Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 8 May 2026 18:49:03 +0500 Subject: [PATCH 01/12] test: get score for second frame --- tests/test_game.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index c31db3d..e22a891 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -108,4 +108,15 @@ TEST(GameTest, ScoreWithStrike) { EXPECT_EQ(game.score(), 0); game.roll(4); EXPECT_EQ(game.score(), 24); +} + +TEST(GameTest, SecondFrameScore) { + Game game; + game.roll(0); + game.roll(2); + game.roll(3); + game.roll(5); + for (int i = 0; i < 16; ++i) + game.roll(0); + EXPECT_EQ(game.frameScore(2), 8); } \ No newline at end of file From edd89ec6f8c895b1432165c30f19866e54d2b76b Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 8 May 2026 18:50:12 +0500 Subject: [PATCH 02/12] feat: add frameScore stub --- includes/game.h | 1 + sources/game.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/game.h b/includes/game.h index a118040..6a25937 100644 --- a/includes/game.h +++ b/includes/game.h @@ -9,6 +9,7 @@ class Game { public: void roll(int pins); int score() const; + int frameScore(int frame) const; }; #endif \ No newline at end of file diff --git a/sources/game.cpp b/sources/game.cpp index a6193a0..70ceba0 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -47,4 +47,6 @@ int Game::score() const { } return total; -} \ No newline at end of file +} + +int Game::frameScore(int frame) const { return 8; } \ No newline at end of file From 05ac3ec98f87eb5eeb5503969dfaf867839fef2c Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 8 May 2026 19:12:46 +0500 Subject: [PATCH 03/12] feat: get frame score of default frame --- sources/game.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sources/game.cpp b/sources/game.cpp index 70ceba0..21ac069 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -49,4 +49,14 @@ int Game::score() const { return total; } -int Game::frameScore(int frame) const { return 8; } \ No newline at end of file +int Game::frameScore(int frame) const { + int rollIndex = 0; + + for (int f = 1; f < frame; ++f) { + if (rollIndex >= rolls.size()) + return 0; + rollIndex += 2; + } + + return rolls[rollIndex] + rolls[rollIndex + 1]; +} \ No newline at end of file From c7551f330c0ad0020690a07514ec92320629e7d5 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 8 May 2026 19:14:53 +0500 Subject: [PATCH 04/12] test: frame score with strike --- tests/test_game.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index e22a891..e20e8c6 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -119,4 +119,15 @@ TEST(GameTest, SecondFrameScore) { for (int i = 0; i < 16; ++i) game.roll(0); EXPECT_EQ(game.frameScore(2), 8); +} + +TEST(GameTest, FrameScoreWithStrike) { + Game game; + game.roll(10); + game.roll(5); + game.roll(4); + + for (int i = 0; i < 17; ++i) + game.roll(0); + EXPECT_EQ(game.frameScore(1), 19); } \ No newline at end of file From 47c13c0bb9fdf522b22ea5ec886e2988ece3953d Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:04:07 +0500 Subject: [PATCH 05/12] feat: get frame score with strike --- sources/game.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sources/game.cpp b/sources/game.cpp index 21ac069..c717cc1 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -55,7 +55,19 @@ int Game::frameScore(int frame) const { for (int f = 1; f < frame; ++f) { if (rollIndex >= rolls.size()) return 0; - rollIndex += 2; + if (rolls[rollIndex] == 10) + rollIndex += 1; + else + rollIndex += 2; + } + + if (rollIndex >= rolls.size()) + return 0; + + if (rolls[rollIndex] == 10) { + if (rollIndex + 2 >= rolls.size()) + return 0; + return 10 + rolls[rollIndex + 1] + rolls[rollIndex + 2]; } return rolls[rollIndex] + rolls[rollIndex + 1]; From 3bfe4655df2feecf60f808291b5e295333424cfc Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:05:41 +0500 Subject: [PATCH 06/12] test: frame score with spare --- tests/test_game.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index e20e8c6..7958d3f 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -130,4 +130,14 @@ TEST(GameTest, FrameScoreWithStrike) { for (int i = 0; i < 17; ++i) game.roll(0); EXPECT_EQ(game.frameScore(1), 19); +} + +TEST(GameTest, FrameScoreWithSpare) { + Game game; + game.roll(6); + game.roll(4); + game.roll(5); + for (int i = 0; i < 17; ++i) + game.roll(0); + EXPECT_EQ(game.frameScore(1), 15); } \ No newline at end of file From 8266cdefae64a1b35fe4f9be256b332f91371726 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:07:36 +0500 Subject: [PATCH 07/12] feat: get frame score with spare --- sources/game.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sources/game.cpp b/sources/game.cpp index c717cc1..d683171 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -70,5 +70,14 @@ int Game::frameScore(int frame) const { return 10 + rolls[rollIndex + 1] + rolls[rollIndex + 2]; } + if (rollIndex + 1 >= rolls.size()) + return 0; + + if (rolls[rollIndex] + rolls[rollIndex + 1] == 10) { + if (rolls[rollIndex + 2] >= rolls.size()) + return 0; + return 10 + rolls[rollIndex + 2]; + } + return rolls[rollIndex] + rolls[rollIndex + 1]; } \ No newline at end of file From 7c7c74f6d623c14121c1679b2fd0d51103e8f14c Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:15:47 +0500 Subject: [PATCH 08/12] fix: calculating index of roll, not value --- sources/game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/game.cpp b/sources/game.cpp index d683171..33f9327 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -74,7 +74,7 @@ int Game::frameScore(int frame) const { return 0; if (rolls[rollIndex] + rolls[rollIndex + 1] == 10) { - if (rolls[rollIndex + 2] >= rolls.size()) + if (rollIndex + 2 >= rolls.size()) return 0; return 10 + rolls[rollIndex + 2]; } From d9359c8c99bb3434de5da04ba9cfda30c33ca809 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:16:29 +0500 Subject: [PATCH 09/12] test: frame score of tenth frame with strike (passed) --- tests/test_game.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index 7958d3f..265aa11 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -140,4 +140,14 @@ TEST(GameTest, FrameScoreWithSpare) { for (int i = 0; i < 17; ++i) game.roll(0); EXPECT_EQ(game.frameScore(1), 15); -} \ No newline at end of file +} + +TEST(GameTest, FrameScoreOfTenthFrameWithStrike) { + Game game; + for (int i = 0; i < 18; ++i) + game.roll(0); + game.roll(10); + game.roll(4); + game.roll(3); + EXPECT_EQ(game.frameScore(10), 17); +} From 9ee4297ddb04556a7bcdc93077091ef5490693ce Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:17:07 +0500 Subject: [PATCH 10/12] test: frame score of tenth frame with spare (passed) --- tests/test_game.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index 265aa11..0acd92c 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -151,3 +151,13 @@ TEST(GameTest, FrameScoreOfTenthFrameWithStrike) { game.roll(3); EXPECT_EQ(game.frameScore(10), 17); } + +TEST(GameTest, FrameScoreOfTenthFrameWithSpare) { + Game game; + for (int i = 0; i < 18; ++i) + game.roll(0); + game.roll(6); + game.roll(4); + game.roll(3); + EXPECT_EQ(game.frameScore(10), 13); +} \ No newline at end of file From 768fd1f75e025d1491c62400f4b6c1644de4bd32 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:19:10 +0500 Subject: [PATCH 11/12] test: frame score of tenth frame (passed) --- tests/test_game.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index 0acd92c..0dd730b 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -160,4 +160,13 @@ TEST(GameTest, FrameScoreOfTenthFrameWithSpare) { game.roll(4); game.roll(3); EXPECT_EQ(game.frameScore(10), 13); +} + +TEST(GameTest, FrameScoreOfTenthFrame) { + Game game; + for (int i = 0; i < 18; ++i) + game.roll(0); + game.roll(4); + game.roll(4); + EXPECT_EQ(game.frameScore(10), 8); } \ No newline at end of file From 5efa58c35f9121b410f0b53d0c9136cdfdad19d6 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 May 2026 15:21:32 +0500 Subject: [PATCH 12/12] test: frame score tenth frame incomplete with strike & frame score after strike (passed) --- tests/test_game.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index 0dd730b..b98c25c 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -169,4 +169,20 @@ TEST(GameTest, FrameScoreOfTenthFrame) { game.roll(4); game.roll(4); EXPECT_EQ(game.frameScore(10), 8); +} + +TEST(GameTest, FrameScoreAfterStrike) { + Game game; + game.roll(10); + game.roll(2); + game.roll(3); + EXPECT_EQ(game.frameScore(2), 5); +} + +TEST(GameTest, FrameScoreTenthFrameIncomplete) { + Game game; + for (int i = 0; i < 18; ++i) + game.roll(0); + game.roll(10); + EXPECT_EQ(game.frameScore(10), 0); } \ No newline at end of file