From 3b557e07ac97786fe2323128494470d7c2926363 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Wed, 24 May 2023 10:31:56 +0100 Subject: [PATCH 01/18] Project setup --- .rspec | 1 + Gemfile | 7 ++++ Gemfile.lock | 26 ++++++++++++ spec/spec_helper.rb | 98 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..c99d2e73 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..41df210d --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" + +gem "rspec", "~> 3.12" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..7f340830 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,26 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.5.0) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + rspec (~> 3.12) + +BUNDLED WITH + 2.4.13 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..c80d44b9 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,98 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From 931c7c84097115b035d04dcba884abdc856185e4 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Wed, 24 May 2023 19:50:43 +0100 Subject: [PATCH 02/18] test-driving Frame class --- lib/frame.rb | 39 ++++++++++++ lib/score_card.rb | 11 ++++ spec/frame_spec.rb | 96 +++++++++++++++++++++++++++++ spec/score_card_integration_spec.rb | 17 +++++ 4 files changed, 163 insertions(+) create mode 100644 lib/frame.rb create mode 100644 lib/score_card.rb create mode 100644 spec/frame_spec.rb create mode 100644 spec/score_card_integration_spec.rb diff --git a/lib/frame.rb b/lib/frame.rb new file mode 100644 index 00000000..4ac086f3 --- /dev/null +++ b/lib/frame.rb @@ -0,0 +1,39 @@ +class Frame + attr_accessor :rolls, :bonus_score + + def initialize + @rolls = [] + @frame_score = 0 + @bonus_score = 0 + @total_score = 0 + end + + # Methods for frame-specific behavior, such as calculating frame score, tracking strikes/spares, etc. + def add_roll(pins) + fail "A frame may only contain up to three rolls" if @rolls.length == 3 + + @rolls << pins + end + + def calculate_frame_score + @rolls.each do |roll| + @frame_score += roll + end + + return @frame_score + end + + def calculate_total_score + @total_score = calculate_frame_score + @bonus_score + + return @total_score + end + + def is_strike? + @rolls[0] == 10 + end + + def is_spare? + (@rolls[0] + @rolls[1]) == 10 + end +end \ No newline at end of file diff --git a/lib/score_card.rb b/lib/score_card.rb new file mode 100644 index 00000000..3d5e5f7a --- /dev/null +++ b/lib/score_card.rb @@ -0,0 +1,11 @@ +require 'frame' + +class ScoreCard + def initialize + @frames = [] + # Initialize ten frames? + # 10.times { @frames << Frame.new } + end + + # Methods to interact with frames and rolls +end diff --git a/spec/frame_spec.rb b/spec/frame_spec.rb new file mode 100644 index 00000000..b2621bcc --- /dev/null +++ b/spec/frame_spec.rb @@ -0,0 +1,96 @@ +require 'frame' + +RSpec.describe Frame do + context '#rolls' do + it 'initializes with an empty rolls array' do + frame = Frame.new + + expect(frame.rolls).to eq [] + end + end + + context '#add_rolls' do + it 'adds up to three rolls to the array' do + frame = Frame.new + + frame.add_roll(1) + frame.add_roll(1) + frame.add_roll(1) + + expect(frame.rolls).to eq [1, 1, 1] + end + + it 'throws error when a fourth add_roll attempted' do + frame = Frame.new + + frame.add_roll(1) + frame.add_roll(1) + frame.add_roll(1) + + expect{frame.add_roll(1)}.to raise_error "A frame may only contain up to three rolls" + end + end + + context '#calculate_frame_score' do + it 'returns 0 when rolls = [0, 0]' do + frame = Frame.new + + frame.add_roll(0) + frame.add_roll(0) + + expect(frame.calculate_frame_score).to eq 0 + end + + it 'returns 5 when rolls = [2, 3]' do + frame = Frame.new + + frame.add_roll(2) + frame.add_roll(3) + + expect(frame.calculate_frame_score).to eq 5 + end + end + + context '#calculate_total_score' do + it 'returns 0 when calculate_frame_score and bonus_score are 0' do + frame = Frame.new + + frame.add_roll(0) + frame.add_roll(0) + + expect(frame.calculate_total_score).to eq 0 + end + + it 'returns 10 when calculate_frame_score is 9 and bonus_score is 1' do + frame = Frame.new + + frame.add_roll(8) + frame.add_roll(1) + + frame.bonus_score = 1 + + expect(frame.calculate_total_score).to eq 10 + end + end + + context '#is_strike?' do + it 'returns true when first roll = 10' do + frame = Frame.new + + frame.add_roll(10) + + expect(frame.is_strike?).to eq true + end + end + + context '#is_spare?' do + it 'returns true when sum of first two rolls = 10' do + frame = Frame.new + + frame.add_roll(9) + frame.add_roll(1) + + expect(frame.is_strike?).to eq true + end + end +end \ No newline at end of file diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb new file mode 100644 index 00000000..9d339421 --- /dev/null +++ b/spec/score_card_integration_spec.rb @@ -0,0 +1,17 @@ +require 'frame' +require 'score_card' + +RSpec.describe 'integration' do + xit 'returns game score of 0 for a Gutter Game' do + # score_card = ScoreCard.new + + + # result = score_card.game_score + + # expect(result).to eq(0) + end + + xit 'returns game score of 300 for a Perfect Game' do + + end +end \ No newline at end of file From 1cd89d9b61fa23622e3f1c6c8c0e13c2615ce179 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Wed, 24 May 2023 21:49:37 +0100 Subject: [PATCH 03/18] test-drove Frame class with #is_strike? and #is_spare? --- lib/frame.rb | 5 ++--- spec/frame_spec.rb | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index 4ac086f3..3f0d4bff 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -8,7 +8,6 @@ def initialize @total_score = 0 end - # Methods for frame-specific behavior, such as calculating frame score, tracking strikes/spares, etc. def add_roll(pins) fail "A frame may only contain up to three rolls" if @rolls.length == 3 @@ -34,6 +33,6 @@ def is_strike? end def is_spare? - (@rolls[0] + @rolls[1]) == 10 + (@rolls.length == 2) && (@rolls[0] + @rolls[1] == 10) end -end \ No newline at end of file +end diff --git a/spec/frame_spec.rb b/spec/frame_spec.rb index b2621bcc..5b556175 100644 --- a/spec/frame_spec.rb +++ b/spec/frame_spec.rb @@ -87,10 +87,31 @@ it 'returns true when sum of first two rolls = 10' do frame = Frame.new + frame.add_roll(5) + frame.add_roll(5) + + expect(frame.calculate_total_score).to eq 10 + expect(frame.is_spare?).to eq true + end + + it 'returns false when sum correct but only one roll' do + frame = Frame.new + + frame.add_roll(10) + + expect(frame.calculate_total_score).to eq 10 + expect(frame.is_spare?).to eq false + end + + it 'returns false when sum correct but three rolls' do + frame = Frame.new + frame.add_roll(9) frame.add_roll(1) + frame.add_roll(0) - expect(frame.is_strike?).to eq true + expect(frame.calculate_total_score).to eq 10 + expect(frame.is_spare?).to eq false end end end \ No newline at end of file From 3a9e336203216fd26e7499e1c5bb1c9ed1fceda1 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Thu, 25 May 2023 10:16:20 +0100 Subject: [PATCH 04/18] test-drove basic zero return for Gutter Game --- lib/score_card.rb | 4 ++++ spec/score_card_integration_spec.rb | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/score_card.rb b/lib/score_card.rb index 3d5e5f7a..585f9bbc 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -5,7 +5,11 @@ def initialize @frames = [] # Initialize ten frames? # 10.times { @frames << Frame.new } + @game_score = 0 end # Methods to interact with frames and rolls + def game_score + return @game_score + end end diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 9d339421..ff6fc86d 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -2,13 +2,10 @@ require 'score_card' RSpec.describe 'integration' do - xit 'returns game score of 0 for a Gutter Game' do - # score_card = ScoreCard.new - + it 'returns game score of 0 for a Gutter Game' do + score_card = ScoreCard.new - # result = score_card.game_score - - # expect(result).to eq(0) + expect(score_card.game_score).to eq(0) end xit 'returns game score of 300 for a Perfect Game' do From 30918f3394b3e1e412312577f5113c4ace1d656c Mon Sep 17 00:00:00 2001 From: wimdavies Date: Fri, 26 May 2023 15:33:49 +0100 Subject: [PATCH 05/18] Test-drove frame naming, marking standard frames complete, ten frame limit, basic roll adding --- lib/frame.rb | 5 ++- lib/score_card.rb | 24 +++++++++-- spec/score_card_integration_spec.rb | 65 +++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index 3f0d4bff..0206542c 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -1,11 +1,14 @@ class Frame - attr_accessor :rolls, :bonus_score + attr_reader :rolls, :frame_score + attr_accessor :frame_number, :bonus_score, :complete def initialize + @frame_number = 0 @rolls = [] @frame_score = 0 @bonus_score = 0 @total_score = 0 + @complete = false end def add_roll(pins) diff --git a/lib/score_card.rb b/lib/score_card.rb index 585f9bbc..0bee6edd 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -1,15 +1,31 @@ require 'frame' class ScoreCard + attr_reader :frames + def initialize @frames = [] - # Initialize ten frames? - # 10.times { @frames << Frame.new } @game_score = 0 end - # Methods to interact with frames and rolls - def game_score + def add_frame + fail "A game may only consist of 10 frames" if @frames.length == 10 + + frame = Frame.new + frame.frame_number = @frames.length + 1 + + @frames << frame + end + + def roll_current_frame(pins) + @frames[0].add_roll(pins) + + @frames[0].complete = true if @frames[0].rolls.length == 2 || @frames[0].rolls[0] == 10 + end + + def calculate_game_score return @game_score end + + end diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index ff6fc86d..bd7b6b12 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -2,10 +2,69 @@ require 'score_card' RSpec.describe 'integration' do - it 'returns game score of 0 for a Gutter Game' do + it 'initializes with game score of 0' do score_card = ScoreCard.new - - expect(score_card.game_score).to eq(0) + + expect(score_card.calculate_game_score).to eq(0) + end + + it 'ScoreCard can make new frames with the correct frame_number' do + score_card = ScoreCard.new + + score_card.add_frame + expect(score_card.frames.length).to eq 1 + expect(score_card.frames[0].frame_number).to eq 1 + + score_card.add_frame + expect(score_card.frames.length).to eq 2 + expect(score_card.frames[1].frame_number).to eq 2 + end + + it 'ScoreCard can enter "standard" rolls into the first frame' do + score_card = ScoreCard.new + + score_card.add_frame + score_card.roll_current_frame(5) + score_card.roll_current_frame(2) + + expect(score_card.frames[0].rolls).to eq [5, 2] + expect(score_card.frames[0].calculate_frame_score).to eq 7 + end + + it 'ScoreCard marks a "standard" frame completed after two non-strike rolls' do + score_card = ScoreCard.new + + score_card.add_frame + score_card.roll_current_frame(5) + expect(score_card.frames[0].complete).to eq false + + + score_card.roll_current_frame(2) + expect(score_card.frames[0].complete).to eq true + end + + it 'ScoreCard marks a "standard" frame complete after a single strike' do + score_card = ScoreCard.new + + score_card.add_frame + score_card.roll_current_frame(10) + + expect(score_card.frames[0].is_strike?).to eq true + expect(score_card.frames[0].complete).to eq true + end + + it 'ScoreCard will fail when an eleven frame is attempted' do + score_card = ScoreCard.new + + 10.times { score_card.add_frame } + + expect{score_card.add_frame}.to raise_error "A game may only consist of 10 frames" + end + + xit 'returns game score of 0 for a Gutter Game' do + score_card = ScoreCard.new + # some method calls + expect(score_card.calculate_game_score).to eq(0) end xit 'returns game score of 300 for a Perfect Game' do From f611c5b754ca20f5fe24e45d37ead0cca82ff027 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Fri, 26 May 2023 22:09:07 +0100 Subject: [PATCH 06/18] major rework from ScoreCard#add_roll to #init with 10 numbered frames; reworked fails into Frame; testdrove current_frame_index & complete interaction; rudimentary game score calculation --- .gitignore | 1 + lib/frame.rb | 5 +- lib/score_card.rb | 30 +++++---- spec/frame_spec.rb | 32 +++++----- spec/score_card_integration_spec.rb | 99 ++++++++++++++++++++--------- 5 files changed, 106 insertions(+), 61 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5ae7ed87 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +scratchpad.rb diff --git a/lib/frame.rb b/lib/frame.rb index 0206542c..dc670eed 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -12,7 +12,8 @@ def initialize end def add_roll(pins) - fail "A frame may only contain up to three rolls" if @rolls.length == 3 + fail 'Only the tenth frame may consist of more than two rolls' if @frame_number < 10 && @rolls.length == 2 + fail 'The tenth frame may consist of no more than three rolls' if @frame_number == 10 && @rolls.length == 3 @rolls << pins end @@ -32,7 +33,7 @@ def calculate_total_score end def is_strike? - @rolls[0] == 10 + @rolls[0] == 10 end def is_spare? diff --git a/lib/score_card.rb b/lib/score_card.rb index 0bee6edd..de274ff8 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -1,29 +1,35 @@ -require 'frame' +require_relative 'frame' class ScoreCard - attr_reader :frames + attr_reader :frames, :current_frame_index def initialize @frames = [] + @current_frame_index = 0 @game_score = 0 - end - - def add_frame - fail "A game may only consist of 10 frames" if @frames.length == 10 - - frame = Frame.new - frame.frame_number = @frames.length + 1 - @frames << frame + 10.times do + frame = Frame.new + frame.frame_number = @frames.length + 1 + @frames << frame + end end def roll_current_frame(pins) - @frames[0].add_roll(pins) + @frames[@current_frame_index].add_roll(pins) - @frames[0].complete = true if @frames[0].rolls.length == 2 || @frames[0].rolls[0] == 10 + if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].rolls[0] == 10 + @frames[@current_frame_index].complete = true + end + + @current_frame_index += 1 if @frames[@current_frame_index].complete == true end def calculate_game_score + @frames.each do |frame| + @game_score += frame.calculate_frame_score + end + return @game_score end diff --git a/spec/frame_spec.rb b/spec/frame_spec.rb index 5b556175..a8905689 100644 --- a/spec/frame_spec.rb +++ b/spec/frame_spec.rb @@ -10,24 +10,34 @@ end context '#add_rolls' do - it 'adds up to three rolls to the array' do + it 'adds rolls to the array' do frame = Frame.new - frame.add_roll(1) frame.add_roll(1) frame.add_roll(1) - expect(frame.rolls).to eq [1, 1, 1] + expect(frame.rolls).to eq [1, 1] end - it 'throws error when a fourth add_roll attempted' do + it 'fails when adding a third roll to a non-tenth frame' do frame = Frame.new + + frame.frame_number = 1 + frame.add_roll(1) + frame.add_roll(1) + + expect{frame.add_roll(1)}.to raise_error 'Only the tenth frame may consist of more than two rolls' + end + it 'fails when a fourth add_roll attempted on tenth frame' do + frame = Frame.new + + frame.frame_number = 10 frame.add_roll(1) frame.add_roll(1) frame.add_roll(1) - expect{frame.add_roll(1)}.to raise_error "A frame may only contain up to three rolls" + expect{frame.add_roll(1)}.to raise_error 'The tenth frame may consist of no more than three rolls' end end @@ -77,6 +87,7 @@ it 'returns true when first roll = 10' do frame = Frame.new + frame.frame_number = 2 frame.add_roll(10) expect(frame.is_strike?).to eq true @@ -102,16 +113,5 @@ expect(frame.calculate_total_score).to eq 10 expect(frame.is_spare?).to eq false end - - it 'returns false when sum correct but three rolls' do - frame = Frame.new - - frame.add_roll(9) - frame.add_roll(1) - frame.add_roll(0) - - expect(frame.calculate_total_score).to eq 10 - expect(frame.is_spare?).to eq false - end end end \ No newline at end of file diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index bd7b6b12..3016522d 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -2,39 +2,35 @@ require 'score_card' RSpec.describe 'integration' do - it 'initializes with game score of 0' do + it 'ScoreCard initializes with 10 frames, correctly numbered' do score_card = ScoreCard.new - - expect(score_card.calculate_game_score).to eq(0) - end - - it 'ScoreCard can make new frames with the correct frame_number' do - score_card = ScoreCard.new - - score_card.add_frame - expect(score_card.frames.length).to eq 1 - expect(score_card.frames[0].frame_number).to eq 1 - - score_card.add_frame - expect(score_card.frames.length).to eq 2 - expect(score_card.frames[1].frame_number).to eq 2 + + expect(score_card.frames.length).to eq(10) + expect(score_card.frames[0].frame_number).to eq(1) + expect(score_card.frames[1].frame_number).to eq(2) + expect(score_card.frames[2].frame_number).to eq(3) + expect(score_card.frames[3].frame_number).to eq(4) + expect(score_card.frames[4].frame_number).to eq(5) + expect(score_card.frames[5].frame_number).to eq(6) + expect(score_card.frames[6].frame_number).to eq(7) + expect(score_card.frames[7].frame_number).to eq(8) + expect(score_card.frames[8].frame_number).to eq(9) + expect(score_card.frames[9].frame_number).to eq(10) end - - it 'ScoreCard can enter "standard" rolls into the first frame' do + + it 'can enter "standard" rolls into the first frame' do score_card = ScoreCard.new - - score_card.add_frame + score_card.roll_current_frame(5) score_card.roll_current_frame(2) - + expect(score_card.frames[0].rolls).to eq [5, 2] expect(score_card.frames[0].calculate_frame_score).to eq 7 end - - it 'ScoreCard marks a "standard" frame completed after two non-strike rolls' do + + it 'marks a "standard" frame completed after two non-strike rolls' do score_card = ScoreCard.new - score_card.add_frame score_card.roll_current_frame(5) expect(score_card.frames[0].complete).to eq false @@ -43,31 +39,72 @@ expect(score_card.frames[0].complete).to eq true end - it 'ScoreCard marks a "standard" frame complete after a single strike' do + it 'marks a "standard" frame complete after a single strike' do score_card = ScoreCard.new - score_card.add_frame score_card.roll_current_frame(10) expect(score_card.frames[0].is_strike?).to eq true expect(score_card.frames[0].complete).to eq true end - it 'ScoreCard will fail when an eleven frame is attempted' do + it 'updates the current frame index correctly after frame is completed' do score_card = ScoreCard.new - 10.times { score_card.add_frame } + score_card.roll_current_frame(10) - expect{score_card.add_frame}.to raise_error "A game may only consist of 10 frames" + expect(score_card.current_frame_index).to eq 1 end - xit 'returns game score of 0 for a Gutter Game' do + it 'can enter subsequent rolls into correct "regular" frames' do score_card = ScoreCard.new - # some method calls + + score_card.roll_current_frame(2) + score_card.roll_current_frame(2) + expect(score_card.frames[0].complete).to eq true + expect(score_card.current_frame_index).to eq 1 + + score_card.roll_current_frame(5) + score_card.roll_current_frame(2) + + expect(score_card.frames[1].rolls).to eq [5, 2] + expect(score_card.frames[1].calculate_frame_score).to eq 7 + expect(score_card.current_frame_index).to eq 2 + end + + it 'after strike, can enter subsequent rolls into correct "regular" frames' do + score_card = ScoreCard.new + + score_card.roll_current_frame(10) + expect(score_card.frames[0].complete).to eq true + expect(score_card.current_frame_index).to eq 1 + + score_card.roll_current_frame(5) + score_card.roll_current_frame(2) + expect(score_card.current_frame_index).to eq 2 + end + + it 'calculates game score of 0 for a Gutter Game' do + score_card = ScoreCard.new + + 20.times{ score_card.roll_current_frame(0) } + expect(score_card.calculate_game_score).to eq(0) end + it 'calculates game score of 90 when each roll is 1' do + score_card = ScoreCard.new + + 20.times{ score_card.roll_current_frame(1) } + + expect(score_card.calculate_game_score).to eq(20) + end + xit 'returns game score of 300 for a Perfect Game' do - + score_card = ScoreCard.new + + 21.times{ score_card.roll_current_frame(10) } + + expect(score_card.calculate_game_score).to eq(300) end end \ No newline at end of file From d28af4f657598ce0cdd9149678ac3ba9717fbe09 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Sat, 27 May 2023 13:27:09 +0100 Subject: [PATCH 07/18] testdrove #calculate_bonus_scores for spares on regular frames; major rework of frame#calculate method returns (and testing as a result) --- lib/frame.rb | 10 +++++--- lib/score_card.rb | 12 +++++++++ spec/frame_spec.rb | 27 +++++++++++-------- spec/score_card_integration_spec.rb | 40 ++++++++++++++++++++++++++--- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index dc670eed..08d7f374 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -1,5 +1,5 @@ class Frame - attr_reader :rolls, :frame_score + attr_reader :rolls, :frame_score, :total_score attr_accessor :frame_number, :bonus_score, :complete def initialize @@ -23,13 +23,15 @@ def calculate_frame_score @frame_score += roll end - return @frame_score + # return @frame_score end def calculate_total_score - @total_score = calculate_frame_score + @bonus_score + calculate_frame_score - return @total_score + @total_score = (@frame_score + @bonus_score) + + # return @total_score end def is_strike? diff --git a/lib/score_card.rb b/lib/score_card.rb index de274ff8..41814559 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -25,6 +25,18 @@ def roll_current_frame(pins) @current_frame_index += 1 if @frames[@current_frame_index].complete == true end + def calculate_bonus_scores + # for spares on regular frames + @frames.each_with_index do |frame, index| + next_frame = @frames[index + 1] + + if frame.is_spare? + + frame.bonus_score = next_frame.rolls[1] + end + end + end + def calculate_game_score @frames.each do |frame| @game_score += frame.calculate_frame_score diff --git a/spec/frame_spec.rb b/spec/frame_spec.rb index a8905689..35470af6 100644 --- a/spec/frame_spec.rb +++ b/spec/frame_spec.rb @@ -42,44 +42,49 @@ end context '#calculate_frame_score' do - it 'returns 0 when rolls = [0, 0]' do + it 'sets frame_score to 0 when rolls = [0, 0]' do frame = Frame.new frame.add_roll(0) frame.add_roll(0) + frame.calculate_frame_score - expect(frame.calculate_frame_score).to eq 0 + expect(frame.frame_score).to eq 0 end - it 'returns 5 when rolls = [2, 3]' do + it 'sets frame_score to 5 when rolls = [2, 3]' do frame = Frame.new frame.add_roll(2) frame.add_roll(3) + frame.calculate_frame_score - expect(frame.calculate_frame_score).to eq 5 + expect(frame.frame_score).to eq 5 end end context '#calculate_total_score' do - it 'returns 0 when calculate_frame_score and bonus_score are 0' do + it 'sets total_score to 0 when frame_score and bonus_score are 0' do frame = Frame.new frame.add_roll(0) frame.add_roll(0) + frame.calculate_frame_score + frame.calculate_total_score - expect(frame.calculate_total_score).to eq 0 + expect(frame.total_score).to eq 0 end - it 'returns 10 when calculate_frame_score is 9 and bonus_score is 1' do + it 'sets total_score to 10 when frame_score is 9 and bonus_score is 1' do frame = Frame.new frame.add_roll(8) frame.add_roll(1) frame.bonus_score = 1 + frame.calculate_total_score - expect(frame.calculate_total_score).to eq 10 + expect(frame.total_score).to eq 10 end end @@ -100,8 +105,9 @@ frame.add_roll(5) frame.add_roll(5) + frame.calculate_frame_score - expect(frame.calculate_total_score).to eq 10 + expect(frame.frame_score).to eq 10 expect(frame.is_spare?).to eq true end @@ -109,8 +115,9 @@ frame = Frame.new frame.add_roll(10) + frame.calculate_frame_score - expect(frame.calculate_total_score).to eq 10 + expect(frame.frame_score).to eq 10 expect(frame.is_spare?).to eq false end end diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 3016522d..884a9d58 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -23,9 +23,10 @@ score_card.roll_current_frame(5) score_card.roll_current_frame(2) + score_card.frames[0].calculate_frame_score expect(score_card.frames[0].rolls).to eq [5, 2] - expect(score_card.frames[0].calculate_frame_score).to eq 7 + expect(score_card.frames[0].frame_score).to eq 7 end it 'marks a "standard" frame completed after two non-strike rolls' do @@ -66,9 +67,10 @@ score_card.roll_current_frame(5) score_card.roll_current_frame(2) + score_card.frames[1].calculate_frame_score expect(score_card.frames[1].rolls).to eq [5, 2] - expect(score_card.frames[1].calculate_frame_score).to eq 7 + expect(score_card.frames[1].frame_score).to eq 7 expect(score_card.current_frame_index).to eq 2 end @@ -83,8 +85,38 @@ score_card.roll_current_frame(2) expect(score_card.current_frame_index).to eq 2 end + + it 'calculates the bonus score for a regular spare frame' do + score_card = ScoreCard.new + + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + expect(score_card.frames[0].is_spare?).to eq true + + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + expect(score_card.frames[0].bonus_score).to eq 1 + + score_card.frames[0].calculate_total_score + expect(score_card.frames[0].frame_score).to eq 10 + expect(score_card.frames[0].total_score).to eq 11 + end + + xit 'calculates the bonus score for a regular strike frame' do + + end + + xit 'calculates the bonus score for a tenth frame spare' do + + end + + xit 'calculates the bonus score for a tenth frame strike' do + + end - it 'calculates game score of 0 for a Gutter Game' do + xit 'calculates game score of 0 for a Gutter Game' do score_card = ScoreCard.new 20.times{ score_card.roll_current_frame(0) } @@ -92,7 +124,7 @@ expect(score_card.calculate_game_score).to eq(0) end - it 'calculates game score of 90 when each roll is 1' do + xit 'calculates game score of 90 when each roll is 1' do score_card = ScoreCard.new 20.times{ score_card.roll_current_frame(1) } From 545fcc3be8aa3b0688404cf6fc1b5032a4638014 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Sat, 27 May 2023 13:36:05 +0100 Subject: [PATCH 08/18] wrote test for bonus from ninth-frame spare. NB: bonuses only calculated after two rolls. Change this? --- spec/score_card_integration_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 884a9d58..7ad39243 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -104,6 +104,31 @@ expect(score_card.frames[0].total_score).to eq 11 end + it 'calculates the bonus score for a ninth spare frame' do + score_card = ScoreCard.new + + # 8 frames of zeros + 16.times do + score_card.roll_current_frame(0) + end + + # ninth frame is a spare + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + expect(score_card.frames[8].is_spare?).to eq true + + #rolls of tenth frame + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + expect(score_card.frames[8].bonus_score).to eq 1 + + score_card.frames[8].calculate_total_score + expect(score_card.frames[8].frame_score).to eq 10 + expect(score_card.frames[8].total_score).to eq 11 + end + xit 'calculates the bonus score for a regular strike frame' do end From bbf4f0b4a600e7eed8fb2098c8814900669fb49d Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 08:55:38 +0100 Subject: [PATCH 09/18] midway through test writing for strike bonuses: fixed error in #calculate_bonus_scores not caught by tests; updated tests to cover in future --- lib/score_card.rb | 10 ++++++++-- spec/score_card_integration_spec.rb | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/score_card.rb b/lib/score_card.rb index 41814559..20791730 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -18,21 +18,27 @@ def initialize def roll_current_frame(pins) @frames[@current_frame_index].add_roll(pins) + # handling completion + # TODO case when tenth frame if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].rolls[0] == 10 @frames[@current_frame_index].complete = true end - + # incrementing current_frame_index if completed @current_frame_index += 1 if @frames[@current_frame_index].complete == true end def calculate_bonus_scores # for spares on regular frames + # TODO spares on tenth + # TODO strikes on regular when next not strike + # TODO strikes on regular when next strike + # TODO strikes on tenth @frames.each_with_index do |frame, index| next_frame = @frames[index + 1] if frame.is_spare? - frame.bonus_score = next_frame.rolls[1] + frame.bonus_score = next_frame.rolls[0] end end end diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 7ad39243..95645903 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -94,7 +94,7 @@ expect(score_card.frames[0].is_spare?).to eq true score_card.roll_current_frame(1) - score_card.roll_current_frame(1) + score_card.roll_current_frame(2) score_card.calculate_bonus_scores expect(score_card.frames[0].bonus_score).to eq 1 @@ -129,7 +129,19 @@ expect(score_card.frames[8].total_score).to eq 11 end - xit 'calculates the bonus score for a regular strike frame' do + xit 'calculates the bonus score for a regular strike frame (when next roll not a strike)' do + score_card = ScoreCard.new + # frame 1 strike + score_card.roll_current_frame(10) + # frame 2 regular rolls + score_card.roll_current_frame(2) + score_card.roll_current_frame(3) + + + + end + + xit 'calculates the bonus score for a regular strike frame (when next roll is a strike)' do end From 6d61aa3220e45b42653b3f99be24a71168c35a1d Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 09:56:23 +0100 Subject: [PATCH 10/18] testdrove bonus score for both cases of regular frame strike --- lib/score_card.rb | 11 +++-- spec/score_card_integration_spec.rb | 63 ++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/lib/score_card.rb b/lib/score_card.rb index 20791730..de23f9a5 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -29,17 +29,22 @@ def roll_current_frame(pins) def calculate_bonus_scores # for spares on regular frames + # for strikes on regular when next not strike + # for strikes on regular when next strike # TODO spares on tenth - # TODO strikes on regular when next not strike - # TODO strikes on regular when next strike # TODO strikes on tenth @frames.each_with_index do |frame, index| next_frame = @frames[index + 1] + subsequent_frame = @frames[index + 2] if frame.is_spare? - frame.bonus_score = next_frame.rolls[0] + elsif frame.is_strike? && next_frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + subsequent_frame.rolls[0] + elsif frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] end + end end diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 95645903..8c786f7b 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -18,7 +18,7 @@ expect(score_card.frames[9].frame_number).to eq(10) end - it 'can enter "standard" rolls into the first frame' do + it 'can enter "regular" rolls into the first frame' do score_card = ScoreCard.new score_card.roll_current_frame(5) @@ -29,7 +29,7 @@ expect(score_card.frames[0].frame_score).to eq 7 end - it 'marks a "standard" frame completed after two non-strike rolls' do + it 'marks a "regular" frame completed after two non-strike rolls' do score_card = ScoreCard.new score_card.roll_current_frame(5) @@ -40,7 +40,16 @@ expect(score_card.frames[0].complete).to eq true end - it 'marks a "standard" frame complete after a single strike' do + it 'marks a "regular" frame complete after a single strike' do + score_card = ScoreCard.new + + score_card.roll_current_frame(10) + + expect(score_card.frames[0].is_strike?).to eq true + expect(score_card.frames[0].complete).to eq true + end + + it 'marks a "regular" frame complete after a single strike' do score_card = ScoreCard.new score_card.roll_current_frame(10) @@ -129,24 +138,58 @@ expect(score_card.frames[8].total_score).to eq 11 end - xit 'calculates the bonus score for a regular strike frame (when next roll not a strike)' do + it 'calculates the bonus score for a regular strike frame (when next roll not a strike)' do score_card = ScoreCard.new - # frame 1 strike + # frame 1: strike score_card.roll_current_frame(10) - # frame 2 regular rolls + # frame 2: two regular rolls scoring 5 score_card.roll_current_frame(2) score_card.roll_current_frame(3) + score_card.calculate_bonus_scores + # frame 1: bonus score of 5 + expect(score_card.frames[0].bonus_score).to eq 5 - + score_card.frames[0].calculate_total_score + expect(score_card.frames[0].frame_score).to eq 10 + expect(score_card.frames[0].total_score).to eq 15 end - xit 'calculates the bonus score for a regular strike frame (when next roll is a strike)' do - + it 'calculates the bonus score for a regular strike frame (when next roll is a strike)' do + score_card = ScoreCard.new + # frame 1 strike + score_card.roll_current_frame(10) + # frame 2 strike + score_card.roll_current_frame(10) + # frame 3 regular rolls + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + + expect(score_card.frames[0].bonus_score).to eq 11 + expect(score_card.frames[1].bonus_score).to eq 2 + + score_card.frames[0].calculate_total_score + expect(score_card.frames[0].frame_score).to eq 10 + expect(score_card.frames[0].total_score).to eq 21 + + score_card.frames[1].calculate_total_score + expect(score_card.frames[1].frame_score).to eq 10 + expect(score_card.frames[1].total_score).to eq 12 end xit 'calculates the bonus score for a tenth frame spare' do - + score_card = ScoreCard.new + + # 9 frames of zeros + 16.times do + score_card.roll_current_frame(0) + end + + score_card.roll_current_frame(10) + + expect(score_card) end xit 'calculates the bonus score for a tenth frame strike' do From 36d3b26118a21cbad9f4c8402502184ba66e6453 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 10:46:38 +0100 Subject: [PATCH 11/18] Testdrove Frame#is_spare? case for returning false when first roll is 10 (important for tenth frame) --- lib/frame.rb | 2 +- lib/score_card.rb | 15 +++++++-- spec/frame_spec.rb | 11 +++++++ spec/score_card_integration_spec.rb | 48 ++++++++++++++++++++++++----- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index 08d7f374..bdf9221a 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -39,6 +39,6 @@ def is_strike? end def is_spare? - (@rolls.length == 2) && (@rolls[0] + @rolls[1] == 10) + (@rolls.length == 2) && (@rolls[0] + @rolls[1] == 10) && @rolls[0] != 10 end end diff --git a/lib/score_card.rb b/lib/score_card.rb index de23f9a5..030250d6 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -20,9 +20,20 @@ def roll_current_frame(pins) # handling completion # TODO case when tenth frame - if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].rolls[0] == 10 - @frames[@current_frame_index].complete = true + case @frames[@current_frame_index].frame_number + when 10 + if @frames[@current_frame_index].is_spare? + + else + + end + + else + if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].rolls[0] == 10 + @frames[@current_frame_index].complete = true + end end + # incrementing current_frame_index if completed @current_frame_index += 1 if @frames[@current_frame_index].complete == true end diff --git a/spec/frame_spec.rb b/spec/frame_spec.rb index 35470af6..c0046a8a 100644 --- a/spec/frame_spec.rb +++ b/spec/frame_spec.rb @@ -120,5 +120,16 @@ expect(frame.frame_score).to eq 10 expect(frame.is_spare?).to eq false end + + it 'returns false when first roll 10 and second roll 0' do + frame = Frame.new + + frame.add_roll(10) + frame.add_roll(0) + frame.calculate_frame_score + + expect(frame.frame_score).to eq 10 + expect(frame.is_spare?).to eq false + end end end \ No newline at end of file diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 8c786f7b..b75449e2 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -35,7 +35,6 @@ score_card.roll_current_frame(5) expect(score_card.frames[0].complete).to eq false - score_card.roll_current_frame(2) expect(score_card.frames[0].complete).to eq true end @@ -48,14 +47,45 @@ expect(score_card.frames[0].is_strike?).to eq true expect(score_card.frames[0].complete).to eq true end + + it 'does not mark tenth frame complete after a spare' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + + score_card.roll_current_frame(9) + score_card.roll_current_frame(1) + expect(score_card.frames[9].complete).to eq false + end + + it 'marks tenth frame spare complete after bonus roll' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + + score_card.roll_current_frame(9) + score_card.roll_current_frame(1) + expect(score_card.frames[9].complete).to eq false + score_card.roll_current_frame(1) + expect(score_card.frames[9].complete).to eq true + end + + xit 'does not mark tenth frame complete after a single strike' do + end - it 'marks a "regular" frame complete after a single strike' do + xit 'does not mark tenth frame complete after two strikes' do score_card = ScoreCard.new - score_card.roll_current_frame(10) + + end - expect(score_card.frames[0].is_strike?).to eq true - expect(score_card.frames[0].complete).to eq true + xit 'marks tenth frame strike complete after two bonus rolls' do end it 'updates the current frame index correctly after frame is completed' do @@ -183,7 +213,7 @@ score_card = ScoreCard.new # 9 frames of zeros - 16.times do + 18.times do score_card.roll_current_frame(0) end @@ -192,7 +222,11 @@ expect(score_card) end - xit 'calculates the bonus score for a tenth frame strike' do + xit 'calculates the bonus score for a single tenth frame strike' do + + end + + xit 'calculates the bonus score for two tenth frame strikes' do end From fbe8f0ec14acac6655156311b37598ac717fe9d3 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 10:58:38 +0100 Subject: [PATCH 12/18] testdrove Frame#calculate_frame_score to account for bonus roll existence and tenth frame strikes --- lib/frame.rb | 7 +++++-- spec/frame_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index bdf9221a..01dc0580 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -19,8 +19,11 @@ def add_roll(pins) end def calculate_frame_score - @rolls.each do |roll| - @frame_score += roll + + if is_strike? + @frame_score = @rolls[0] + else + @frame_score = @rolls[0] + @rolls[1] end # return @frame_score diff --git a/spec/frame_spec.rb b/spec/frame_spec.rb index c0046a8a..6f7eaa1f 100644 --- a/spec/frame_spec.rb +++ b/spec/frame_spec.rb @@ -61,6 +61,30 @@ expect(frame.frame_score).to eq 5 end + + it 'sets frame_score to 10 when rolls = [1, 9, 5] (tenth frame issue)' do + frame = Frame.new + frame.frame_number = 10 + + frame.add_roll(1) + frame.add_roll(9) + frame.add_roll(5) + frame.calculate_frame_score + + expect(frame.frame_score).to eq 10 + end + + it 'sets frame_score to 10 when rolls = [10, 10, 10] (tenth frame issue)' do + frame = Frame.new + frame.frame_number = 10 + + frame.add_roll(10) + frame.add_roll(10) + frame.add_roll(10) + frame.calculate_frame_score + + expect(frame.frame_score).to eq 10 + end end context '#calculate_total_score' do From 6d766fdebb0aee542c10fa4e5de102eb105c70ce Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 15:45:39 +0100 Subject: [PATCH 13/18] big test-drive of completion conditions; refactored by extracting this into a method --- lib/frame.rb | 4 +- lib/score_card.rb | 44 ++++++++------- spec/score_card_integration_spec.rb | 84 +++++++++++++++++++++++++++-- 3 files changed, 107 insertions(+), 25 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index 01dc0580..15cbf721 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -38,10 +38,10 @@ def calculate_total_score end def is_strike? - @rolls[0] == 10 + @rolls[0] == 10 end def is_spare? - (@rolls.length == 2) && (@rolls[0] + @rolls[1] == 10) && @rolls[0] != 10 + @rolls.length > 1 && (@rolls[0] + @rolls[1]) == 10 && @rolls[0] != 10 end end diff --git a/lib/score_card.rb b/lib/score_card.rb index 030250d6..9acf07a6 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -17,25 +17,13 @@ def initialize def roll_current_frame(pins) @frames[@current_frame_index].add_roll(pins) - - # handling completion - # TODO case when tenth frame - case @frames[@current_frame_index].frame_number - when 10 - if @frames[@current_frame_index].is_spare? - - else - - end - - else - if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].rolls[0] == 10 - @frames[@current_frame_index].complete = true - end - end + mark_complete_on_conditions + # incrementing current_frame_index if completed - @current_frame_index += 1 if @frames[@current_frame_index].complete == true + if @current_frame_index < 9 && @frames[@current_frame_index].complete == true + @current_frame_index += 1 + end end def calculate_bonus_scores @@ -67,5 +55,25 @@ def calculate_game_score return @game_score end - + def mark_complete_on_conditions + # handling completion + case @current_frame_index + when 9 + frame = @frames[@current_frame_index] + + if frame.is_strike? || frame.is_spare? + if frame.rolls.length == 3 + frame.complete = true + end + else + if frame.rolls.length == 2 + frame.complete = true + end + end + else + if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].is_strike? + @frames[@current_frame_index].complete = true + end + end + end end diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index b75449e2..3a15ef7e 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -55,9 +55,15 @@ 18.times do score_card.roll_current_frame(0) end + expect(score_card.current_frame_index).to eq 9 score_card.roll_current_frame(9) score_card.roll_current_frame(1) + expect(score_card.current_frame_index).to eq 9 + expect(score_card.frames[score_card.current_frame_index].frame_number).to eq 10 + + expect(score_card.frames[9].is_spare?).to eq true + expect(score_card.frames[9].rolls.length).to eq 2 expect(score_card.frames[9].complete).to eq false end @@ -69,33 +75,101 @@ score_card.roll_current_frame(0) end + # tenth frame spare score_card.roll_current_frame(9) score_card.roll_current_frame(1) + expect(score_card.current_frame_index).to eq 9 + expect(score_card.frames[score_card.current_frame_index].frame_number).to eq 10 + expect(score_card.frames[9].is_spare?).to eq true expect(score_card.frames[9].complete).to eq false + + # tenth frame bonus roll score_card.roll_current_frame(1) + expect(score_card.current_frame_index).to eq 9 + expect(score_card.frames[score_card.current_frame_index].frame_number).to eq 10 + expect(score_card.frames[9].is_spare?).to eq true + expect(score_card.frames[9].rolls.length).to eq 3 expect(score_card.frames[9].complete).to eq true end - xit 'does not mark tenth frame complete after a single strike' do + it 'does not mark tenth frame complete after a single strike' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + + # tenth frame strike + score_card.roll_current_frame(10) + expect(score_card.current_frame_index).to eq 9 + expect(score_card.frames[score_card.current_frame_index].frame_number).to eq 10 + expect(score_card.frames[9].is_strike?).to eq true + expect(score_card.frames[9].is_spare?).to eq false + expect(score_card.frames[9].complete).to eq false end - xit 'does not mark tenth frame complete after two strikes' do + it 'does not mark tenth frame complete after two strikes' do score_card = ScoreCard.new - + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + + # tenth frame strikes + score_card.roll_current_frame(10) + # one bonus roll + score_card.roll_current_frame(10) + expect(score_card.current_frame_index).to eq 9 + expect(score_card.frames[score_card.current_frame_index].frame_number).to eq 10 + expect(score_card.frames[9].is_strike?).to eq true + expect(score_card.frames[9].is_spare?).to eq false + expect(score_card.frames[9].complete).to eq false end - xit 'marks tenth frame strike complete after two bonus rolls' do + it 'marks tenth frame strike complete after two bonus rolls' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + + # tenth frame strike + score_card.roll_current_frame(10) + # two bonus rolls + score_card.roll_current_frame(2) + score_card.roll_current_frame(3) + expect(score_card.current_frame_index).to eq 9 + expect(score_card.frames[score_card.current_frame_index].frame_number).to eq 10 + expect(score_card.frames[9].is_strike?).to eq true + expect(score_card.frames[9].is_spare?).to eq false + expect(score_card.frames[9].complete).to eq true end it 'updates the current frame index correctly after frame is completed' do score_card = ScoreCard.new - + score_card.roll_current_frame(10) expect(score_card.current_frame_index).to eq 1 end + it 'will not update the current frame index after tenth frame is completed' do + score_card = ScoreCard.new + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + + score_card.roll_current_frame(10) + score_card.roll_current_frame(10) + score_card.roll_current_frame(10) + + expect(score_card.current_frame_index).to eq 9 + end + it 'can enter subsequent rolls into correct "regular" frames' do score_card = ScoreCard.new From 81e30939524e10c61fd5ca8fa43d1dab0974645a Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 17:00:16 +0100 Subject: [PATCH 14/18] testdriving bonus scoring for ninth frame; game score test writing --- lib/frame.rb | 1 - lib/score_card.rb | 38 ++++++---- spec/score_card_integration_spec.rb | 110 +++++++++++++++++++++++++--- 3 files changed, 124 insertions(+), 25 deletions(-) diff --git a/lib/frame.rb b/lib/frame.rb index 15cbf721..d9640e03 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -19,7 +19,6 @@ def add_roll(pins) end def calculate_frame_score - if is_strike? @frame_score = @rolls[0] else diff --git a/lib/score_card.rb b/lib/score_card.rb index 9acf07a6..c3913ee8 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -27,36 +27,46 @@ def roll_current_frame(pins) end def calculate_bonus_scores - # for spares on regular frames - # for strikes on regular when next not strike - # for strikes on regular when next strike - # TODO spares on tenth - # TODO strikes on tenth @frames.each_with_index do |frame, index| next_frame = @frames[index + 1] subsequent_frame = @frames[index + 2] - if frame.is_spare? - frame.bonus_score = next_frame.rolls[0] - elsif frame.is_strike? && next_frame.is_strike? - frame.bonus_score = next_frame.rolls[0] + subsequent_frame.rolls[0] - elsif frame.is_strike? - frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] + case frame.frame_number + when 10 + if frame.is_spare? + frame.bonus_score = frame.rolls[2] + elsif frame.is_strike? + frame.bonus_score = frame.rolls[1] + frame.rolls[2] + end + when 9 + if frame.is_spare? + frame.bonus_score = next_frame.rolls[0] + elsif frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] + end + else + if frame.is_spare? + frame.bonus_score = next_frame.rolls[0] + elsif frame.is_strike? && next_frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + subsequent_frame.rolls[0] + elsif frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] + end end - end end def calculate_game_score + calculate_bonus_scores + @frames.each do |frame| - @game_score += frame.calculate_frame_score + frame.calculate_frame_score end return @game_score end def mark_complete_on_conditions - # handling completion case @current_frame_index when 9 frame = @frames[@current_frame_index] diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index 3a15ef7e..bc7868b2 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -283,28 +283,118 @@ expect(score_card.frames[1].total_score).to eq 12 end - xit 'calculates the bonus score for a tenth frame spare' do + it 'calculates the bonus score for a ninth frame spare' do + score_card = ScoreCard.new + + # 8 frames of zeros + 16.times do + score_card.roll_current_frame(0) + end + # 9th frame spare + score_card.roll_current_frame(9) + score_card.roll_current_frame(1) + # 10th frame rolls + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + + expect(score_card.frames[8].bonus_score).to eq 1 + end + + it 'calculates the bonus score for a ninth frame strike' do + score_card = ScoreCard.new + + # 8 frames of zeros + 16.times do + score_card.roll_current_frame(0) + end + # 9th frame strike + score_card.roll_current_frame(10) + # 10th frame rolls + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + + expect(score_card.frames[8].bonus_score).to eq 2 + end + + + it 'calculates the bonus score for a tenth frame spare' do score_card = ScoreCard.new # 9 frames of zeros 18.times do score_card.roll_current_frame(0) end + # 10th frame spare + score_card.roll_current_frame(9) + score_card.roll_current_frame(1) + # bonus roll + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + expect(score_card.frames[9].bonus_score).to eq 1 + end + + it 'calculates the bonus score for a tenth frame strike (regular bonus rolls)' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + # 10th frame strike score_card.roll_current_frame(10) + # bonus rolls + score_card.roll_current_frame(1) + score_card.roll_current_frame(1) - expect(score_card) + score_card.calculate_bonus_scores + + expect(score_card.frames[9].bonus_score).to eq 2 end - xit 'calculates the bonus score for a single tenth frame strike' do - + it 'calculates the bonus score for a tenth frame strike (bonus: one strike, one regular)' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + # 10th frame strike + score_card.roll_current_frame(10) + # bonus rolls + score_card.roll_current_frame(10) + score_card.roll_current_frame(1) + + score_card.calculate_bonus_scores + + expect(score_card.frames[9].bonus_score).to eq 11 end - xit 'calculates the bonus score for two tenth frame strikes' do - + it 'calculates the bonus score for a tenth frame strike (two bonus strikes)' do + score_card = ScoreCard.new + + # 9 frames of zeros + 18.times do + score_card.roll_current_frame(0) + end + # 10th frame strike + score_card.roll_current_frame(10) + # bonus rolls + score_card.roll_current_frame(10) + score_card.roll_current_frame(10) + + score_card.calculate_bonus_scores + + expect(score_card.frames[9].bonus_score).to eq 20 end - xit 'calculates game score of 0 for a Gutter Game' do + it 'calculates game score of 0 for a Gutter Game' do score_card = ScoreCard.new 20.times{ score_card.roll_current_frame(0) } @@ -312,7 +402,7 @@ expect(score_card.calculate_game_score).to eq(0) end - xit 'calculates game score of 90 when each roll is 1' do + it 'calculates game score of 90 when each roll is 1' do score_card = ScoreCard.new 20.times{ score_card.roll_current_frame(1) } @@ -320,10 +410,10 @@ expect(score_card.calculate_game_score).to eq(20) end - xit 'returns game score of 300 for a Perfect Game' do + it 'returns game score of 300 for a Perfect Game' do score_card = ScoreCard.new - 21.times{ score_card.roll_current_frame(10) } + 12.times{ score_card.roll_current_frame(10) } expect(score_card.calculate_game_score).to eq(300) end From f3da38ce651af836ce9428bbce21547998da1406 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 17:14:07 +0100 Subject: [PATCH 15/18] Major refactor of roll_current_frame, and bonus conditionals --- lib/score_card.rb | 80 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/score_card.rb b/lib/score_card.rb index c3913ee8..64f65992 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -16,14 +16,21 @@ def initialize end def roll_current_frame(pins) - @frames[@current_frame_index].add_roll(pins) - - mark_complete_on_conditions + frame = @frames[@current_frame_index] - # incrementing current_frame_index if completed - if @current_frame_index < 9 && @frames[@current_frame_index].complete == true - @current_frame_index += 1 + frame.add_roll(pins) + + if @current_frame_index == 9 + if frame.is_strike? || frame.is_spare? + frame.complete = frame.rolls.length == 3 + else + frame.complete = frame.rolls.length == 2 + end + else + frame.complete = frame.rolls.length == 2 || frame.is_strike? end + + @current_frame_index += 1 if @current_frame_index < 9 && frame.complete end def calculate_bonus_scores @@ -33,25 +40,11 @@ def calculate_bonus_scores case frame.frame_number when 10 - if frame.is_spare? - frame.bonus_score = frame.rolls[2] - elsif frame.is_strike? - frame.bonus_score = frame.rolls[1] + frame.rolls[2] - end + calculate_bonus_for_frame_10(frame) when 9 - if frame.is_spare? - frame.bonus_score = next_frame.rolls[0] - elsif frame.is_strike? - frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] - end + calculate_bonus_for_frame_9(frame, next_frame) else - if frame.is_spare? - frame.bonus_score = next_frame.rolls[0] - elsif frame.is_strike? && next_frame.is_strike? - frame.bonus_score = next_frame.rolls[0] + subsequent_frame.rolls[0] - elsif frame.is_strike? - frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] - end + calculate_bonus_for_other_frames(frame, next_frame, subsequent_frame) end end end @@ -66,24 +59,31 @@ def calculate_game_score return @game_score end - def mark_complete_on_conditions - case @current_frame_index - when 9 - frame = @frames[@current_frame_index] + private + + def calculate_bonus_for_frame_10(frame) + if frame.is_spare? + frame.bonus_score = frame.rolls[2] + elsif frame.is_strike? + frame.bonus_score = frame.rolls[1] + frame.rolls[2] + end + end - if frame.is_strike? || frame.is_spare? - if frame.rolls.length == 3 - frame.complete = true - end - else - if frame.rolls.length == 2 - frame.complete = true - end - end - else - if @frames[@current_frame_index].rolls.length == 2 || @frames[@current_frame_index].is_strike? - @frames[@current_frame_index].complete = true - end + def calculate_bonus_for_frame_9(frame, next_frame) + if frame.is_spare? + frame.bonus_score = next_frame.rolls[0] + elsif frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] + end + end + + def calculate_bonus_for_other_frames(frame, next_frame, subsequent_frame) + if frame.is_spare? + frame.bonus_score = next_frame.rolls[0] + elsif frame.is_strike? && next_frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + subsequent_frame.rolls[0] + elsif frame.is_strike? + frame.bonus_score = next_frame.rolls[0] + next_frame.rolls[1] end end end From 49e1771ab3e8483559a1962a9fc9e8842fc4a9f9 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 17:23:52 +0100 Subject: [PATCH 16/18] testdrove calculate_game_score method. Done --- lib/score_card.rb | 6 ++++- spec/score_card_integration_spec.rb | 36 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/score_card.rb b/lib/score_card.rb index 64f65992..1959c7e5 100644 --- a/lib/score_card.rb +++ b/lib/score_card.rb @@ -52,11 +52,15 @@ def calculate_bonus_scores def calculate_game_score calculate_bonus_scores + frame_totals = 0 @frames.each do |frame| frame.calculate_frame_score + frame.calculate_total_score + + frame_totals += frame.total_score end - return @game_score + return @game_score = frame_totals end private diff --git a/spec/score_card_integration_spec.rb b/spec/score_card_integration_spec.rb index bc7868b2..4249bd0e 100644 --- a/spec/score_card_integration_spec.rb +++ b/spec/score_card_integration_spec.rb @@ -410,6 +410,42 @@ expect(score_card.calculate_game_score).to eq(20) end + it 'calculates correct game score when an "average" game' do + score_card = ScoreCard.new + + score_card.roll_current_frame(5) + score_card.roll_current_frame(4) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(4) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + + score_card.roll_current_frame(10) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + + score_card.roll_current_frame(3) + score_card.roll_current_frame(5) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(4) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(4) + + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + score_card.roll_current_frame(5) + + expect(score_card.calculate_game_score).to eq(127) + end + it 'returns game score of 300 for a Perfect Game' do score_card = ScoreCard.new From 201d216c664f38fbcf63d5ed54ae4a208c7ecbb9 Mon Sep 17 00:00:00 2001 From: wimdavies Date: Mon, 29 May 2023 17:46:48 +0100 Subject: [PATCH 17/18] Added simplecov and cobertura --- Gemfile | 4 + Gemfile.lock | 13 + coverage/.last_run.json | 5 + coverage/.resultset.json | 773 ++++++++++++++++++++++++++++++++++ coverage/.resultset.json.lock | 0 coverage/coverage.xml | 478 +++++++++++++++++++++ lib/frame.rb | 4 - spec/spec_helper.rb | 6 + 8 files changed, 1279 insertions(+), 4 deletions(-) create mode 100644 coverage/.last_run.json create mode 100644 coverage/.resultset.json create mode 100644 coverage/.resultset.json.lock create mode 100644 coverage/coverage.xml diff --git a/Gemfile b/Gemfile index 41df210d..49590388 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,7 @@ source "https://rubygems.org" # gem "rails" gem "rspec", "~> 3.12" + +gem "simplecov", "~> 0.22.0" + +gem "simplecov-cobertura", "~> 2.1" diff --git a/Gemfile.lock b/Gemfile.lock index 7f340830..b4695496 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,8 @@ GEM remote: https://rubygems.org/ specs: diff-lcs (1.5.0) + docile (1.4.0) + rexml (3.2.5) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -15,12 +17,23 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-cobertura (2.1.0) + rexml + simplecov (~> 0.19) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) PLATFORMS arm64-darwin-22 DEPENDENCIES rspec (~> 3.12) + simplecov (~> 0.22.0) + simplecov-cobertura (~> 2.1) BUNDLED WITH 2.4.13 diff --git a/coverage/.last_run.json b/coverage/.last_run.json new file mode 100644 index 00000000..52d2bf29 --- /dev/null +++ b/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "line": 100.0 + } +} diff --git a/coverage/.resultset.json b/coverage/.resultset.json new file mode 100644 index 00000000..e372cbc8 --- /dev/null +++ b/coverage/.resultset.json @@ -0,0 +1,773 @@ +{ + "RSpec": { + "coverage": { + "/Users/wimdavies/Projects/bowling-challenge-ruby/spec/frame_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + null, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 2, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + 1, + null, + 2, + null, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + null, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + null, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + null, + 1, + null, + null, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + null, + null, + null + ] + }, + "/Users/wimdavies/Projects/bowling-challenge-ruby/lib/frame.rb": { + "lines": [ + 1, + 1, + 1, + null, + 1, + 284, + 284, + 284, + 284, + 284, + 284, + null, + null, + 1, + 391, + 390, + null, + 389, + null, + null, + 1, + 97, + 28, + null, + 69, + null, + null, + null, + 1, + 47, + null, + 47, + null, + null, + 1, + 556, + null, + null, + 1, + 173, + null, + null + ] + }, + "/Users/wimdavies/Projects/bowling-challenge-ruby/spec/score_card_integration_spec.rb": { + "lines": [ + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + null, + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + null, + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 1, + 18, + null, + null, + 1, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 16, + null, + null, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 16, + null, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 16, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 18, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 21, + null, + 1, + null, + null, + 1, + 1, + null, + 21, + null, + 1, + null, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + 1, + null, + null, + 1, + 1, + null, + 13, + null, + 1, + null, + null + ] + }, + "/Users/wimdavies/Projects/bowling-challenge-ruby/lib/score_card.rb": { + "lines": [ + 1, + null, + 1, + 1, + null, + 1, + 27, + 27, + 27, + null, + 27, + 270, + 270, + 270, + null, + null, + null, + 1, + 362, + null, + 362, + null, + 362, + 43, + 28, + null, + 15, + null, + null, + 319, + null, + null, + 362, + null, + null, + 1, + 14, + 140, + 140, + null, + 140, + null, + 14, + null, + 14, + null, + 112, + null, + null, + null, + null, + 1, + 4, + null, + 4, + 4, + 40, + 40, + null, + 40, + null, + null, + 4, + null, + null, + 1, + null, + 1, + 14, + 2, + 12, + 4, + null, + null, + null, + 1, + 14, + 2, + 12, + 2, + null, + null, + null, + 1, + 112, + 4, + 108, + 9, + 99, + 3, + null, + null, + null + ] + } + }, + "timestamp": 1685378604 + } +} diff --git a/coverage/.resultset.json.lock b/coverage/.resultset.json.lock new file mode 100644 index 00000000..e69de29b diff --git a/coverage/coverage.xml b/coverage/coverage.xml new file mode 100644 index 00000000..bff55bf7 --- /dev/null +++ b/coverage/coverage.xml @@ -0,0 +1,478 @@ + + + + + + /Users/wimdavies/Projects/bowling-challenge-ruby + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/frame.rb b/lib/frame.rb index d9640e03..9231a3a3 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -24,16 +24,12 @@ def calculate_frame_score else @frame_score = @rolls[0] + @rolls[1] end - - # return @frame_score end def calculate_total_score calculate_frame_score @total_score = (@frame_score + @bonus_score) - - # return @total_score end def is_strike? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c80d44b9..c37e78f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,9 @@ +require 'simplecov' +require 'simplecov-cobertura' +SimpleCov.start + +SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause From ef72cca2fa4c72bc3ceff6459d15b0b05fb7baaf Mon Sep 17 00:00:00 2001 From: wimdavies Date: Tue, 30 May 2023 10:20:58 +0100 Subject: [PATCH 18/18] 100% code coverage with simplecov and simplecov-cobertura gems installed --- coverage/.resultset.json | 2 +- coverage/coverage.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/coverage/.resultset.json b/coverage/.resultset.json index e372cbc8..a1a50e6e 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -768,6 +768,6 @@ ] } }, - "timestamp": 1685378604 + "timestamp": 1685437384 } } diff --git a/coverage/coverage.xml b/coverage/coverage.xml index bff55bf7..e4a07c31 100644 --- a/coverage/coverage.xml +++ b/coverage/coverage.xml @@ -1,7 +1,7 @@ - + /Users/wimdavies/Projects/bowling-challenge-ruby