From 83411b2492c54acf39ab55ae2195e17eb49f8f06 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Thu, 27 Feb 2020 07:49:30 -0700 Subject: [PATCH 001/285] Add dependencies --- Gemfile | 2 ++ Gemfile.lock | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c4cff67 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'minitest', '~> 5.4' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..6bdfd6c --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + minitest (5.14.0) + +PLATFORMS + ruby + +DEPENDENCIES + minitest (~> 5.4) + +BUNDLED WITH + 2.1.4 From 404ac082fe09886eec2f0cf4a79b4d40ed520d2a Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Thu, 27 Feb 2020 07:53:39 -0700 Subject: [PATCH 002/285] Add incomprehensibly concise example --- lib/bottles.rb | 19 +++ test/bottles_test.rb | 382 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 401 insertions(+) create mode 100644 lib/bottles.rb create mode 100644 test/bottles_test.rb diff --git a/lib/bottles.rb b/lib/bottles.rb new file mode 100644 index 0000000..e63c312 --- /dev/null +++ b/lib/bottles.rb @@ -0,0 +1,19 @@ +class Bottles + def song + verses(99, 0) + end + + def verses(hi, lo) + hi.downto(lo).map {|n| verse(n) }.join("\n") + end + + def verse(n) + "#{n == 0 ? 'No more' : n} bottle#{'s' if n != 1}" + + " of beer on the wall, " + + "#{n == 0 ? 'no more' : n} bottle#{'s' if n != 1} of beer.\n" + + "#{n > 0 ? "Take #{n > 1 ? 'one' : 'it'} down and pass it around" + : "Go to the store and buy some more"}, " + + "#{n-1 < 0 ? 99 : n-1 == 0 ? 'no more' : n-1} bottle#{'s' if n-1 != 1}"+ + " of beer on the wall.\n" + end +end diff --git a/test/bottles_test.rb b/test/bottles_test.rb new file mode 100644 index 0000000..8e1aa70 --- /dev/null +++ b/test/bottles_test.rb @@ -0,0 +1,382 @@ +gem 'minitest', '~> 5.4' +require 'minitest/autorun' +require 'minitest/pride' +require_relative '../lib/bottles' + +class BottlesTest < Minitest::Test + + attr_reader :bottles + def setup + @bottles = ::Bottles.new + end + + def test_the_first_verse + expected = <<-VERSE +99 bottles of beer on the wall, 99 bottles of beer. +Take one down and pass it around, 98 bottles of beer on the wall. +VERSE + assert_equal expected, bottles.verse(99) + end + + def test_another_verse + expected = <<-VERSE +89 bottles of beer on the wall, 89 bottles of beer. +Take one down and pass it around, 88 bottles of beer on the wall. +VERSE + assert_equal expected, bottles.verse(89) + end + + def test_verse_2 + expected = <<-VERSE +2 bottles of beer on the wall, 2 bottles of beer. +Take one down and pass it around, 1 bottle of beer on the wall. + VERSE + assert_equal expected, bottles.verse(2) + end + + def test_verse_1 + expected = <<-VERSE +1 bottle of beer on the wall, 1 bottle of beer. +Take it down and pass it around, no more bottles of beer on the wall. + VERSE + assert_equal expected, bottles.verse(1) + end + + def test_verse_0 + expected = <<-VERSE +No more bottles of beer on the wall, no more bottles of beer. +Go to the store and buy some more, 99 bottles of beer on the wall. + VERSE + assert_equal expected, bottles.verse(0) + end + + def test_a_couple_verses + expected = <<-VERSES +99 bottles of beer on the wall, 99 bottles of beer. +Take one down and pass it around, 98 bottles of beer on the wall. + +98 bottles of beer on the wall, 98 bottles of beer. +Take one down and pass it around, 97 bottles of beer on the wall. +VERSES + assert_equal expected, bottles.verses(99, 98) + end + + def test_a_few_verses + expected = <<-VERSES +2 bottles of beer on the wall, 2 bottles of beer. +Take one down and pass it around, 1 bottle of beer on the wall. + +1 bottle of beer on the wall, 1 bottle of beer. +Take it down and pass it around, no more bottles of beer on the wall. + +No more bottles of beer on the wall, no more bottles of beer. +Go to the store and buy some more, 99 bottles of beer on the wall. +VERSES + assert_equal expected, bottles.verses(2, 0) + end + + def test_the_whole_song + expected = <<-SONG +99 bottles of beer on the wall, 99 bottles of beer. +Take one down and pass it around, 98 bottles of beer on the wall. + +98 bottles of beer on the wall, 98 bottles of beer. +Take one down and pass it around, 97 bottles of beer on the wall. + +97 bottles of beer on the wall, 97 bottles of beer. +Take one down and pass it around, 96 bottles of beer on the wall. + +96 bottles of beer on the wall, 96 bottles of beer. +Take one down and pass it around, 95 bottles of beer on the wall. + +95 bottles of beer on the wall, 95 bottles of beer. +Take one down and pass it around, 94 bottles of beer on the wall. + +94 bottles of beer on the wall, 94 bottles of beer. +Take one down and pass it around, 93 bottles of beer on the wall. + +93 bottles of beer on the wall, 93 bottles of beer. +Take one down and pass it around, 92 bottles of beer on the wall. + +92 bottles of beer on the wall, 92 bottles of beer. +Take one down and pass it around, 91 bottles of beer on the wall. + +91 bottles of beer on the wall, 91 bottles of beer. +Take one down and pass it around, 90 bottles of beer on the wall. + +90 bottles of beer on the wall, 90 bottles of beer. +Take one down and pass it around, 89 bottles of beer on the wall. + +89 bottles of beer on the wall, 89 bottles of beer. +Take one down and pass it around, 88 bottles of beer on the wall. + +88 bottles of beer on the wall, 88 bottles of beer. +Take one down and pass it around, 87 bottles of beer on the wall. + +87 bottles of beer on the wall, 87 bottles of beer. +Take one down and pass it around, 86 bottles of beer on the wall. + +86 bottles of beer on the wall, 86 bottles of beer. +Take one down and pass it around, 85 bottles of beer on the wall. + +85 bottles of beer on the wall, 85 bottles of beer. +Take one down and pass it around, 84 bottles of beer on the wall. + +84 bottles of beer on the wall, 84 bottles of beer. +Take one down and pass it around, 83 bottles of beer on the wall. + +83 bottles of beer on the wall, 83 bottles of beer. +Take one down and pass it around, 82 bottles of beer on the wall. + +82 bottles of beer on the wall, 82 bottles of beer. +Take one down and pass it around, 81 bottles of beer on the wall. + +81 bottles of beer on the wall, 81 bottles of beer. +Take one down and pass it around, 80 bottles of beer on the wall. + +80 bottles of beer on the wall, 80 bottles of beer. +Take one down and pass it around, 79 bottles of beer on the wall. + +79 bottles of beer on the wall, 79 bottles of beer. +Take one down and pass it around, 78 bottles of beer on the wall. + +78 bottles of beer on the wall, 78 bottles of beer. +Take one down and pass it around, 77 bottles of beer on the wall. + +77 bottles of beer on the wall, 77 bottles of beer. +Take one down and pass it around, 76 bottles of beer on the wall. + +76 bottles of beer on the wall, 76 bottles of beer. +Take one down and pass it around, 75 bottles of beer on the wall. + +75 bottles of beer on the wall, 75 bottles of beer. +Take one down and pass it around, 74 bottles of beer on the wall. + +74 bottles of beer on the wall, 74 bottles of beer. +Take one down and pass it around, 73 bottles of beer on the wall. + +73 bottles of beer on the wall, 73 bottles of beer. +Take one down and pass it around, 72 bottles of beer on the wall. + +72 bottles of beer on the wall, 72 bottles of beer. +Take one down and pass it around, 71 bottles of beer on the wall. + +71 bottles of beer on the wall, 71 bottles of beer. +Take one down and pass it around, 70 bottles of beer on the wall. + +70 bottles of beer on the wall, 70 bottles of beer. +Take one down and pass it around, 69 bottles of beer on the wall. + +69 bottles of beer on the wall, 69 bottles of beer. +Take one down and pass it around, 68 bottles of beer on the wall. + +68 bottles of beer on the wall, 68 bottles of beer. +Take one down and pass it around, 67 bottles of beer on the wall. + +67 bottles of beer on the wall, 67 bottles of beer. +Take one down and pass it around, 66 bottles of beer on the wall. + +66 bottles of beer on the wall, 66 bottles of beer. +Take one down and pass it around, 65 bottles of beer on the wall. + +65 bottles of beer on the wall, 65 bottles of beer. +Take one down and pass it around, 64 bottles of beer on the wall. + +64 bottles of beer on the wall, 64 bottles of beer. +Take one down and pass it around, 63 bottles of beer on the wall. + +63 bottles of beer on the wall, 63 bottles of beer. +Take one down and pass it around, 62 bottles of beer on the wall. + +62 bottles of beer on the wall, 62 bottles of beer. +Take one down and pass it around, 61 bottles of beer on the wall. + +61 bottles of beer on the wall, 61 bottles of beer. +Take one down and pass it around, 60 bottles of beer on the wall. + +60 bottles of beer on the wall, 60 bottles of beer. +Take one down and pass it around, 59 bottles of beer on the wall. + +59 bottles of beer on the wall, 59 bottles of beer. +Take one down and pass it around, 58 bottles of beer on the wall. + +58 bottles of beer on the wall, 58 bottles of beer. +Take one down and pass it around, 57 bottles of beer on the wall. + +57 bottles of beer on the wall, 57 bottles of beer. +Take one down and pass it around, 56 bottles of beer on the wall. + +56 bottles of beer on the wall, 56 bottles of beer. +Take one down and pass it around, 55 bottles of beer on the wall. + +55 bottles of beer on the wall, 55 bottles of beer. +Take one down and pass it around, 54 bottles of beer on the wall. + +54 bottles of beer on the wall, 54 bottles of beer. +Take one down and pass it around, 53 bottles of beer on the wall. + +53 bottles of beer on the wall, 53 bottles of beer. +Take one down and pass it around, 52 bottles of beer on the wall. + +52 bottles of beer on the wall, 52 bottles of beer. +Take one down and pass it around, 51 bottles of beer on the wall. + +51 bottles of beer on the wall, 51 bottles of beer. +Take one down and pass it around, 50 bottles of beer on the wall. + +50 bottles of beer on the wall, 50 bottles of beer. +Take one down and pass it around, 49 bottles of beer on the wall. + +49 bottles of beer on the wall, 49 bottles of beer. +Take one down and pass it around, 48 bottles of beer on the wall. + +48 bottles of beer on the wall, 48 bottles of beer. +Take one down and pass it around, 47 bottles of beer on the wall. + +47 bottles of beer on the wall, 47 bottles of beer. +Take one down and pass it around, 46 bottles of beer on the wall. + +46 bottles of beer on the wall, 46 bottles of beer. +Take one down and pass it around, 45 bottles of beer on the wall. + +45 bottles of beer on the wall, 45 bottles of beer. +Take one down and pass it around, 44 bottles of beer on the wall. + +44 bottles of beer on the wall, 44 bottles of beer. +Take one down and pass it around, 43 bottles of beer on the wall. + +43 bottles of beer on the wall, 43 bottles of beer. +Take one down and pass it around, 42 bottles of beer on the wall. + +42 bottles of beer on the wall, 42 bottles of beer. +Take one down and pass it around, 41 bottles of beer on the wall. + +41 bottles of beer on the wall, 41 bottles of beer. +Take one down and pass it around, 40 bottles of beer on the wall. + +40 bottles of beer on the wall, 40 bottles of beer. +Take one down and pass it around, 39 bottles of beer on the wall. + +39 bottles of beer on the wall, 39 bottles of beer. +Take one down and pass it around, 38 bottles of beer on the wall. + +38 bottles of beer on the wall, 38 bottles of beer. +Take one down and pass it around, 37 bottles of beer on the wall. + +37 bottles of beer on the wall, 37 bottles of beer. +Take one down and pass it around, 36 bottles of beer on the wall. + +36 bottles of beer on the wall, 36 bottles of beer. +Take one down and pass it around, 35 bottles of beer on the wall. + +35 bottles of beer on the wall, 35 bottles of beer. +Take one down and pass it around, 34 bottles of beer on the wall. + +34 bottles of beer on the wall, 34 bottles of beer. +Take one down and pass it around, 33 bottles of beer on the wall. + +33 bottles of beer on the wall, 33 bottles of beer. +Take one down and pass it around, 32 bottles of beer on the wall. + +32 bottles of beer on the wall, 32 bottles of beer. +Take one down and pass it around, 31 bottles of beer on the wall. + +31 bottles of beer on the wall, 31 bottles of beer. +Take one down and pass it around, 30 bottles of beer on the wall. + +30 bottles of beer on the wall, 30 bottles of beer. +Take one down and pass it around, 29 bottles of beer on the wall. + +29 bottles of beer on the wall, 29 bottles of beer. +Take one down and pass it around, 28 bottles of beer on the wall. + +28 bottles of beer on the wall, 28 bottles of beer. +Take one down and pass it around, 27 bottles of beer on the wall. + +27 bottles of beer on the wall, 27 bottles of beer. +Take one down and pass it around, 26 bottles of beer on the wall. + +26 bottles of beer on the wall, 26 bottles of beer. +Take one down and pass it around, 25 bottles of beer on the wall. + +25 bottles of beer on the wall, 25 bottles of beer. +Take one down and pass it around, 24 bottles of beer on the wall. + +24 bottles of beer on the wall, 24 bottles of beer. +Take one down and pass it around, 23 bottles of beer on the wall. + +23 bottles of beer on the wall, 23 bottles of beer. +Take one down and pass it around, 22 bottles of beer on the wall. + +22 bottles of beer on the wall, 22 bottles of beer. +Take one down and pass it around, 21 bottles of beer on the wall. + +21 bottles of beer on the wall, 21 bottles of beer. +Take one down and pass it around, 20 bottles of beer on the wall. + +20 bottles of beer on the wall, 20 bottles of beer. +Take one down and pass it around, 19 bottles of beer on the wall. + +19 bottles of beer on the wall, 19 bottles of beer. +Take one down and pass it around, 18 bottles of beer on the wall. + +18 bottles of beer on the wall, 18 bottles of beer. +Take one down and pass it around, 17 bottles of beer on the wall. + +17 bottles of beer on the wall, 17 bottles of beer. +Take one down and pass it around, 16 bottles of beer on the wall. + +16 bottles of beer on the wall, 16 bottles of beer. +Take one down and pass it around, 15 bottles of beer on the wall. + +15 bottles of beer on the wall, 15 bottles of beer. +Take one down and pass it around, 14 bottles of beer on the wall. + +14 bottles of beer on the wall, 14 bottles of beer. +Take one down and pass it around, 13 bottles of beer on the wall. + +13 bottles of beer on the wall, 13 bottles of beer. +Take one down and pass it around, 12 bottles of beer on the wall. + +12 bottles of beer on the wall, 12 bottles of beer. +Take one down and pass it around, 11 bottles of beer on the wall. + +11 bottles of beer on the wall, 11 bottles of beer. +Take one down and pass it around, 10 bottles of beer on the wall. + +10 bottles of beer on the wall, 10 bottles of beer. +Take one down and pass it around, 9 bottles of beer on the wall. + +9 bottles of beer on the wall, 9 bottles of beer. +Take one down and pass it around, 8 bottles of beer on the wall. + +8 bottles of beer on the wall, 8 bottles of beer. +Take one down and pass it around, 7 bottles of beer on the wall. + +7 bottles of beer on the wall, 7 bottles of beer. +Take one down and pass it around, 6 bottles of beer on the wall. + +6 bottles of beer on the wall, 6 bottles of beer. +Take one down and pass it around, 5 bottles of beer on the wall. + +5 bottles of beer on the wall, 5 bottles of beer. +Take one down and pass it around, 4 bottles of beer on the wall. + +4 bottles of beer on the wall, 4 bottles of beer. +Take one down and pass it around, 3 bottles of beer on the wall. + +3 bottles of beer on the wall, 3 bottles of beer. +Take one down and pass it around, 2 bottles of beer on the wall. + +2 bottles of beer on the wall, 2 bottles of beer. +Take one down and pass it around, 1 bottle of beer on the wall. + +1 bottle of beer on the wall, 1 bottle of beer. +Take it down and pass it around, no more bottles of beer on the wall. + +No more bottles of beer on the wall, no more bottles of beer. +Go to the store and buy some more, 99 bottles of beer on the wall. + SONG + assert_equal expected, bottles.song + end +end From b0e7fc923ef28c6535d876dd549dfc3a2895d371 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Thu, 27 Feb 2020 08:14:53 -0700 Subject: [PATCH 003/285] Add speculatively general example --- lib/bottles.rb | 64 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e63c312..c25a7ad 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,19 +1,63 @@ class Bottles + NoMore = lambda do |verse| + "No more bottles of beer on the wall, " + + "no more bottles of beer.\n" + + "Go to the store and buy some more, " + + "99 bottles of beer on the wall.\n" + end + + LastOne = lambda do |verse| + "1 bottle of beer on the wall, " + + "1 bottle of beer.\n" + + "Take it down and pass it around, " + + "no more bottles of beer on the wall.\n" + end + + Penultimate = lambda do |verse| + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" + end + + Default = lambda do |verse| + "#{verse.number} bottles of beer on the wall, " + + "#{verse.number} bottles of beer.\n" + + "Take one down and pass it around, " + + "#{verse.number - 1} bottles of beer on the wall.\n" + end + def song verses(99, 0) end - def verses(hi, lo) - hi.downto(lo).map {|n| verse(n) }.join("\n") + def verses(finish, start) + (finish).downto(start).map {|verse_number| + verse(verse_number) }.join("\n") + end + + def verse(number) + verse_for(number).text + end + + def verse_for(number) + case number + when 0 then Verse.new(number, &NoMore) + when 1 then Verse.new(number, &LastOne) + when 2 then Verse.new(number, &Penultimate) + else Verse.new(number, &Default) + end + end +end + +class Verse + attr_reader :number + def initialize(number, &lyrics) + @number = number + @lyrics = lyrics end - def verse(n) - "#{n == 0 ? 'No more' : n} bottle#{'s' if n != 1}" + - " of beer on the wall, " + - "#{n == 0 ? 'no more' : n} bottle#{'s' if n != 1} of beer.\n" + - "#{n > 0 ? "Take #{n > 1 ? 'one' : 'it'} down and pass it around" - : "Go to the store and buy some more"}, " + - "#{n-1 < 0 ? 99 : n-1 == 0 ? 'no more' : n-1} bottle#{'s' if n-1 != 1}"+ - " of beer on the wall.\n" + def text + @lyrics.call self end end From ee4d53bb860c2ea049aad172ffc495a13c29b91d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Wed, 13 May 2020 15:02:35 -0400 Subject: [PATCH 004/285] Add concretely abstract example --- lib/bottles.rb | 106 ++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index c25a7ad..4fb30b3 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,63 +1,87 @@ class Bottles - NoMore = lambda do |verse| - "No more bottles of beer on the wall, " + - "no more bottles of beer.\n" + - "Go to the store and buy some more, " + - "99 bottles of beer on the wall.\n" + def song + verses(99, 0) end - LastOne = lambda do |verse| - "1 bottle of beer on the wall, " + - "1 bottle of beer.\n" + - "Take it down and pass it around, " + - "no more bottles of beer on the wall.\n" + def verses(bottles_at_start, bottles_at_end) + bottles_at_start.downto(bottles_at_end).map do |bottles| + verse(bottles) + end.join("\n") end - Penultimate = lambda do |verse| - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" + def verse(bottles) + Round.new(bottles).to_s end +end - Default = lambda do |verse| - "#{verse.number} bottles of beer on the wall, " + - "#{verse.number} bottles of beer.\n" + - "Take one down and pass it around, " + - "#{verse.number - 1} bottles of beer on the wall.\n" +class Round + attr_reader :bottles + def initialize(bottles) + @bottles = bottles end - def song - verses(99, 0) + def to_s + challenge + response + end + + def challenge + bottles_of_beer.capitalize + " " + on_wall + ", " + + bottles_of_beer + ".\n" + end + + def response + go_to_the_store_or_take_one_down + ", " + + bottles_of_beer + " " + on_wall + ".\n" + end + + def bottles_of_beer + "#{anglicized_bottle_count} #{pluralized_bottle_form} of #{beer}" end - def verses(finish, start) - (finish).downto(start).map {|verse_number| - verse(verse_number) }.join("\n") + def beer + "beer" end - def verse(number) - verse_for(number).text + def on_wall + "on the wall" end - def verse_for(number) - case number - when 0 then Verse.new(number, &NoMore) - when 1 then Verse.new(number, &LastOne) - when 2 then Verse.new(number, &Penultimate) - else Verse.new(number, &Default) + def pluralized_bottle_form + last_beer? ? "bottle" : "bottles" + end + + def anglicized_bottle_count + all_out? ? "no more" : bottles.to_s + end + + def go_to_the_store_or_take_one_down + if all_out? + @bottles = 99 + buy_new_beer + else + lyrics = drink_beer + @bottles -= 1 + lyrics end end -end -class Verse - attr_reader :number - def initialize(number, &lyrics) - @number = number - @lyrics = lyrics + def buy_new_beer + "Go to the store and buy some more" + end + + def drink_beer + "Take #{it_or_one} down and pass it around" + end + + def it_or_one + last_beer? ? "it" : "one" + end + + def all_out? + bottles.zero? end - def text - @lyrics.call self + def last_beer? + bottles == 1 end end From a705176e24e358c23abd29e50d95f43843b6323b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Wed, 13 May 2020 15:03:20 -0400 Subject: [PATCH 005/285] Add shameless green example --- lib/bottles.rb | 103 ++++++++++++------------------------------------- 1 file changed, 25 insertions(+), 78 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4fb30b3..24c2299 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -3,85 +3,32 @@ def song verses(99, 0) end - def verses(bottles_at_start, bottles_at_end) - bottles_at_start.downto(bottles_at_end).map do |bottles| - verse(bottles) - end.join("\n") - end - - def verse(bottles) - Round.new(bottles).to_s - end -end - -class Round - attr_reader :bottles - def initialize(bottles) - @bottles = bottles - end - - def to_s - challenge + response - end - - def challenge - bottles_of_beer.capitalize + " " + on_wall + ", " + - bottles_of_beer + ".\n" - end - - def response - go_to_the_store_or_take_one_down + ", " + - bottles_of_beer + " " + on_wall + ".\n" - end - - def bottles_of_beer - "#{anglicized_bottle_count} #{pluralized_bottle_form} of #{beer}" - end - - def beer - "beer" - end - - def on_wall - "on the wall" - end - - def pluralized_bottle_form - last_beer? ? "bottle" : "bottles" - end - - def anglicized_bottle_count - all_out? ? "no more" : bottles.to_s - end - - def go_to_the_store_or_take_one_down - if all_out? - @bottles = 99 - buy_new_beer + def verses(upper, lower) + upper.downto(lower).map {|i| verse(i)}.join("\n") + end + + def verse(number) + case number + when 0 + "No more bottles of beer on the wall, " + + "no more bottles of beer.\n" + + "Go to the store and buy some more, " + + "99 bottles of beer on the wall.\n" + when 1 + "1 bottle of beer on the wall, " + + "1 bottle of beer.\n" + + "Take it down and pass it around, " + + "no more bottles of beer on the wall.\n" + when 2 + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" else - lyrics = drink_beer - @bottles -= 1 - lyrics + "#{number} bottles of beer on the wall, " + + "#{number} bottles of beer.\n" + + "Take one down and pass it around, " + + "#{number-1} bottles of beer on the wall.\n" end end - - def buy_new_beer - "Go to the store and buy some more" - end - - def drink_beer - "Take #{it_or_one} down and pass it around" - end - - def it_or_one - last_beer? ? "it" : "one" - end - - def all_out? - bottles.zero? - end - - def last_beer? - bottles == 1 - end end From e3acb2f581a675986d223ec28a5eacf5b892f15e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:23:25 -0400 Subject: [PATCH 006/285] initialize bottles and bottles_test --- lib/bottles.rb | 34 ---- test/bottles_test.rb | 375 ------------------------------------------- 2 files changed, 409 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 24c2299..e69de29 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,34 +0,0 @@ -class Bottles - def song - verses(99, 0) - end - - def verses(upper, lower) - upper.downto(lower).map {|i| verse(i)}.join("\n") - end - - def verse(number) - case number - when 0 - "No more bottles of beer on the wall, " + - "no more bottles of beer.\n" + - "Go to the store and buy some more, " + - "99 bottles of beer on the wall.\n" - when 1 - "1 bottle of beer on the wall, " + - "1 bottle of beer.\n" + - "Take it down and pass it around, " + - "no more bottles of beer on the wall.\n" - when 2 - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" - else - "#{number} bottles of beer on the wall, " + - "#{number} bottles of beer.\n" + - "Take one down and pass it around, " + - "#{number-1} bottles of beer on the wall.\n" - end - end -end diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 8e1aa70..3f40021 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -4,379 +4,4 @@ require_relative '../lib/bottles' class BottlesTest < Minitest::Test - - attr_reader :bottles - def setup - @bottles = ::Bottles.new - end - - def test_the_first_verse - expected = <<-VERSE -99 bottles of beer on the wall, 99 bottles of beer. -Take one down and pass it around, 98 bottles of beer on the wall. -VERSE - assert_equal expected, bottles.verse(99) - end - - def test_another_verse - expected = <<-VERSE -89 bottles of beer on the wall, 89 bottles of beer. -Take one down and pass it around, 88 bottles of beer on the wall. -VERSE - assert_equal expected, bottles.verse(89) - end - - def test_verse_2 - expected = <<-VERSE -2 bottles of beer on the wall, 2 bottles of beer. -Take one down and pass it around, 1 bottle of beer on the wall. - VERSE - assert_equal expected, bottles.verse(2) - end - - def test_verse_1 - expected = <<-VERSE -1 bottle of beer on the wall, 1 bottle of beer. -Take it down and pass it around, no more bottles of beer on the wall. - VERSE - assert_equal expected, bottles.verse(1) - end - - def test_verse_0 - expected = <<-VERSE -No more bottles of beer on the wall, no more bottles of beer. -Go to the store and buy some more, 99 bottles of beer on the wall. - VERSE - assert_equal expected, bottles.verse(0) - end - - def test_a_couple_verses - expected = <<-VERSES -99 bottles of beer on the wall, 99 bottles of beer. -Take one down and pass it around, 98 bottles of beer on the wall. - -98 bottles of beer on the wall, 98 bottles of beer. -Take one down and pass it around, 97 bottles of beer on the wall. -VERSES - assert_equal expected, bottles.verses(99, 98) - end - - def test_a_few_verses - expected = <<-VERSES -2 bottles of beer on the wall, 2 bottles of beer. -Take one down and pass it around, 1 bottle of beer on the wall. - -1 bottle of beer on the wall, 1 bottle of beer. -Take it down and pass it around, no more bottles of beer on the wall. - -No more bottles of beer on the wall, no more bottles of beer. -Go to the store and buy some more, 99 bottles of beer on the wall. -VERSES - assert_equal expected, bottles.verses(2, 0) - end - - def test_the_whole_song - expected = <<-SONG -99 bottles of beer on the wall, 99 bottles of beer. -Take one down and pass it around, 98 bottles of beer on the wall. - -98 bottles of beer on the wall, 98 bottles of beer. -Take one down and pass it around, 97 bottles of beer on the wall. - -97 bottles of beer on the wall, 97 bottles of beer. -Take one down and pass it around, 96 bottles of beer on the wall. - -96 bottles of beer on the wall, 96 bottles of beer. -Take one down and pass it around, 95 bottles of beer on the wall. - -95 bottles of beer on the wall, 95 bottles of beer. -Take one down and pass it around, 94 bottles of beer on the wall. - -94 bottles of beer on the wall, 94 bottles of beer. -Take one down and pass it around, 93 bottles of beer on the wall. - -93 bottles of beer on the wall, 93 bottles of beer. -Take one down and pass it around, 92 bottles of beer on the wall. - -92 bottles of beer on the wall, 92 bottles of beer. -Take one down and pass it around, 91 bottles of beer on the wall. - -91 bottles of beer on the wall, 91 bottles of beer. -Take one down and pass it around, 90 bottles of beer on the wall. - -90 bottles of beer on the wall, 90 bottles of beer. -Take one down and pass it around, 89 bottles of beer on the wall. - -89 bottles of beer on the wall, 89 bottles of beer. -Take one down and pass it around, 88 bottles of beer on the wall. - -88 bottles of beer on the wall, 88 bottles of beer. -Take one down and pass it around, 87 bottles of beer on the wall. - -87 bottles of beer on the wall, 87 bottles of beer. -Take one down and pass it around, 86 bottles of beer on the wall. - -86 bottles of beer on the wall, 86 bottles of beer. -Take one down and pass it around, 85 bottles of beer on the wall. - -85 bottles of beer on the wall, 85 bottles of beer. -Take one down and pass it around, 84 bottles of beer on the wall. - -84 bottles of beer on the wall, 84 bottles of beer. -Take one down and pass it around, 83 bottles of beer on the wall. - -83 bottles of beer on the wall, 83 bottles of beer. -Take one down and pass it around, 82 bottles of beer on the wall. - -82 bottles of beer on the wall, 82 bottles of beer. -Take one down and pass it around, 81 bottles of beer on the wall. - -81 bottles of beer on the wall, 81 bottles of beer. -Take one down and pass it around, 80 bottles of beer on the wall. - -80 bottles of beer on the wall, 80 bottles of beer. -Take one down and pass it around, 79 bottles of beer on the wall. - -79 bottles of beer on the wall, 79 bottles of beer. -Take one down and pass it around, 78 bottles of beer on the wall. - -78 bottles of beer on the wall, 78 bottles of beer. -Take one down and pass it around, 77 bottles of beer on the wall. - -77 bottles of beer on the wall, 77 bottles of beer. -Take one down and pass it around, 76 bottles of beer on the wall. - -76 bottles of beer on the wall, 76 bottles of beer. -Take one down and pass it around, 75 bottles of beer on the wall. - -75 bottles of beer on the wall, 75 bottles of beer. -Take one down and pass it around, 74 bottles of beer on the wall. - -74 bottles of beer on the wall, 74 bottles of beer. -Take one down and pass it around, 73 bottles of beer on the wall. - -73 bottles of beer on the wall, 73 bottles of beer. -Take one down and pass it around, 72 bottles of beer on the wall. - -72 bottles of beer on the wall, 72 bottles of beer. -Take one down and pass it around, 71 bottles of beer on the wall. - -71 bottles of beer on the wall, 71 bottles of beer. -Take one down and pass it around, 70 bottles of beer on the wall. - -70 bottles of beer on the wall, 70 bottles of beer. -Take one down and pass it around, 69 bottles of beer on the wall. - -69 bottles of beer on the wall, 69 bottles of beer. -Take one down and pass it around, 68 bottles of beer on the wall. - -68 bottles of beer on the wall, 68 bottles of beer. -Take one down and pass it around, 67 bottles of beer on the wall. - -67 bottles of beer on the wall, 67 bottles of beer. -Take one down and pass it around, 66 bottles of beer on the wall. - -66 bottles of beer on the wall, 66 bottles of beer. -Take one down and pass it around, 65 bottles of beer on the wall. - -65 bottles of beer on the wall, 65 bottles of beer. -Take one down and pass it around, 64 bottles of beer on the wall. - -64 bottles of beer on the wall, 64 bottles of beer. -Take one down and pass it around, 63 bottles of beer on the wall. - -63 bottles of beer on the wall, 63 bottles of beer. -Take one down and pass it around, 62 bottles of beer on the wall. - -62 bottles of beer on the wall, 62 bottles of beer. -Take one down and pass it around, 61 bottles of beer on the wall. - -61 bottles of beer on the wall, 61 bottles of beer. -Take one down and pass it around, 60 bottles of beer on the wall. - -60 bottles of beer on the wall, 60 bottles of beer. -Take one down and pass it around, 59 bottles of beer on the wall. - -59 bottles of beer on the wall, 59 bottles of beer. -Take one down and pass it around, 58 bottles of beer on the wall. - -58 bottles of beer on the wall, 58 bottles of beer. -Take one down and pass it around, 57 bottles of beer on the wall. - -57 bottles of beer on the wall, 57 bottles of beer. -Take one down and pass it around, 56 bottles of beer on the wall. - -56 bottles of beer on the wall, 56 bottles of beer. -Take one down and pass it around, 55 bottles of beer on the wall. - -55 bottles of beer on the wall, 55 bottles of beer. -Take one down and pass it around, 54 bottles of beer on the wall. - -54 bottles of beer on the wall, 54 bottles of beer. -Take one down and pass it around, 53 bottles of beer on the wall. - -53 bottles of beer on the wall, 53 bottles of beer. -Take one down and pass it around, 52 bottles of beer on the wall. - -52 bottles of beer on the wall, 52 bottles of beer. -Take one down and pass it around, 51 bottles of beer on the wall. - -51 bottles of beer on the wall, 51 bottles of beer. -Take one down and pass it around, 50 bottles of beer on the wall. - -50 bottles of beer on the wall, 50 bottles of beer. -Take one down and pass it around, 49 bottles of beer on the wall. - -49 bottles of beer on the wall, 49 bottles of beer. -Take one down and pass it around, 48 bottles of beer on the wall. - -48 bottles of beer on the wall, 48 bottles of beer. -Take one down and pass it around, 47 bottles of beer on the wall. - -47 bottles of beer on the wall, 47 bottles of beer. -Take one down and pass it around, 46 bottles of beer on the wall. - -46 bottles of beer on the wall, 46 bottles of beer. -Take one down and pass it around, 45 bottles of beer on the wall. - -45 bottles of beer on the wall, 45 bottles of beer. -Take one down and pass it around, 44 bottles of beer on the wall. - -44 bottles of beer on the wall, 44 bottles of beer. -Take one down and pass it around, 43 bottles of beer on the wall. - -43 bottles of beer on the wall, 43 bottles of beer. -Take one down and pass it around, 42 bottles of beer on the wall. - -42 bottles of beer on the wall, 42 bottles of beer. -Take one down and pass it around, 41 bottles of beer on the wall. - -41 bottles of beer on the wall, 41 bottles of beer. -Take one down and pass it around, 40 bottles of beer on the wall. - -40 bottles of beer on the wall, 40 bottles of beer. -Take one down and pass it around, 39 bottles of beer on the wall. - -39 bottles of beer on the wall, 39 bottles of beer. -Take one down and pass it around, 38 bottles of beer on the wall. - -38 bottles of beer on the wall, 38 bottles of beer. -Take one down and pass it around, 37 bottles of beer on the wall. - -37 bottles of beer on the wall, 37 bottles of beer. -Take one down and pass it around, 36 bottles of beer on the wall. - -36 bottles of beer on the wall, 36 bottles of beer. -Take one down and pass it around, 35 bottles of beer on the wall. - -35 bottles of beer on the wall, 35 bottles of beer. -Take one down and pass it around, 34 bottles of beer on the wall. - -34 bottles of beer on the wall, 34 bottles of beer. -Take one down and pass it around, 33 bottles of beer on the wall. - -33 bottles of beer on the wall, 33 bottles of beer. -Take one down and pass it around, 32 bottles of beer on the wall. - -32 bottles of beer on the wall, 32 bottles of beer. -Take one down and pass it around, 31 bottles of beer on the wall. - -31 bottles of beer on the wall, 31 bottles of beer. -Take one down and pass it around, 30 bottles of beer on the wall. - -30 bottles of beer on the wall, 30 bottles of beer. -Take one down and pass it around, 29 bottles of beer on the wall. - -29 bottles of beer on the wall, 29 bottles of beer. -Take one down and pass it around, 28 bottles of beer on the wall. - -28 bottles of beer on the wall, 28 bottles of beer. -Take one down and pass it around, 27 bottles of beer on the wall. - -27 bottles of beer on the wall, 27 bottles of beer. -Take one down and pass it around, 26 bottles of beer on the wall. - -26 bottles of beer on the wall, 26 bottles of beer. -Take one down and pass it around, 25 bottles of beer on the wall. - -25 bottles of beer on the wall, 25 bottles of beer. -Take one down and pass it around, 24 bottles of beer on the wall. - -24 bottles of beer on the wall, 24 bottles of beer. -Take one down and pass it around, 23 bottles of beer on the wall. - -23 bottles of beer on the wall, 23 bottles of beer. -Take one down and pass it around, 22 bottles of beer on the wall. - -22 bottles of beer on the wall, 22 bottles of beer. -Take one down and pass it around, 21 bottles of beer on the wall. - -21 bottles of beer on the wall, 21 bottles of beer. -Take one down and pass it around, 20 bottles of beer on the wall. - -20 bottles of beer on the wall, 20 bottles of beer. -Take one down and pass it around, 19 bottles of beer on the wall. - -19 bottles of beer on the wall, 19 bottles of beer. -Take one down and pass it around, 18 bottles of beer on the wall. - -18 bottles of beer on the wall, 18 bottles of beer. -Take one down and pass it around, 17 bottles of beer on the wall. - -17 bottles of beer on the wall, 17 bottles of beer. -Take one down and pass it around, 16 bottles of beer on the wall. - -16 bottles of beer on the wall, 16 bottles of beer. -Take one down and pass it around, 15 bottles of beer on the wall. - -15 bottles of beer on the wall, 15 bottles of beer. -Take one down and pass it around, 14 bottles of beer on the wall. - -14 bottles of beer on the wall, 14 bottles of beer. -Take one down and pass it around, 13 bottles of beer on the wall. - -13 bottles of beer on the wall, 13 bottles of beer. -Take one down and pass it around, 12 bottles of beer on the wall. - -12 bottles of beer on the wall, 12 bottles of beer. -Take one down and pass it around, 11 bottles of beer on the wall. - -11 bottles of beer on the wall, 11 bottles of beer. -Take one down and pass it around, 10 bottles of beer on the wall. - -10 bottles of beer on the wall, 10 bottles of beer. -Take one down and pass it around, 9 bottles of beer on the wall. - -9 bottles of beer on the wall, 9 bottles of beer. -Take one down and pass it around, 8 bottles of beer on the wall. - -8 bottles of beer on the wall, 8 bottles of beer. -Take one down and pass it around, 7 bottles of beer on the wall. - -7 bottles of beer on the wall, 7 bottles of beer. -Take one down and pass it around, 6 bottles of beer on the wall. - -6 bottles of beer on the wall, 6 bottles of beer. -Take one down and pass it around, 5 bottles of beer on the wall. - -5 bottles of beer on the wall, 5 bottles of beer. -Take one down and pass it around, 4 bottles of beer on the wall. - -4 bottles of beer on the wall, 4 bottles of beer. -Take one down and pass it around, 3 bottles of beer on the wall. - -3 bottles of beer on the wall, 3 bottles of beer. -Take one down and pass it around, 2 bottles of beer on the wall. - -2 bottles of beer on the wall, 2 bottles of beer. -Take one down and pass it around, 1 bottle of beer on the wall. - -1 bottle of beer on the wall, 1 bottle of beer. -Take it down and pass it around, no more bottles of beer on the wall. - -No more bottles of beer on the wall, no more bottles of beer. -Go to the store and buy some more, 99 bottles of beer on the wall. - SONG - assert_equal expected, bottles.song - end end From 4fa231116409ece11e2ba0796deb3ee8d79b422d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:24:18 -0400 Subject: [PATCH 007/285] verse 99 test --- test/bottles_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 3f40021..19ec8b7 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -4,4 +4,12 @@ require_relative '../lib/bottles' class BottlesTest < Minitest::Test + def test_the_first_verse + expected = + "99 bottles of beer on the wall, " + + "99 bottles of beer.\n" + + "Take one down and pass it around, " + + "98 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(99) + end end From 4c77752f7777094d2e5a5be03e38797a9400a2a9 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:24:51 -0400 Subject: [PATCH 008/285] empty Bottles class --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index e69de29..69e17dd 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -0,0 +1,2 @@ +class Bottles +end \ No newline at end of file From cd1323c3685d53ba28d8fb9930e7819fe5210ad5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:25:18 -0400 Subject: [PATCH 009/285] empty verse method --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 69e17dd..69e3da8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,2 +1,4 @@ class Bottles + def verse + end end \ No newline at end of file From 6c2a9e9ed60f80c67174c39081d628a4c577d5a0 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:25:55 -0400 Subject: [PATCH 010/285] verse method takes _ argument --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 69e3da8..f3b3ff0 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,4 +1,4 @@ class Bottles - def verse + def verse(_) end end \ No newline at end of file From cde07d590e54219588f4aa5dfbbc85cd86db29ae Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:27:06 -0400 Subject: [PATCH 011/285] pass verse 99 test --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index f3b3ff0..d9a7c27 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,4 +1,8 @@ class Bottles def verse(_) + "99 bottles of beer on the wall, " + + "99 bottles of beer.\n" + + "Take one down and pass it around, " + + "98 bottles of beer on the wall.\n" end end \ No newline at end of file From 2f7463d47bb3ae6b50647aed817e1870c6159dfd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:28:38 -0400 Subject: [PATCH 012/285] verse 3 test --- test/bottles_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 19ec8b7..fb75c22 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -12,4 +12,13 @@ def test_the_first_verse "98 bottles of beer on the wall.\n" assert_equal expected, Bottles.new.verse(99) end + + def test_another_verse + expected = + "3 bottles of beer on the wall, " + + "3 bottles of beer.\n" + + "Take one down and pass it around, " + + "2 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(3) + end end From 02bb3d39f9b81eb091c4a4f0b7e1af968181d524 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:29:38 -0400 Subject: [PATCH 013/285] pass 3 and 99 with conditional --- lib/bottles.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index d9a7c27..cd92745 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,8 +1,15 @@ class Bottles - def verse(_) - "99 bottles of beer on the wall, " + - "99 bottles of beer.\n" + - "Take one down and pass it around, " + - "98 bottles of beer on the wall.\n" + def verse(number) + if number == 99 + "99 bottles of beer on the wall, " + + "99 bottles of beer.\n" + + "Take one down and pass it around, " + + "98 bottles of beer on the wall.\n" + else + "3 bottles of beer on the wall, " + + "3 bottles of beer.\n" + + "Take one down and pass it around, " + + "2 bottles of beer on the wall.\n" + end end end \ No newline at end of file From 6507af9c9094dc53fb682a90ce7b8d88767dc9be Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:30:46 -0400 Subject: [PATCH 014/285] separate conditional from lyrics --- lib/bottles.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index cd92745..4bd78d3 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,15 +1,14 @@ class Bottles def verse(number) if number == 99 - "99 bottles of beer on the wall, " + - "99 bottles of beer.\n" + - "Take one down and pass it around, " + - "98 bottles of beer on the wall.\n" + n = 99 else - "3 bottles of beer on the wall, " + - "3 bottles of beer.\n" + - "Take one down and pass it around, " + - "2 bottles of beer on the wall.\n" + n = 3 end + + "#{n} bottles of beer on the wall, " + + "#{n} bottles of beer.\n" + + "Take one down and pass it around, " + + "#{n - 1} bottles of beer on the wall.\n" end end \ No newline at end of file From 32c3b62d1b841677b97728118052a37d6bd7336f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:31:38 -0400 Subject: [PATCH 015/285] interpolate number into verse string --- lib/bottles.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4bd78d3..50faafd 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,14 +1,8 @@ class Bottles def verse(number) - if number == 99 - n = 99 - else - n = 3 - end - - "#{n} bottles of beer on the wall, " + - "#{n} bottles of beer.\n" + + "#{number} bottles of beer on the wall, " + + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{n - 1} bottles of beer on the wall.\n" + "#{number-1} bottles of beer on the wall.\n" end end \ No newline at end of file From 448f654a28ef66a98a4c51b19eb98caf2e3b737f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:32:46 -0400 Subject: [PATCH 016/285] verse 2 test --- test/bottles_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index fb75c22..a291934 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -21,4 +21,13 @@ def test_another_verse "2 bottles of beer on the wall.\n" assert_equal expected, Bottles.new.verse(3) end + + def test_verse_2 + expected = + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(2) + end end From 850d91d222a8ead1e795a79610d37e126a323eab Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:34:35 -0400 Subject: [PATCH 017/285] pass 2 test with outer conditional --- lib/bottles.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 50faafd..d38d1e1 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,8 +1,15 @@ class Bottles def verse(number) - "#{number} bottles of beer on the wall, " + - "#{number} bottles of beer.\n" + - "Take one down and pass it around, " + - "#{number-1} bottles of beer on the wall.\n" + if number == 2 + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" + else + "#{number} bottles of beer on the wall, " + + "#{number} bottles of beer.\n" + + "Take one down and pass it around, " + + "#{number-1} bottles of beer on the wall.\n" + end end end \ No newline at end of file From 95bc492798a8ff5e8ab5979cde682bb0cc942304 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:35:15 -0400 Subject: [PATCH 018/285] pass 2 test with inner conditional --- lib/bottles.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index d38d1e1..91af8e0 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,15 +1,9 @@ class Bottles def verse(number) - if number == 2 - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" - else - "#{number} bottles of beer on the wall, " + - "#{number} bottles of beer.\n" + - "Take one down and pass it around, " + - "#{number-1} bottles of beer on the wall.\n" - end + "#{number} bottles of beer on the wall, " + + "#{number} bottles of beer.\n" + + "Take one down and pass it around, " + + "#{number-1} bottle#{'s' unless (number-1) == 1} of beer " + + "on the wall.\n" end end \ No newline at end of file From 4d0277834240eaffb8f62bffd8d64a85b29d1f4a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:36:48 -0400 Subject: [PATCH 019/285] revert to outer conditional --- lib/bottles.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 91af8e0..d38d1e1 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,9 +1,15 @@ class Bottles def verse(number) - "#{number} bottles of beer on the wall, " + - "#{number} bottles of beer.\n" + - "Take one down and pass it around, " + - "#{number-1} bottle#{'s' unless (number-1) == 1} of beer " + - "on the wall.\n" + if number == 2 + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" + else + "#{number} bottles of beer on the wall, " + + "#{number} bottles of beer.\n" + + "Take one down and pass it around, " + + "#{number-1} bottles of beer on the wall.\n" + end end end \ No newline at end of file From 733786bfef7897dc716ca6b5166ccf716d3ffe70 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:37:58 -0400 Subject: [PATCH 020/285] verse 1 test --- test/bottles_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index a291934..50bdc0e 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -30,4 +30,13 @@ def test_verse_2 "1 bottle of beer on the wall.\n" assert_equal expected, Bottles.new.verse(2) end + + def test_verse_1 + expected = + "1 bottle of beer on the wall, " + + "1 bottle of beer.\n" + + "Take it down and pass it around, " + + "no more bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(1) + end end From c3a11e4460a9f9e80b6dea1ec7181407bd0d6af2 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:38:55 -0400 Subject: [PATCH 021/285] pass 1 test --- lib/bottles.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index d38d1e1..97e9c68 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,6 +1,12 @@ class Bottles def verse(number) - if number == 2 + case number + when 1 + "1 bottle of beer on the wall, " + + "1 bottle of beer.\n" + + "Take it down and pass it around, " + + "no more bottles of beer on the wall.\n" + when 2 "2 bottles of beer on the wall, " + "2 bottles of beer.\n" + "Take one down and pass it around, " + From e589d40100672f31b21874938e794abd6b49bd2e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:39:38 -0400 Subject: [PATCH 022/285] verse 0 test --- test/bottles_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 50bdc0e..a26e63d 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -39,4 +39,13 @@ def test_verse_1 "no more bottles of beer on the wall.\n" assert_equal expected, Bottles.new.verse(1) end + + def test_verse_0 + expected = + "No more bottles of beer on the wall, " + + "no more bottles of beer.\n" + + "Go to the store and buy some more, " + + "99 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(0) + end end From 39af9e0965618da6f890f4b7061e30544250bfa1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:40:11 -0400 Subject: [PATCH 023/285] pass 0 test --- lib/bottles.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 97e9c68..1137f1f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,6 +1,11 @@ class Bottles def verse(number) case number + when 0 + "No more bottles of beer on the wall, " + + "no more bottles of beer.\n" + + "Go to the store and buy some more, " + + "99 bottles of beer on the wall.\n" when 1 "1 bottle of beer on the wall, " + "1 bottle of beer.\n" + From ce2f7da0e7f789145fdb735f66fcfcc2e772fb47 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:42:12 -0400 Subject: [PATCH 024/285] verses test #1 --- test/bottles_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index a26e63d..376c33b 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -48,4 +48,18 @@ def test_verse_0 "99 bottles of beer on the wall.\n" assert_equal expected, Bottles.new.verse(0) end + + def test_a_couple_verses + expected = + "99 bottles of beer on the wall, " + + "99 bottles of beer.\n" + + "Take one down and pass it around, " + + "98 bottles of beer on the wall.\n" + + "\n" + + "98 bottles of beer on the wall, " + + "98 bottles of beer.\n" + + "Take one down and pass it around, " + + "97 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verses(99, 98) + end end From 1cf87f760d9e681217eaedd88d2ea301df9e52d3 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:42:59 -0400 Subject: [PATCH 025/285] pass verses test #1 w/literal --- lib/bottles.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 1137f1f..4faaf42 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,4 +23,16 @@ def verse(number) "#{number-1} bottles of beer on the wall.\n" end end + + def verses(_, _) + "99 bottles of beer on the wall, " + + "99 bottles of beer.\n" + + "Take one down and pass it around, " + + "98 bottles of beer on the wall.\n" + + "\n" + + "98 bottles of beer on the wall, " + + "98 bottles of beer.\n" + + "Take one down and pass it around, " + + "97 bottles of beer on the wall.\n" + end end \ No newline at end of file From fdabde73c91d6ac4642d870f1cff00865ac0f809 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:44:02 -0400 Subject: [PATCH 026/285] pass verses test #1 w/verse 99 + 98 --- lib/bottles.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4faaf42..f5a1400 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,14 +25,6 @@ def verse(number) end def verses(_, _) - "99 bottles of beer on the wall, " + - "99 bottles of beer.\n" + - "Take one down and pass it around, " + - "98 bottles of beer on the wall.\n" + - "\n" + - "98 bottles of beer on the wall, " + - "98 bottles of beer.\n" + - "Take one down and pass it around, " + - "97 bottles of beer on the wall.\n" + verse(99) + "\n" + verse(98) end end \ No newline at end of file From f7572cb4d5bab41d08582a7fbd61eacdd623f323 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:44:47 -0400 Subject: [PATCH 027/285] verses test #2 --- test/bottles_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 376c33b..df5ed5b 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -62,4 +62,23 @@ def test_a_couple_verses "97 bottles of beer on the wall.\n" assert_equal expected, Bottles.new.verses(99, 98) end + + def test_a_few_verses + expected = + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" + + "\n" + + "1 bottle of beer on the wall, " + + "1 bottle of beer.\n" + + "Take it down and pass it around, " + + "no more bottles of beer on the wall.\n" + + "\n" + + "No more bottles of beer on the wall, " + + "no more bottles of beer.\n" + + "Go to the store and buy some more, " + + "99 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verses(2, 0) + end end From 5a7a9ae8433b4b43b616c512598121e28d6adb3e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:49:21 -0400 Subject: [PATCH 028/285] pass verses test #2 w crazy talk --- lib/bottles.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f5a1400..abfc416 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,7 +24,11 @@ def verse(number) end end - def verses(_, _) - verse(99) + "\n" + verse(98) + def verses(upper, lower) + if upper == 99 + verse(99) + "\n" + verse(98) + else + verse(2) + "\n" + verse(1) + "\n" + verse(0) + end end end \ No newline at end of file From 6ae138bd8974956048f5211c3da91e88c191664b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:49:52 -0400 Subject: [PATCH 029/285] pass verses test #2 by looping over verse --- lib/bottles.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index abfc416..a01c33a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,10 +25,6 @@ def verse(number) end def verses(upper, lower) - if upper == 99 - verse(99) + "\n" + verse(98) - else - verse(2) + "\n" + verse(1) + "\n" + verse(0) - end + upper.downto(lower).collect {|i| verse(i)}.join("\n") end end \ No newline at end of file From acb3a583055a8a9cb45f58c38008f51e134e6828 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:58:59 -0400 Subject: [PATCH 030/285] move verses method to top --- lib/bottles.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a01c33a..876141f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,4 +1,8 @@ class Bottles + def verses(upper, lower) + upper.downto(lower).collect {|i| verse(i)}.join("\n") + end + def verse(number) case number when 0 @@ -23,8 +27,4 @@ def verse(number) "#{number-1} bottles of beer on the wall.\n" end end - - def verses(upper, lower) - upper.downto(lower).collect {|i| verse(i)}.join("\n") - end end \ No newline at end of file From a3252094b3bf663d6009af7910759311a6eae54b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 11:59:26 -0400 Subject: [PATCH 031/285] add untested song method --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 876141f..54ce5a0 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,4 +1,8 @@ class Bottles + def song + verses(99,0) + end + def verses(upper, lower) upper.downto(lower).collect {|i| verse(i)}.join("\n") end From 49c45666037f2804246fe82f784637b7c994073d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 13:08:21 -0400 Subject: [PATCH 032/285] song test #1 echo chamber --- test/bottles_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index df5ed5b..f675f77 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -81,4 +81,9 @@ def test_a_few_verses "99 bottles of beer on the wall.\n" assert_equal expected, Bottles.new.verses(2, 0) end + + def test_the_whole_song + bottles = Bottles.new + assert_equal bottles.verses(99, 0), bottles.song + end end From 6ee96925f8d4ca4c07c6bc01f4aaf1b6555928f7 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 13:21:59 -0400 Subject: [PATCH 033/285] badly broken verses alternative --- lib/bottles.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 54ce5a0..d7ef8c3 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -7,6 +7,16 @@ def verses(upper, lower) upper.downto(lower).collect {|i| verse(i)}.join("\n") end + def verses(upper, lower) + if upper == 99 && lower == 98 + verse(99) + "\n" + verse(98) + elsif upper == 2 + verse(2) + "\n" + verse(1) + "\n" + verse(0) + else + "ok" + end + end + def verse(number) case number when 0 @@ -31,4 +41,4 @@ def verse(number) "#{number-1} bottles of beer on the wall.\n" end end -end \ No newline at end of file +end From 7f87c4d895588f13a320233fbec359bc1b7a7808 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 13:25:52 -0400 Subject: [PATCH 034/285] remove badly broken verses alternative --- lib/bottles.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index d7ef8c3..54ce5a0 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -7,16 +7,6 @@ def verses(upper, lower) upper.downto(lower).collect {|i| verse(i)}.join("\n") end - def verses(upper, lower) - if upper == 99 && lower == 98 - verse(99) + "\n" + verse(98) - elsif upper == 2 - verse(2) + "\n" + verse(1) + "\n" + verse(0) - else - "ok" - end - end - def verse(number) case number when 0 @@ -41,4 +31,4 @@ def verse(number) "#{number-1} bottles of beer on the wall.\n" end end -end +end \ No newline at end of file From 58842e643496a4dadf7803bbd093d572f4c92066 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 13:27:24 -0400 Subject: [PATCH 035/285] song test #2 echo chamber again --- test/bottles_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index f675f77..8e4dc3d 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -84,6 +84,9 @@ def test_a_few_verses def test_the_whole_song bottles = Bottles.new - assert_equal bottles.verses(99, 0), bottles.song + expected = + 99.downto(0).collect {|i| bottles.verse(i) + }.join("\n") + assert_equal expected, bottles.song end end From 0ca68624ee7581dd7e83097aa5d1801a5d55d70d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 13:31:14 -0400 Subject: [PATCH 036/285] song test #3-just write it down --- test/bottles_test.rb | 307 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 302 insertions(+), 5 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 8e4dc3d..2a4ff63 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -83,10 +83,307 @@ def test_a_few_verses end def test_the_whole_song - bottles = Bottles.new - expected = - 99.downto(0).collect {|i| bottles.verse(i) - }.join("\n") - assert_equal expected, bottles.song + expected = <<~SONG + 99 bottles of beer on the wall, 99 bottles of beer. + Take one down and pass it around, 98 bottles of beer on the wall. + + 98 bottles of beer on the wall, 98 bottles of beer. + Take one down and pass it around, 97 bottles of beer on the wall. + + 97 bottles of beer on the wall, 97 bottles of beer. + Take one down and pass it around, 96 bottles of beer on the wall. + + 96 bottles of beer on the wall, 96 bottles of beer. + Take one down and pass it around, 95 bottles of beer on the wall. + + 95 bottles of beer on the wall, 95 bottles of beer. + Take one down and pass it around, 94 bottles of beer on the wall. + + 94 bottles of beer on the wall, 94 bottles of beer. + Take one down and pass it around, 93 bottles of beer on the wall. + + 93 bottles of beer on the wall, 93 bottles of beer. + Take one down and pass it around, 92 bottles of beer on the wall. + + 92 bottles of beer on the wall, 92 bottles of beer. + Take one down and pass it around, 91 bottles of beer on the wall. + + 91 bottles of beer on the wall, 91 bottles of beer. + Take one down and pass it around, 90 bottles of beer on the wall. + + 90 bottles of beer on the wall, 90 bottles of beer. + Take one down and pass it around, 89 bottles of beer on the wall. + + 89 bottles of beer on the wall, 89 bottles of beer. + Take one down and pass it around, 88 bottles of beer on the wall. + + 88 bottles of beer on the wall, 88 bottles of beer. + Take one down and pass it around, 87 bottles of beer on the wall. + + 87 bottles of beer on the wall, 87 bottles of beer. + Take one down and pass it around, 86 bottles of beer on the wall. + + 86 bottles of beer on the wall, 86 bottles of beer. + Take one down and pass it around, 85 bottles of beer on the wall. + + 85 bottles of beer on the wall, 85 bottles of beer. + Take one down and pass it around, 84 bottles of beer on the wall. + + 84 bottles of beer on the wall, 84 bottles of beer. + Take one down and pass it around, 83 bottles of beer on the wall. + + 83 bottles of beer on the wall, 83 bottles of beer. + Take one down and pass it around, 82 bottles of beer on the wall. + + 82 bottles of beer on the wall, 82 bottles of beer. + Take one down and pass it around, 81 bottles of beer on the wall. + + 81 bottles of beer on the wall, 81 bottles of beer. + Take one down and pass it around, 80 bottles of beer on the wall. + + 80 bottles of beer on the wall, 80 bottles of beer. + Take one down and pass it around, 79 bottles of beer on the wall. + + 79 bottles of beer on the wall, 79 bottles of beer. + Take one down and pass it around, 78 bottles of beer on the wall. + + 78 bottles of beer on the wall, 78 bottles of beer. + Take one down and pass it around, 77 bottles of beer on the wall. + + 77 bottles of beer on the wall, 77 bottles of beer. + Take one down and pass it around, 76 bottles of beer on the wall. + + 76 bottles of beer on the wall, 76 bottles of beer. + Take one down and pass it around, 75 bottles of beer on the wall. + + 75 bottles of beer on the wall, 75 bottles of beer. + Take one down and pass it around, 74 bottles of beer on the wall. + + 74 bottles of beer on the wall, 74 bottles of beer. + Take one down and pass it around, 73 bottles of beer on the wall. + + 73 bottles of beer on the wall, 73 bottles of beer. + Take one down and pass it around, 72 bottles of beer on the wall. + + 72 bottles of beer on the wall, 72 bottles of beer. + Take one down and pass it around, 71 bottles of beer on the wall. + + 71 bottles of beer on the wall, 71 bottles of beer. + Take one down and pass it around, 70 bottles of beer on the wall. + + 70 bottles of beer on the wall, 70 bottles of beer. + Take one down and pass it around, 69 bottles of beer on the wall. + + 69 bottles of beer on the wall, 69 bottles of beer. + Take one down and pass it around, 68 bottles of beer on the wall. + + 68 bottles of beer on the wall, 68 bottles of beer. + Take one down and pass it around, 67 bottles of beer on the wall. + + 67 bottles of beer on the wall, 67 bottles of beer. + Take one down and pass it around, 66 bottles of beer on the wall. + + 66 bottles of beer on the wall, 66 bottles of beer. + Take one down and pass it around, 65 bottles of beer on the wall. + + 65 bottles of beer on the wall, 65 bottles of beer. + Take one down and pass it around, 64 bottles of beer on the wall. + + 64 bottles of beer on the wall, 64 bottles of beer. + Take one down and pass it around, 63 bottles of beer on the wall. + + 63 bottles of beer on the wall, 63 bottles of beer. + Take one down and pass it around, 62 bottles of beer on the wall. + + 62 bottles of beer on the wall, 62 bottles of beer. + Take one down and pass it around, 61 bottles of beer on the wall. + + 61 bottles of beer on the wall, 61 bottles of beer. + Take one down and pass it around, 60 bottles of beer on the wall. + + 60 bottles of beer on the wall, 60 bottles of beer. + Take one down and pass it around, 59 bottles of beer on the wall. + + 59 bottles of beer on the wall, 59 bottles of beer. + Take one down and pass it around, 58 bottles of beer on the wall. + + 58 bottles of beer on the wall, 58 bottles of beer. + Take one down and pass it around, 57 bottles of beer on the wall. + + 57 bottles of beer on the wall, 57 bottles of beer. + Take one down and pass it around, 56 bottles of beer on the wall. + + 56 bottles of beer on the wall, 56 bottles of beer. + Take one down and pass it around, 55 bottles of beer on the wall. + + 55 bottles of beer on the wall, 55 bottles of beer. + Take one down and pass it around, 54 bottles of beer on the wall. + + 54 bottles of beer on the wall, 54 bottles of beer. + Take one down and pass it around, 53 bottles of beer on the wall. + + 53 bottles of beer on the wall, 53 bottles of beer. + Take one down and pass it around, 52 bottles of beer on the wall. + + 52 bottles of beer on the wall, 52 bottles of beer. + Take one down and pass it around, 51 bottles of beer on the wall. + + 51 bottles of beer on the wall, 51 bottles of beer. + Take one down and pass it around, 50 bottles of beer on the wall. + + 50 bottles of beer on the wall, 50 bottles of beer. + Take one down and pass it around, 49 bottles of beer on the wall. + + 49 bottles of beer on the wall, 49 bottles of beer. + Take one down and pass it around, 48 bottles of beer on the wall. + + 48 bottles of beer on the wall, 48 bottles of beer. + Take one down and pass it around, 47 bottles of beer on the wall. + + 47 bottles of beer on the wall, 47 bottles of beer. + Take one down and pass it around, 46 bottles of beer on the wall. + + 46 bottles of beer on the wall, 46 bottles of beer. + Take one down and pass it around, 45 bottles of beer on the wall. + + 45 bottles of beer on the wall, 45 bottles of beer. + Take one down and pass it around, 44 bottles of beer on the wall. + + 44 bottles of beer on the wall, 44 bottles of beer. + Take one down and pass it around, 43 bottles of beer on the wall. + + 43 bottles of beer on the wall, 43 bottles of beer. + Take one down and pass it around, 42 bottles of beer on the wall. + + 42 bottles of beer on the wall, 42 bottles of beer. + Take one down and pass it around, 41 bottles of beer on the wall. + + 41 bottles of beer on the wall, 41 bottles of beer. + Take one down and pass it around, 40 bottles of beer on the wall. + + 40 bottles of beer on the wall, 40 bottles of beer. + Take one down and pass it around, 39 bottles of beer on the wall. + + 39 bottles of beer on the wall, 39 bottles of beer. + Take one down and pass it around, 38 bottles of beer on the wall. + + 38 bottles of beer on the wall, 38 bottles of beer. + Take one down and pass it around, 37 bottles of beer on the wall. + + 37 bottles of beer on the wall, 37 bottles of beer. + Take one down and pass it around, 36 bottles of beer on the wall. + + 36 bottles of beer on the wall, 36 bottles of beer. + Take one down and pass it around, 35 bottles of beer on the wall. + + 35 bottles of beer on the wall, 35 bottles of beer. + Take one down and pass it around, 34 bottles of beer on the wall. + + 34 bottles of beer on the wall, 34 bottles of beer. + Take one down and pass it around, 33 bottles of beer on the wall. + + 33 bottles of beer on the wall, 33 bottles of beer. + Take one down and pass it around, 32 bottles of beer on the wall. + + 32 bottles of beer on the wall, 32 bottles of beer. + Take one down and pass it around, 31 bottles of beer on the wall. + + 31 bottles of beer on the wall, 31 bottles of beer. + Take one down and pass it around, 30 bottles of beer on the wall. + + 30 bottles of beer on the wall, 30 bottles of beer. + Take one down and pass it around, 29 bottles of beer on the wall. + + 29 bottles of beer on the wall, 29 bottles of beer. + Take one down and pass it around, 28 bottles of beer on the wall. + + 28 bottles of beer on the wall, 28 bottles of beer. + Take one down and pass it around, 27 bottles of beer on the wall. + + 27 bottles of beer on the wall, 27 bottles of beer. + Take one down and pass it around, 26 bottles of beer on the wall. + + 26 bottles of beer on the wall, 26 bottles of beer. + Take one down and pass it around, 25 bottles of beer on the wall. + + 25 bottles of beer on the wall, 25 bottles of beer. + Take one down and pass it around, 24 bottles of beer on the wall. + + 24 bottles of beer on the wall, 24 bottles of beer. + Take one down and pass it around, 23 bottles of beer on the wall. + + 23 bottles of beer on the wall, 23 bottles of beer. + Take one down and pass it around, 22 bottles of beer on the wall. + + 22 bottles of beer on the wall, 22 bottles of beer. + Take one down and pass it around, 21 bottles of beer on the wall. + + 21 bottles of beer on the wall, 21 bottles of beer. + Take one down and pass it around, 20 bottles of beer on the wall. + + 20 bottles of beer on the wall, 20 bottles of beer. + Take one down and pass it around, 19 bottles of beer on the wall. + + 19 bottles of beer on the wall, 19 bottles of beer. + Take one down and pass it around, 18 bottles of beer on the wall. + + 18 bottles of beer on the wall, 18 bottles of beer. + Take one down and pass it around, 17 bottles of beer on the wall. + + 17 bottles of beer on the wall, 17 bottles of beer. + Take one down and pass it around, 16 bottles of beer on the wall. + + 16 bottles of beer on the wall, 16 bottles of beer. + Take one down and pass it around, 15 bottles of beer on the wall. + + 15 bottles of beer on the wall, 15 bottles of beer. + Take one down and pass it around, 14 bottles of beer on the wall. + + 14 bottles of beer on the wall, 14 bottles of beer. + Take one down and pass it around, 13 bottles of beer on the wall. + + 13 bottles of beer on the wall, 13 bottles of beer. + Take one down and pass it around, 12 bottles of beer on the wall. + + 12 bottles of beer on the wall, 12 bottles of beer. + Take one down and pass it around, 11 bottles of beer on the wall. + + 11 bottles of beer on the wall, 11 bottles of beer. + Take one down and pass it around, 10 bottles of beer on the wall. + + 10 bottles of beer on the wall, 10 bottles of beer. + Take one down and pass it around, 9 bottles of beer on the wall. + + 9 bottles of beer on the wall, 9 bottles of beer. + Take one down and pass it around, 8 bottles of beer on the wall. + + 8 bottles of beer on the wall, 8 bottles of beer. + Take one down and pass it around, 7 bottles of beer on the wall. + + 7 bottles of beer on the wall, 7 bottles of beer. + Take one down and pass it around, 6 bottles of beer on the wall. + + 6 bottles of beer on the wall, 6 bottles of beer. + Take one down and pass it around, 5 bottles of beer on the wall. + + 5 bottles of beer on the wall, 5 bottles of beer. + Take one down and pass it around, 4 bottles of beer on the wall. + + 4 bottles of beer on the wall, 4 bottles of beer. + Take one down and pass it around, 3 bottles of beer on the wall. + + 3 bottles of beer on the wall, 3 bottles of beer. + Take one down and pass it around, 2 bottles of beer on the wall. + + 2 bottles of beer on the wall, 2 bottles of beer. + Take one down and pass it around, 1 bottle of beer on the wall. + + 1 bottle of beer on the wall, 1 bottle of beer. + Take it down and pass it around, no more bottles of beer on the wall. + + No more bottles of beer on the wall, no more bottles of beer. + Go to the store and buy some more, 99 bottles of beer on the wall. + SONG + assert_equal expected, Bottles.new.song end end From 8fbc51955e8ee5ce1246e625ede407fed8113b06 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:23:55 -0400 Subject: [PATCH 037/285] add case 6/7 to verse --- lib/bottles.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 54ce5a0..df5aba4 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,6 +24,16 @@ def verse(number) "2 bottles of beer.\n" + "Take one down and pass it around, " + "1 bottle of beer on the wall.\n" + when 6 + "1 six-pack of beer on the wall, " + + "1 six-pack of beer.\n" + + "Take one down and pass it around, " + + "5 bottles of beer on the wall.\n" + when 7 + "7 bottles of beer on the wall, " + + "7 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 six-pack of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + From 5cdb6b1bd2cc44adfa4480a859889cad771a3ba9 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:24:37 -0400 Subject: [PATCH 038/285] revert case 6/7 --- lib/bottles.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index df5aba4..54ce5a0 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,16 +24,6 @@ def verse(number) "2 bottles of beer.\n" + "Take one down and pass it around, " + "1 bottle of beer on the wall.\n" - when 6 - "1 six-pack of beer on the wall, " + - "1 six-pack of beer.\n" + - "Take one down and pass it around, " + - "5 bottles of beer on the wall.\n" - when 7 - "7 bottles of beer on the wall, " + - "7 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 six-pack of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + From 8bbdda792f7dbb808b2d13f1dd65f670be7e1e27 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:25:56 -0400 Subject: [PATCH 039/285] interpolate number in 2 case --- lib/bottles.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 54ce5a0..e21ef8e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -20,10 +20,10 @@ def verse(number) "Take it down and pass it around, " + "no more bottles of beer on the wall.\n" when 2 - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + + "#{number} bottles of beer on the wall, " + + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" + "#{number-1} bottle of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + From 6472691721ab67da1c0ce188cff1472c399c4b3c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:27:10 -0400 Subject: [PATCH 040/285] fling entire container method in --- lib/bottles.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e21ef8e..e1be86b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,12 +23,20 @@ def verse(number) "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} bottle of beer on the wall.\n" + "#{number-1} #{container(number-1)} of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} bottles of beer on the wall.\n" + "#{number-1} #{container(number-1)} of beer on the wall.\n" end end -end \ No newline at end of file + + def container(number) + if number == 1 + "bottle" + else + "bottles" + end + end +end From bcf25702ea515950e42f4571d1dc41ff6c92b9bd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:28:01 -0400 Subject: [PATCH 041/285] revert prior change --- lib/bottles.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e1be86b..e21ef8e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,20 +23,12 @@ def verse(number) "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} #{container(number-1)} of beer on the wall.\n" + "#{number-1} bottle of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} #{container(number-1)} of beer on the wall.\n" + "#{number-1} bottles of beer on the wall.\n" end end - - def container(number) - if number == 1 - "bottle" - else - "bottles" - end - end -end +end \ No newline at end of file From 8bf693d99d5e29c6a67d651e8f8f65371c479614 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:30:59 -0400 Subject: [PATCH 042/285] add empty container method --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index e21ef8e..3ab08f7 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -31,4 +31,7 @@ def verse(number) "#{number-1} bottles of beer on the wall.\n" end end + + def container + end end \ No newline at end of file From 2ffce1e991077b256ae793debad334c0aafcb6a9 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:31:11 -0400 Subject: [PATCH 043/285] return 'bottles' in container --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3ab08f7..a293f27 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -33,5 +33,6 @@ def verse(number) end def container + "bottles" end end \ No newline at end of file From 1ce89b7d23c75d97705315f4cb4f3faa6ae42a1d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:31:44 -0400 Subject: [PATCH 044/285] send #container in default --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a293f27..8fbaf9f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,7 +28,7 @@ def verse(number) "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} bottles of beer on the wall.\n" + "#{number-1} #{container} of beer on the wall.\n" end end From 8bbad05cb5a40a6094d3559597dc2f20fd7afd44 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:32:13 -0400 Subject: [PATCH 045/285] add defaulted arg to container --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8fbaf9f..5dd998a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -32,7 +32,7 @@ def verse(number) end end - def container + def container(number=:FIXME) "bottles" end end \ No newline at end of file From 30f83f451c487d341706632b359fd522e03f1a7d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:32:48 -0400 Subject: [PATCH 046/285] add entire conditional to container --- lib/bottles.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5dd998a..f6eb80b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -33,6 +33,10 @@ def verse(number) end def container(number=:FIXME) - "bottles" + if number == 1 + "bottle" + else + "bottles" + end end end \ No newline at end of file From 103e78da802911186cae7ce16e3c9cf0d669ac27 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 15:33:33 -0400 Subject: [PATCH 047/285] pass arg when sending #container --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f6eb80b..a1bd928 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,7 +28,7 @@ def verse(number) "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} #{container} of beer on the wall.\n" + "#{number-1} #{container(number-1)} of beer on the wall.\n" end end From a27d249dfba58072fbcb7674c47272606bff5cd1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:09:14 -0400 Subject: [PATCH 048/285] use #container in 2 case --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a1bd928..ed9543c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,7 +23,7 @@ def verse(number) "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + - "#{number-1} bottle of beer on the wall.\n" + "#{number-1} #{container(number-1)} of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + From bb7075833627cbf741d98fd514440f19af545bb2 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:09:52 -0400 Subject: [PATCH 049/285] remove obsolete default arg --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ed9543c..088170f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -32,7 +32,7 @@ def verse(number) end end - def container(number=:FIXME) + def container(number) if number == 1 "bottle" else From c557716a7eb81e878a7da244b0da61132ce68493 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:10:08 -0400 Subject: [PATCH 050/285] delete obsolete 2 case --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 088170f..ac9c47c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,11 +19,6 @@ def verse(number) "1 bottle of beer.\n" + "Take it down and pass it around, " + "no more bottles of beer on the wall.\n" - when 2 - "#{number} bottles of beer on the wall, " + - "#{number} bottles of beer.\n" + - "Take one down and pass it around, " + - "#{number-1} #{container(number-1)} of beer on the wall.\n" else "#{number} bottles of beer on the wall, " + "#{number} bottles of beer.\n" + From acc5aeac78541503a1478dd68d0075f53ac768f7 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:33:50 -0400 Subject: [PATCH 051/285] interpolate number at start of 1 case --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ac9c47c..da5308c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -15,7 +15,7 @@ def verse(number) "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" when 1 - "1 bottle of beer on the wall, " + + "#{number} bottle of beer on the wall, " + "1 bottle of beer.\n" + "Take it down and pass it around, " + "no more bottles of beer on the wall.\n" From 70a1d30692c48d0f286c2b5df83c00d327e7926d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:34:39 -0400 Subject: [PATCH 052/285] send #container in phrase 1 case 1 --- lib/bottles.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index da5308c..6f768e6 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -15,12 +15,12 @@ def verse(number) "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" when 1 - "#{number} bottle of beer on the wall, " + + "#{number} #{container(number)} of beer on the wall, " + "1 bottle of beer.\n" + "Take it down and pass it around, " + "no more bottles of beer on the wall.\n" else - "#{number} bottles of beer on the wall, " + + "#{number} #{container(number)} of beer on the wall, " + "#{number} bottles of beer.\n" + "Take one down and pass it around, " + "#{number-1} #{container(number-1)} of beer on the wall.\n" @@ -34,4 +34,4 @@ def container(number) "bottles" end end -end \ No newline at end of file +end From 821013c917a7dac05d24894a0968ede30b426d84 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:36:49 -0400 Subject: [PATCH 053/285] make phrase 1/2 of case 1/else identical --- lib/bottles.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6f768e6..0872400 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -16,12 +16,12 @@ def verse(number) "99 bottles of beer on the wall.\n" when 1 "#{number} #{container(number)} of beer on the wall, " + - "1 bottle of beer.\n" + + "#{number} #{container(number)} of beer.\n" + "Take it down and pass it around, " + "no more bottles of beer on the wall.\n" else "#{number} #{container(number)} of beer on the wall, " + - "#{number} bottles of beer.\n" + + "#{number} #{container(number)} of beer.\n" + "Take one down and pass it around, " + "#{number-1} #{container(number-1)} of beer on the wall.\n" end @@ -34,4 +34,4 @@ def container(number) "bottles" end end -end +end \ No newline at end of file From bef2d99d06ce120822c89708d4cdb80749f2e543 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:39:54 -0400 Subject: [PATCH 054/285] add pronoun --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0872400..946a45e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -34,4 +34,7 @@ def container(number) "bottles" end end + + def pronoun + end end \ No newline at end of file From ab7f687bcd291b2d39bcabc8ed47cfedde1f5f9a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:40:11 -0400 Subject: [PATCH 055/285] pronoun returns 'one' --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 946a45e..b9e1dc8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -36,5 +36,6 @@ def container(number) end def pronoun + "one" end end \ No newline at end of file From dc3c1633a312f90dd03539dfdf50662de9ad8339 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:40:44 -0400 Subject: [PATCH 056/285] send pronoun in else --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b9e1dc8..f325315 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -22,7 +22,7 @@ def verse(number) else "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + - "Take one down and pass it around, " + + "Take #{pronoun} down and pass it around, " + "#{number-1} #{container(number-1)} of beer on the wall.\n" end end From 008ec30af05b4e0860b1592bca08aaffcb285eeb Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:41:02 -0400 Subject: [PATCH 057/285] add defaulted arg to pronoun --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f325315..f65da6e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -35,7 +35,7 @@ def container(number) end end - def pronoun + def pronoun(number=:FIXME) "one" end end \ No newline at end of file From ebb9f06ee839f22bb2792c35bcc2f2ca78b585bf Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:41:38 -0400 Subject: [PATCH 058/285] use pronoun arg in if statement --- lib/bottles.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f65da6e..de370b1 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -36,6 +36,10 @@ def container(number) end def pronoun(number=:FIXME) - "one" + if number == 1 + "it" + else + "one" + end end end \ No newline at end of file From 8be9e2ecfccc80ca55b30c271ab115955aa9f734 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:42:19 -0400 Subject: [PATCH 059/285] pass arg to pronoun in else --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index de370b1..07b2491 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -22,7 +22,7 @@ def verse(number) else "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + - "Take #{pronoun} down and pass it around, " + + "Take #{pronoun(number)} down and pass it around, " + "#{number-1} #{container(number-1)} of beer on the wall.\n" end end From 0092a4f331ce97e7af8fba5ce9def79a46575aa6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:42:45 -0400 Subject: [PATCH 060/285] use pronoun arg in 1 case --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 07b2491..b2d6f79 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,7 +17,7 @@ def verse(number) when 1 "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + - "Take it down and pass it around, " + + "Take #{pronoun(number)} down and pass it around, " + "no more bottles of beer on the wall.\n" else "#{number} #{container(number)} of beer on the wall, " + From d7e74072ed005539fd031aa80f10124a075799bd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:43:14 -0400 Subject: [PATCH 061/285] remove obsolete arg from pronoun --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b2d6f79..ac354b5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -35,7 +35,7 @@ def container(number) end end - def pronoun(number=:FIXME) + def pronoun(number) if number == 1 "it" else From 12ecb9b2d18480a44097be30d3efee8095d3777a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:44:17 -0400 Subject: [PATCH 062/285] add quantity --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index ac354b5..b11de98 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -27,6 +27,9 @@ def verse(number) end end + def quantity + end + def container(number) if number == 1 "bottle" From e7914ace0d96273a645e16fb8cfaab76b3486c79 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:44:47 -0400 Subject: [PATCH 063/285] quantity returns 'no more' --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index b11de98..4eb4c59 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,6 +28,7 @@ def verse(number) end def quantity + "no more" end def container(number) From 9ce9cb7bb1ea7e6cbb4c9d2836b5e52fab040f85 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:45:31 -0400 Subject: [PATCH 064/285] 1 case sends quantity --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4eb4c59..215e238 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,7 +18,7 @@ def verse(number) "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + - "no more bottles of beer on the wall.\n" + "#{quantity} bottles of beer on the wall.\n" else "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + From 66721ac34b53b14ed8f8f47e9d51bd1cc580eba8 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:45:53 -0400 Subject: [PATCH 065/285] add arg and wrong default to quantity --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 215e238..dbea17f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -27,7 +27,7 @@ def verse(number) end end - def quantity + def quantity(number=:FIXME) "no more" end From d5610c9428596e8ee70ff44896a71136688b254c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:48:36 -0400 Subject: [PATCH 066/285] use wrong default in quantity conditional --- lib/bottles.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index dbea17f..64b5e3c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,7 +28,11 @@ def verse(number) end def quantity(number=:FIXME) - "no more" + if number == 0 + "no more" + else + number + end end def container(number) From ad81c8871963bbce6bdd8d2790a9768a632c66c6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:48:53 -0400 Subject: [PATCH 067/285] revert to green --- lib/bottles.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 64b5e3c..dbea17f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,11 +28,7 @@ def verse(number) end def quantity(number=:FIXME) - if number == 0 - "no more" - else - number - end + "no more" end def container(number) From b8e4da60b17463e6cfb23a1492e4f9ec4e12d4c1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:49:28 -0400 Subject: [PATCH 068/285] set quantity arg default to correct value --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index dbea17f..e9b5249 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -27,7 +27,7 @@ def verse(number) end end - def quantity(number=:FIXME) + def quantity(number=0) "no more" end From 3af4d676a8f9482116f9a820302bb3d91e22f6cb Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:50:17 -0400 Subject: [PATCH 069/285] use correct default in quantity conditional --- lib/bottles.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e9b5249..b2d07bf 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,7 +28,11 @@ def verse(number) end def quantity(number=0) - "no more" + if number == 0 + "no more" + else + number + end end def container(number) From a7d9f5d03ffa7ce327c667fe5824b7b2dbb2bac6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:51:16 -0400 Subject: [PATCH 070/285] send quantity(arg) in case 1 phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b2d07bf..2f1eaad 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,7 +18,7 @@ def verse(number) "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + - "#{quantity} bottles of beer on the wall.\n" + "#{quantity(number-1)} bottles of beer on the wall.\n" else "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + From e81781a0252fe6fee8876e9df89e32052b7f929d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:51:52 -0400 Subject: [PATCH 071/285] send quantity(arg) in else phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 2f1eaad..6dc2a44 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,7 +23,7 @@ def verse(number) "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + - "#{number-1} #{container(number-1)} of beer on the wall.\n" + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" end end From 50742cd4b2d69b8d75a99e8e83a27e52044fe39b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:52:13 -0400 Subject: [PATCH 072/285] remove obsolete default --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6dc2a44..40958c5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -27,7 +27,7 @@ def verse(number) end end - def quantity(number=0) + def quantity(number) if number == 0 "no more" else From 3eaf43f43dcbb4558a894ab2513040e9af5d9565 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:53:09 -0400 Subject: [PATCH 073/285] send container in case 1 phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 40958c5..09bfad1 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,7 +18,7 @@ def verse(number) "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + - "#{quantity(number-1)} bottles of beer on the wall.\n" + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" else "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + From 32002303b45531ffd3630a43297c5378a60b0256 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:53:34 -0400 Subject: [PATCH 074/285] delete case 1 --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 09bfad1..376a524 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,11 +14,6 @@ def verse(number) "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" - when 1 - "#{number} #{container(number)} of beer on the wall, " + - "#{number} #{container(number)} of beer.\n" + - "Take #{pronoun(number)} down and pass it around, " + - "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" else "#{number} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + From 97a689428505bfe6c5f75218499be637355dd77f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:54:44 -0400 Subject: [PATCH 075/285] send quantity in case 0 phrase 1 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 376a524..720abb7 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,7 +10,7 @@ def verses(upper, lower) def verse(number) case number when 0 - "No more bottles of beer on the wall, " + + "#{quantity(number).capitalize} bottles of beer on the wall, " + "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" From 40abbcfd28e2fea8aeb61fe7a15f0797f852b748 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:55:37 -0400 Subject: [PATCH 076/285] send quantity in else phrase 1, FAILS --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 720abb7..277474c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -15,7 +15,7 @@ def verse(number) "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" else - "#{number} #{container(number)} of beer on the wall, " + + "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" From 557aec59e1f761e997c127ecead6b9daec9bc9ea Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:56:20 -0400 Subject: [PATCH 077/285] hack to_s in else case to sidestep error --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 277474c..133bd3b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -15,7 +15,7 @@ def verse(number) "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" else - "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + + "#{quantity(number).to_s.capitalize} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" From 6ff0514d0d4d1f0734dbeecf8e94ad29f7ddf8db Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:56:48 -0400 Subject: [PATCH 078/285] add unneeded to_s to 1 case to make them the same --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 133bd3b..3a3ba1d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,7 +10,7 @@ def verses(upper, lower) def verse(number) case number when 0 - "#{quantity(number).capitalize} bottles of beer on the wall, " + + "#{quantity(number).to_s.capitalize} bottles of beer on the wall, " + "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" From 78194c579e2fa97564cfaa3c9da1e3e2407f9300 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:57:31 -0400 Subject: [PATCH 079/285] add to_s to #quantity, return a capitalizable --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3a3ba1d..2585549 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -26,7 +26,7 @@ def quantity(number) if number == 0 "no more" else - number + number.to_s end end From b1a6915f6332e62d2b51e2cfdf0fc340dc5a69dd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:57:59 -0400 Subject: [PATCH 080/285] remove obsolete to_s's --- lib/bottles.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 2585549..5e52470 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,12 +10,12 @@ def verses(upper, lower) def verse(number) case number when 0 - "#{quantity(number).to_s.capitalize} bottles of beer on the wall, " + + "#{quantity(number).capitalize} bottles of beer on the wall, " + "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" else - "#{quantity(number).to_s.capitalize} #{container(number)} of beer on the wall, " + + "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{number} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" From e996aef9a3f4589a26236e0a118e30b8d58e5d72 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:58:41 -0400 Subject: [PATCH 081/285] send container in case 0 phrase 1 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5e52470..3b4c86b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,7 +10,7 @@ def verses(upper, lower) def verse(number) case number when 0 - "#{quantity(number).capitalize} bottles of beer on the wall, " + + "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" From 7c030819ea7a22bb31189a787749b54b2a1b0a31 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 16:59:42 -0400 Subject: [PATCH 082/285] send quantity in else phrase 2 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3b4c86b..0f5c111 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -16,7 +16,7 @@ def verse(number) "99 bottles of beer on the wall.\n" else "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + - "#{number} #{container(number)} of beer.\n" + + "#{quantity(number)} #{container(number)} of beer.\n" + "Take #{pronoun(number)} down and pass it around, " + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" end From 20785df707024f01e043e4930514af15e090d323 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:00:23 -0400 Subject: [PATCH 083/285] make case 0 phrase 2 like else phrase 2 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0f5c111..177d66b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -11,7 +11,7 @@ def verse(number) case number when 0 "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + - "no more bottles of beer.\n" + + "#{quantity(number)} #{container(number)} of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" else From 1144261b5d79b10dd8f30543a8c09a3caad504e5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:02:25 -0400 Subject: [PATCH 084/285] add complete #action --- lib/bottles.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 177d66b..0bdc4cb 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -38,6 +38,14 @@ def container(number) end end + def action(number) + if number == 0 + "Go to the store and buy some more" + else + "Take #{pronoun(number)} down and pass it around" + end + end + def pronoun(number) if number == 1 "it" From e7b14e3f8af7acb462bb661cb4d7a55bcd5eebe6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:03:00 -0400 Subject: [PATCH 085/285] use #action --- lib/bottles.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0bdc4cb..4f46547 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -12,12 +12,12 @@ def verse(number) when 0 "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + - "Go to the store and buy some more, " + + "#{action(number)}, " + "99 bottles of beer on the wall.\n" else "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + - "Take #{pronoun(number)} down and pass it around, " + + "#{action(number)}, " + "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" end end From 943408938a8b59103ddb228a6f22f302a3e83631 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:05:58 -0400 Subject: [PATCH 086/285] send #quantity(99) --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4f46547..7b2fe90 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -13,7 +13,7 @@ def verse(number) "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "99 bottles of beer on the wall.\n" + "#{quantity(99)} bottles of beer on the wall.\n" else "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + From 1fb7d1fc4e5199c42cbc177f86ba6c7112c2da7b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:13:09 -0400 Subject: [PATCH 087/285] send container in case 0 phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 7b2fe90..88d1a02 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -13,7 +13,7 @@ def verse(number) "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "#{quantity(99)} bottles of beer on the wall.\n" + "#{quantity(99)} #{container(number-1)} of beer on the wall.\n" else "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + From 61ad1c5a5e594fdab30e8df1bd0f97980f610cac Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:13:37 -0400 Subject: [PATCH 088/285] add #successor(number) --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 88d1a02..ac79d6a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -53,4 +53,8 @@ def pronoun(number) "one" end end + + def successor(number) + number - 1 + end end \ No newline at end of file From f9fa810617e7fe8d9e7c61df04ab0f028b0011ec Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:14:10 -0400 Subject: [PATCH 089/285] send #successor in else phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ac79d6a..e7bd954 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,7 +18,7 @@ def verse(number) "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "#{quantity(number-1)} #{container(number-1)} of beer on the wall.\n" + "#{quantity(successor(number))} #{container(number-1)} of beer on the wall.\n" end end From c3132b8c6a5ac0172778eff3a4972a8360bb8f16 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:14:51 -0400 Subject: [PATCH 090/285] add conditional to #successor --- lib/bottles.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e7bd954..6d3e53e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -55,6 +55,10 @@ def pronoun(number) end def successor(number) - number - 1 + if number == 0 + 99 + else + number - 1 + end end end \ No newline at end of file From 9cbd3b8183b3c8a10d59938c20547eb81c1ee50b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:15:19 -0400 Subject: [PATCH 091/285] replace 99 with successor(number) --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6d3e53e..b5a7799 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -13,7 +13,7 @@ def verse(number) "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "#{quantity(99)} #{container(number-1)} of beer on the wall.\n" + "#{quantity(successor(number))} #{container(number-1)} of beer on the wall.\n" else "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + From 37ce41f888e587686e4844c75343d36d78271b0d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:16:25 -0400 Subject: [PATCH 092/285] use successor everywhere --- lib/bottles.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b5a7799..6a792b3 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -13,12 +13,12 @@ def verse(number) "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "#{quantity(successor(number))} #{container(number-1)} of beer on the wall.\n" + "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" else "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "#{quantity(successor(number))} #{container(number-1)} of beer on the wall.\n" + "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" end end From f98d9d87c32bdf66105c0c4f70f7f3a9125a0230 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:17:23 -0400 Subject: [PATCH 093/285] try common template --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6a792b3..e0db7fc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -20,6 +20,10 @@ def verse(number) "#{action(number)}, " + "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" end + "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + + "#{quantity(number)} #{container(number)} of beer.\n" + + "#{action(number)}, " + + "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" end def quantity(number) From 2fa7d051c1678e655f12d52a108c8e270be890a3 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 14 May 2020 17:17:41 -0400 Subject: [PATCH 094/285] delete obsolete code --- lib/bottles.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e0db7fc..f7b729e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,18 +8,6 @@ def verses(upper, lower) end def verse(number) - case number - when 0 - "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + - "#{quantity(number)} #{container(number)} of beer.\n" + - "#{action(number)}, " + - "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" - else - "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + - "#{quantity(number)} #{container(number)} of beer.\n" + - "#{action(number)}, " + - "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" - end "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + From 89a48743d4bf332462c2bdbe0a8ac15bcbbb0274 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 07:46:07 -0400 Subject: [PATCH 095/285] wrap long lines in verse --- lib/bottles.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f7b729e..a4f949b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,10 +8,12 @@ def verses(upper, lower) end def verse(number) - "#{quantity(number).capitalize} #{container(number)} of beer on the wall, " + + "#{quantity(number).capitalize} #{container(number)} " + + "of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{action(number)}, " + - "#{quantity(successor(number))} #{container(successor(number))} of beer on the wall.\n" + "#{quantity(successor(number))} #{container(successor(number))} " + + "of beer on the wall.\n" end def quantity(number) From a3214ee908702d0caa55d22cf7e1d74867039673 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 08:04:13 -0400 Subject: [PATCH 096/285] add empty BottleNumber class --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index a4f949b..6449491 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -55,4 +55,7 @@ def successor(number) number - 1 end end +end + +class BottleNumber end \ No newline at end of file From f6e5a122b9a369d43ed267553e3003ed5e22f1ab Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 08:04:52 -0400 Subject: [PATCH 097/285] copy obsessive methods to BottleNumber --- lib/bottles.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6449491..3f9e53d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -58,4 +58,43 @@ def successor(number) end class BottleNumber + def quantity(number) + if number == 0 + "no more" + else + number.to_s + end + end + + def container(number) + if number == 1 + "bottle" + else + "bottles" + end + end + + def action(number) + if number == 0 + "Go to the store and buy some more" + else + "Take #{pronoun(number)} down and pass it around" + end + end + + def pronoun(number) + if number == 1 + "it" + else + "one" + end + end + + def successor(number) + if number == 0 + 99 + else + number - 1 + end + end end \ No newline at end of file From a504be3efd898b03e634463aafd420dbe03c740e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 08:06:36 -0400 Subject: [PATCH 098/285] add attr_reader and initializer --- lib/bottles.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3f9e53d..427e272 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -58,6 +58,11 @@ def successor(number) end class BottleNumber + attr_reader :number + def initialize(number) + @number = number + end + def quantity(number) if number == 0 "no more" From 0052ae4dab92dad01705c6e8ac27682a06152275 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:05:05 -0400 Subject: [PATCH 099/285] parse/exec BottleNumber#quantity --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 427e272..af634f9 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,6 +17,7 @@ def verse(number) end def quantity(number) + BottleNumber.new(number).quantity(number) if number == 0 "no more" else From 08ce5ca87c2c863caddf5f36fc841e019ff83c52 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:05:47 -0400 Subject: [PATCH 100/285] use BottleNumber#quantity result --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index af634f9..0e53141 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,12 +17,12 @@ def verse(number) end def quantity(number) - BottleNumber.new(number).quantity(number) if number == 0 "no more" else number.to_s end + BottleNumber.new(number).quantity(number) end def container(number) From 1456e3d572e073d28aa171affc871ddd69f79d4b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:06:05 -0400 Subject: [PATCH 101/285] delete obsolete code --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0e53141..5d53e30 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,11 +17,6 @@ def verse(number) end def quantity(number) - if number == 0 - "no more" - else - number.to_s - end BottleNumber.new(number).quantity(number) end From 3e4f06a082e5e3ad50b635da303228253ea81031 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:06:42 -0400 Subject: [PATCH 102/285] parse/exec BottleNumber#container --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5d53e30..1064830 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,6 +21,7 @@ def quantity(number) end def container(number) + BottleNumber.new(number).container(number) if number == 1 "bottle" else From f8e6cad6c59b4e5acbf48a2fd4f8038b129f5844 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:07:00 -0400 Subject: [PATCH 103/285] use BottleNumber#container result --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 1064830..cd226a9 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,12 +21,12 @@ def quantity(number) end def container(number) - BottleNumber.new(number).container(number) if number == 1 "bottle" else "bottles" end + BottleNumber.new(number).container(number) end def action(number) From fc3a4354865591cff8af9c11a8fd9193d799d868 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:07:10 -0400 Subject: [PATCH 104/285] delete obsolete code --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index cd226a9..effd53f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,11 +21,6 @@ def quantity(number) end def container(number) - if number == 1 - "bottle" - else - "bottles" - end BottleNumber.new(number).container(number) end From 52e384c363c0148f18d9e84ea131f5b0d8b995f0 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:07:28 -0400 Subject: [PATCH 105/285] parse/exec BottleNumber#action --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index effd53f..8cf0c86 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,6 +25,7 @@ def container(number) end def action(number) + BottleNumber.new(number).action(number) if number == 0 "Go to the store and buy some more" else From b43f221e79de744d0cddfaa1b25632f223723fbb Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:07:41 -0400 Subject: [PATCH 106/285] use BottleNumber#action result --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8cf0c86..eabe508 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,12 +25,12 @@ def container(number) end def action(number) - BottleNumber.new(number).action(number) if number == 0 "Go to the store and buy some more" else "Take #{pronoun(number)} down and pass it around" end + BottleNumber.new(number).action(number) end def pronoun(number) From 8ee2229a40aaf05fc818aa26951b015949ceb09f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:07:49 -0400 Subject: [PATCH 107/285] delete obsolete code --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index eabe508..e871e71 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,11 +25,6 @@ def container(number) end def action(number) - if number == 0 - "Go to the store and buy some more" - else - "Take #{pronoun(number)} down and pass it around" - end BottleNumber.new(number).action(number) end From bf42aa3c57265f5f55da951d12e0ef5c5dd698d6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:08:10 -0400 Subject: [PATCH 108/285] parse/exec BottleNumber#pronoun --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index e871e71..deffd15 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -29,6 +29,7 @@ def action(number) end def pronoun(number) + BottleNumber.new(number).pronoun(number) if number == 1 "it" else From d764d71e66b5aef92bd2ab9653de246717169ce5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:08:23 -0400 Subject: [PATCH 109/285] use BottleNumber#pronoun result --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index deffd15..86c7f64 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -29,12 +29,12 @@ def action(number) end def pronoun(number) - BottleNumber.new(number).pronoun(number) if number == 1 "it" else "one" end + BottleNumber.new(number).pronoun(number) end def successor(number) From e20667ddee1057b9d557cc3f23c9d52fb0dde147 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:08:31 -0400 Subject: [PATCH 110/285] delete obsolete code --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 86c7f64..649953a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -29,11 +29,6 @@ def action(number) end def pronoun(number) - if number == 1 - "it" - else - "one" - end BottleNumber.new(number).pronoun(number) end From 70f4cba0eb42d40b373085261a7d0b67c971c5ac Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:08:46 -0400 Subject: [PATCH 111/285] parse/exec BottleNumber#successor --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 649953a..c9736fc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -33,6 +33,7 @@ def pronoun(number) end def successor(number) + BottleNumber.new(number).successor(number) if number == 0 99 else From 6c2d3c4a18d3b4bca5e587b7e7056610c9ca258d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:08:58 -0400 Subject: [PATCH 112/285] use BottleNumber#successor result --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index c9736fc..1141f22 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -33,12 +33,12 @@ def pronoun(number) end def successor(number) - BottleNumber.new(number).successor(number) if number == 0 99 else number - 1 end + BottleNumber.new(number).successor(number) end end From cb95f42acfc5cfa4099d06c6faa3de356ca29faf Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:09:07 -0400 Subject: [PATCH 113/285] delete obsolete code --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 1141f22..80bcc9c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -33,11 +33,6 @@ def pronoun(number) end def successor(number) - if number == 0 - 99 - else - number - 1 - end BottleNumber.new(number).successor(number) end end From d3be56cfd6ab4d99d33e14a0fa216aa087c7449b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:10:17 -0400 Subject: [PATCH 114/285] rename BottleNumber#quantity argument --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 80bcc9c..96f7356 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -43,7 +43,7 @@ def initialize(number) @number = number end - def quantity(number) + def quantity(delete_me=nil) if number == 0 "no more" else From 3b4c7c7c29d5eb9714f56ab44ce7291d8bbd09d4 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:10:55 -0400 Subject: [PATCH 115/285] remove param from sender --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 96f7356..a409914 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,7 +17,7 @@ def verse(number) end def quantity(number) - BottleNumber.new(number).quantity(number) + BottleNumber.new(number).quantity end def container(number) From 8f2e7c18c6106009c8c96c47cfcf6bdeca44e0cd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:11:18 -0400 Subject: [PATCH 116/285] remove arg from receiver --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a409914..2c05c50 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -43,7 +43,7 @@ def initialize(number) @number = number end - def quantity(delete_me=nil) + def quantity if number == 0 "no more" else From 185c027a587c5da3317b383767cca0a620bf75d4 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:11:54 -0400 Subject: [PATCH 117/285] rename BottleNumber#container argument --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 2c05c50..06fa85b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -51,7 +51,7 @@ def quantity end end - def container(number) + def container(delete_me=nil) if number == 1 "bottle" else From 72f88acb6031685036792e4a4676f043d8bc5000 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:12:02 -0400 Subject: [PATCH 118/285] remove param from sender --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 06fa85b..3eaf0bf 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,7 +21,7 @@ def quantity(number) end def container(number) - BottleNumber.new(number).container(number) + BottleNumber.new(number).container end def action(number) From 62b1d14c56365083a0b03aca1465d92c0a19e840 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:12:08 -0400 Subject: [PATCH 119/285] remove arg from receiver --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3eaf0bf..9a88677 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -51,7 +51,7 @@ def quantity end end - def container(delete_me=nil) + def container if number == 1 "bottle" else From 9517843b4941b83859b9330354fda59c4a3671e6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:12:32 -0400 Subject: [PATCH 120/285] rename BottleNumber#action argument --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9a88677..10e4650 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -59,7 +59,7 @@ def container end end - def action(number) + def action(delete_me=nil) if number == 0 "Go to the store and buy some more" else From 79caa4fe608f461b265fcde7bbc8b13127ec6c40 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:12:40 -0400 Subject: [PATCH 121/285] remove param from sender --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 10e4650..cc6d62b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,7 +25,7 @@ def container(number) end def action(number) - BottleNumber.new(number).action(number) + BottleNumber.new(number).action end def pronoun(number) From 538dcd3e228ade29d05e7ae26f63211f92911e6f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:12:47 -0400 Subject: [PATCH 122/285] remove arg from receiver --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index cc6d62b..2f33056 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -59,7 +59,7 @@ def container end end - def action(delete_me=nil) + def action if number == 0 "Go to the store and buy some more" else From 61f863ddc479d3928df0d007388f4b311d55e75b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:13:12 -0400 Subject: [PATCH 123/285] rename BottleNumber#pronoun argument --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 2f33056..c8aa893 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -67,7 +67,7 @@ def action end end - def pronoun(number) + def pronoun(delete_me=nil) if number == 1 "it" else From d9f0321794dbb2812c4342794dd37412ee77fd68 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:13:35 -0400 Subject: [PATCH 124/285] remove param from unused sender --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index c8aa893..0837d3a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -29,7 +29,7 @@ def action(number) end def pronoun(number) - BottleNumber.new(number).pronoun(number) + BottleNumber.new(number).pronoun end def successor(number) From fb2bc412c750c6d76c1296fdf800984e422b232c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:13:53 -0400 Subject: [PATCH 125/285] remove arg from receiver FAIL --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0837d3a..7508b34 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -67,7 +67,7 @@ def action end end - def pronoun(delete_me=nil) + def pronoun if number == 1 "it" else From eaad2d160b8e55fbc34fee2322b8817eb3776be5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:14:28 -0400 Subject: [PATCH 126/285] revert prior change --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 7508b34..0837d3a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -67,7 +67,7 @@ def action end end - def pronoun + def pronoun(delete_me=nil) if number == 1 "it" else From 630c8d9fba1f342f7969f7b9b01de46eb33dfd5a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:22:07 -0400 Subject: [PATCH 127/285] delete unused Bottles#pronoun --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0837d3a..e6aa309 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,10 +28,6 @@ def action(number) BottleNumber.new(number).action end - def pronoun(number) - BottleNumber.new(number).pronoun - end - def successor(number) BottleNumber.new(number).successor(number) end From 461ed1f284436f4c5735df8baa32d926ea8e5f70 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:22:23 -0400 Subject: [PATCH 128/285] remove param from sender --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e6aa309..d07448b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -59,7 +59,7 @@ def action if number == 0 "Go to the store and buy some more" else - "Take #{pronoun(number)} down and pass it around" + "Take #{pronoun} down and pass it around" end end From 7d01c25cfa6f2f7dd0626f879eee3d9d48072123 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:22:35 -0400 Subject: [PATCH 129/285] remove arg from receiver --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index d07448b..a4cfe83 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -63,7 +63,7 @@ def action end end - def pronoun(delete_me=nil) + def pronoun if number == 1 "it" else From 32879abf932adc791af638ef3ba8c0648385143e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:22:56 -0400 Subject: [PATCH 130/285] rename BottleNumber#successor argument --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a4cfe83..a8645fc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -71,7 +71,7 @@ def pronoun end end - def successor(number) + def successor(delete_me=nil) if number == 0 99 else From c2f19697bab4cafedde41e4e29066b2c2a3fcb2f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:23:07 -0400 Subject: [PATCH 131/285] remove param from sender --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a8645fc..68c4feb 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -29,7 +29,7 @@ def action(number) end def successor(number) - BottleNumber.new(number).successor(number) + BottleNumber.new(number).successor end end From a95fde78743a18de184aa5c7bfe1cb49aef50f8b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:23:16 -0400 Subject: [PATCH 132/285] remove arg from receiver --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 68c4feb..e77b79a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -71,7 +71,7 @@ def pronoun end end - def successor(delete_me=nil) + def successor if number == 0 99 else From 3437f4432c5181494fc2a807f7f81b93b53545fc Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:25:02 -0400 Subject: [PATCH 133/285] cache (memoize) a BottleNumber --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index e77b79a..406a620 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,6 +8,8 @@ def verses(upper, lower) end def verse(number) + bottle_number = BottleNumber.new(number) + "#{quantity(number).capitalize} #{container(number)} " + "of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + From 4725db6f678cfc67fc993d91fbf14b68182a044e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:25:46 -0400 Subject: [PATCH 134/285] send #action to bottle_number --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 406a620..d4fe5d9 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -13,7 +13,7 @@ def verse(number) "#{quantity(number).capitalize} #{container(number)} " + "of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + - "#{action(number)}, " + + "#{bottle_number.action}, " + "#{quantity(successor(number))} #{container(successor(number))} " + "of beer on the wall.\n" end From 516815e014dbc4d2842aa6a8db304c649756fa78 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:26:37 -0400 Subject: [PATCH 135/285] use bottle_number is phrase 1 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index d4fe5d9..622842d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,7 +10,7 @@ def verses(upper, lower) def verse(number) bottle_number = BottleNumber.new(number) - "#{quantity(number).capitalize} #{container(number)} " + + "#{bottle_number.quantity.capitalize} #{bottle_number.container} " + "of beer on the wall, " + "#{quantity(number)} #{container(number)} of beer.\n" + "#{bottle_number.action}, " + From 6fd68644d2f86c167160bd148329a9c628bf0e74 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:27:34 -0400 Subject: [PATCH 136/285] use bottle_number is phrase 2 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 622842d..f669081 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -12,7 +12,7 @@ def verse(number) "#{bottle_number.quantity.capitalize} #{bottle_number.container} " + "of beer on the wall, " + - "#{quantity(number)} #{container(number)} of beer.\n" + + "#{bottle_number.quantity} #{bottle_number.container} of beer.\n" + "#{bottle_number.action}, " + "#{quantity(successor(number))} #{container(successor(number))} " + "of beer on the wall.\n" From 0c87e3f6de19167fcf7dad74f8ff9923caee03dd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:28:42 -0400 Subject: [PATCH 137/285] cache (memoize) the next BottleNumber --- lib/bottles.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f669081..f7a391c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,7 +8,8 @@ def verses(upper, lower) end def verse(number) - bottle_number = BottleNumber.new(number) + bottle_number = BottleNumber.new(number) + next_bottle_number = BottleNumber.new(bottle_number.successor) "#{bottle_number.quantity.capitalize} #{bottle_number.container} " + "of beer on the wall, " + From ed83d220b8a02266a432a5f03558d171494fb3fc Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:29:23 -0400 Subject: [PATCH 138/285] use next_bottle_number is phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f7a391c..bb86cb2 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -15,7 +15,7 @@ def verse(number) "of beer on the wall, " + "#{bottle_number.quantity} #{bottle_number.container} of beer.\n" + "#{bottle_number.action}, " + - "#{quantity(successor(number))} #{container(successor(number))} " + + "#{next_bottle_number.quantity} #{next_bottle_number.container} " + "of beer on the wall.\n" end From 24cd63702e6053001a216c000c26809e1b40ca6a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Fri, 15 May 2020 11:30:21 -0400 Subject: [PATCH 139/285] delete obsolete code --- lib/bottles.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index bb86cb2..078ac57 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,22 +18,6 @@ def verse(number) "#{next_bottle_number.quantity} #{next_bottle_number.container} " + "of beer on the wall.\n" end - - def quantity(number) - BottleNumber.new(number).quantity - end - - def container(number) - BottleNumber.new(number).container - end - - def action(number) - BottleNumber.new(number).action - end - - def successor(number) - BottleNumber.new(number).successor - end end class BottleNumber From f52bff9162c7ba3453fb4fdabae20c1566343674 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:30:39 -0400 Subject: [PATCH 140/285] add BottleNumber#to_s --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 078ac57..9db596b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -26,6 +26,10 @@ def initialize(number) @number = number end + def to_s + "#{quantity} #{container}" + end + def quantity if number == 0 "no more" From 8f8a6fa020aca024f0921a20013aee39785faaf8 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:32:09 -0400 Subject: [PATCH 141/285] use to_s in phrase 1 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9db596b..a66fb96 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -11,7 +11,7 @@ def verse(number) bottle_number = BottleNumber.new(number) next_bottle_number = BottleNumber.new(bottle_number.successor) - "#{bottle_number.quantity.capitalize} #{bottle_number.container} " + + "#{bottle_number} ".capitalize + "of beer on the wall, " + "#{bottle_number.quantity} #{bottle_number.container} of beer.\n" + "#{bottle_number.action}, " + From 5d8ec823d2f549735f134329f0a5b656c03a7eab Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:33:02 -0400 Subject: [PATCH 142/285] use to_s in phrase 2 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a66fb96..4873ec2 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -13,7 +13,7 @@ def verse(number) "#{bottle_number} ".capitalize + "of beer on the wall, " + - "#{bottle_number.quantity} #{bottle_number.container} of beer.\n" + + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + "#{next_bottle_number.quantity} #{next_bottle_number.container} " + "of beer on the wall.\n" From e17527e651220215d5c8ff3e6d77811cac8aba60 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:33:11 -0400 Subject: [PATCH 143/285] use to_s in phrase 4 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4873ec2..16eda55 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -15,7 +15,7 @@ def verse(number) "of beer on the wall, " + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + - "#{next_bottle_number.quantity} #{next_bottle_number.container} " + + "#{next_bottle_number} " + "of beer on the wall.\n" end end From 7f4a20e36ee5b08fe04dd43e4258cf52359a82ea Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:34:01 -0400 Subject: [PATCH 144/285] unite phrase 1 on single line --- lib/bottles.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 16eda55..bf2a3b8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -11,8 +11,7 @@ def verse(number) bottle_number = BottleNumber.new(number) next_bottle_number = BottleNumber.new(bottle_number.successor) - "#{bottle_number} ".capitalize + - "of beer on the wall, " + + "#{bottle_number} ".capitalize + "of beer on the wall, " + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + "#{next_bottle_number} " + From 221ca49485a5c82a19f972d5565c4e7a9031d911 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:34:54 -0400 Subject: [PATCH 145/285] consolidate phrase 1 strings --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index bf2a3b8..a6a64a8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -11,7 +11,7 @@ def verse(number) bottle_number = BottleNumber.new(number) next_bottle_number = BottleNumber.new(bottle_number.successor) - "#{bottle_number} ".capitalize + "of beer on the wall, " + + "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + "#{next_bottle_number} " + From 5697969efa6328b2e5b2e724a3bd108ff399e86e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:35:17 -0400 Subject: [PATCH 146/285] unite phrase 4 on single line --- lib/bottles.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a6a64a8..f5204c4 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,8 +14,7 @@ def verse(number) "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + - "#{next_bottle_number} " + - "of beer on the wall.\n" + "#{next_bottle_number} " + "of beer on the wall.\n" end end From 0788ebb5c0a21986678f19cc60f2fb52113a05a6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:35:33 -0400 Subject: [PATCH 147/285] consolidate phrase 4 strings --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f5204c4..6fd1ba8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,7 +14,7 @@ def verse(number) "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + - "#{next_bottle_number} " + "of beer on the wall.\n" + "#{next_bottle_number} of beer on the wall.\n" end end From 5af6dc5fa86003d7c740fd8136471514785021fe Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:37:08 -0400 Subject: [PATCH 148/285] create BottleNumber0 class --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6fd1ba8..5a82673 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -67,4 +67,7 @@ def successor number - 1 end end +end + +class BottleNumber0 < BottleNumber end \ No newline at end of file From 1bbb637eb461146b2f46ddf0b0ad01ff68c913b8 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:37:58 -0400 Subject: [PATCH 149/285] copy #quantity to BottleNumber0 --- lib/bottles.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5a82673..a54c42c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -70,4 +70,11 @@ def successor end class BottleNumber0 < BottleNumber + def quantity + if number == 0 + "no more" + else + number.to_s + end + end end \ No newline at end of file From 2560fde6249ecbe3cfaaaca7ba637a99ff9406cf Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:38:50 -0400 Subject: [PATCH 150/285] reduce #quantity to specialization --- lib/bottles.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a54c42c..c77c8db 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -71,10 +71,6 @@ def successor class BottleNumber0 < BottleNumber def quantity - if number == 0 - "no more" - else - number.to_s - end + "no more" end end \ No newline at end of file From 5a4b5523130dcd4bcd8e354682c1b5d518a496b1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:39:36 -0400 Subject: [PATCH 151/285] add #bottle_number_for --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index c77c8db..1068198 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -16,6 +16,10 @@ def verse(number) "#{bottle_number.action}, " + "#{next_bottle_number} of beer on the wall.\n" end + + def bottle_number_for(number) + BottleNumber.new(number) + end end class BottleNumber From f74faa7b4e4e6982318933c9279c5d30456b3afd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:40:09 -0400 Subject: [PATCH 152/285] use #bottle_number_for once --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 1068198..9d11292 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,7 +8,7 @@ def verses(upper, lower) end def verse(number) - bottle_number = BottleNumber.new(number) + bottle_number = bottle_number_for(number) next_bottle_number = BottleNumber.new(bottle_number.successor) "#{bottle_number} of beer on the wall, ".capitalize + From 1bf280fb8820f504a94a32d8ce0caebcd6a41aeb Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:40:20 -0400 Subject: [PATCH 153/285] use #bottle_number_for twice --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9d11292..1764ffe 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -9,7 +9,7 @@ def verses(upper, lower) def verse(number) bottle_number = bottle_number_for(number) - next_bottle_number = BottleNumber.new(bottle_number.successor) + next_bottle_number = bottle_number_for(bottle_number.successor) "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + From 92b0eb0b4985ca0350f067596262178b70326cda Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:41:27 -0400 Subject: [PATCH 154/285] manufacture a bottle number --- lib/bottles.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 1764ffe..0f6cc1d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,7 +18,11 @@ def verse(number) end def bottle_number_for(number) - BottleNumber.new(number) + if number == 0 + BottleNumber0.new(number) + else + BottleNumber.new(number) + end end end From b5ce9522d71ec549e5f6c5fd1a3fa40483c5d694 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:42:16 -0400 Subject: [PATCH 155/285] parse an alternate factory impl --- lib/bottles.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0f6cc1d..3bd8c52 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,6 +18,12 @@ def verse(number) end def bottle_number_for(number) + if number == 0 + BottleNumber0 + else + BottleNumber + end.new(number) + if number == 0 BottleNumber0.new(number) else From ccf8a14d2b3efa2a9d4e0e352c56fc65a639a121 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:42:32 -0400 Subject: [PATCH 156/285] use the alternate implementation --- lib/bottles.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3bd8c52..0c242fe 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,12 +23,6 @@ def bottle_number_for(number) else BottleNumber end.new(number) - - if number == 0 - BottleNumber0.new(number) - else - BottleNumber.new(number) - end end end From cf4c4e0783ae1fcd9d65ceacf881f420baaf5f17 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:43:30 -0400 Subject: [PATCH 157/285] reduce super #quantity to generalization --- lib/bottles.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0c242fe..5f51bec 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -37,11 +37,7 @@ def to_s end def quantity - if number == 0 - "no more" - else - number.to_s - end + number.to_s end def container From e0dd252aa26ab540f5293970758ae9011f48263b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:44:21 -0400 Subject: [PATCH 158/285] copy #action to BottleNumber0 --- lib/bottles.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5f51bec..78afebd 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -77,4 +77,12 @@ class BottleNumber0 < BottleNumber def quantity "no more" end + + def action + if number == 0 + "Go to the store and buy some more" + else + "Take #{pronoun} down and pass it around" + end + end end \ No newline at end of file From 092f8ff9f158be2ce0b69692566961f45de1a180 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:44:43 -0400 Subject: [PATCH 159/285] return specialization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 78afebd..ca08560 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -80,9 +80,9 @@ def quantity def action if number == 0 - "Go to the store and buy some more" else "Take #{pronoun} down and pass it around" end + "Go to the store and buy some more" end end \ No newline at end of file From 8b5f746c5db417cf0841077fcc327d8651bc7c28 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:44:57 -0400 Subject: [PATCH 160/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ca08560..14351cc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -79,10 +79,6 @@ def quantity end def action - if number == 0 - else - "Take #{pronoun} down and pass it around" - end "Go to the store and buy some more" end end \ No newline at end of file From aa8f07ce61ec9dfb3c9415cf26126d5c06e3f446 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:45:15 -0400 Subject: [PATCH 161/285] return super's generalization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 14351cc..e8d4175 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -52,8 +52,8 @@ def action if number == 0 "Go to the store and buy some more" else - "Take #{pronoun} down and pass it around" end + "Take #{pronoun} down and pass it around" end def pronoun From b6fdef9a80d3337adbd7f553a78e8853ecd3e505 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:45:22 -0400 Subject: [PATCH 162/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e8d4175..32787f5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -49,10 +49,6 @@ def container end def action - if number == 0 - "Go to the store and buy some more" - else - end "Take #{pronoun} down and pass it around" end From b4d21fa3ea9b37e32c1f0ae98ca4c52ec19fcbd6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:45:43 -0400 Subject: [PATCH 163/285] copy #successor to BottleNumber0 --- lib/bottles.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 32787f5..8e917b3 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -77,4 +77,12 @@ def quantity def action "Go to the store and buy some more" end + + def successor + if number == 0 + 99 + else + number - 1 + end + end end \ No newline at end of file From e6da42d14b00826c130e79b37051e0657fd25562 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:45:54 -0400 Subject: [PATCH 164/285] return specialization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8e917b3..7377296 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -80,9 +80,9 @@ def action def successor if number == 0 - 99 else number - 1 end + 99 end end \ No newline at end of file From 1add2f0015b754c53259bd2a3551d2d785c62b52 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:46:02 -0400 Subject: [PATCH 165/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 7377296..7517487 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -79,10 +79,6 @@ def action end def successor - if number == 0 - else - number - 1 - end 99 end end \ No newline at end of file From 6b841173fabef38b3a11a8cdeebd876478764bcc Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:46:08 -0400 Subject: [PATCH 166/285] return super's generalization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 7517487..533f26d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -64,8 +64,8 @@ def successor if number == 0 99 else - number - 1 end + number - 1 end end From dc8f6f0ecc8418df9c8805cc2f5d7143edc2c669 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:46:15 -0400 Subject: [PATCH 167/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 533f26d..ad58955 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -61,10 +61,6 @@ def pronoun end def successor - if number == 0 - 99 - else - end number - 1 end end From 9d33dc354ab105ad0c1f9cebdf85bf5f78e3cede Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:46:44 -0400 Subject: [PATCH 168/285] create BottleNumber1 class --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index ad58955..9c220b1 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -77,4 +77,7 @@ def action def successor 99 end +end + +class BottleNumber1 < BottleNumber end \ No newline at end of file From 2016970464cc86711b69a348aa6114c77eda336b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:47:16 -0400 Subject: [PATCH 169/285] copy #container to BottleNumber1 --- lib/bottles.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9c220b1..edac5cb 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -80,4 +80,11 @@ def successor end class BottleNumber1 < BottleNumber + def container + if number == 1 + "bottle" + else + "bottles" + end + end end \ No newline at end of file From 4911a71386f84ca78453c7bf7703989277797eac Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:47:33 -0400 Subject: [PATCH 170/285] return specialization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index edac5cb..e489cbf 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -82,9 +82,9 @@ def successor class BottleNumber1 < BottleNumber def container if number == 1 - "bottle" else "bottles" end + "bottle" end end \ No newline at end of file From 4d3c2610a65f3e24e264399c8d911502b7e8a264 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:47:43 -0400 Subject: [PATCH 171/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e489cbf..4a78eb5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -81,10 +81,6 @@ def successor class BottleNumber1 < BottleNumber def container - if number == 1 - else - "bottles" - end "bottle" end end \ No newline at end of file From 186c5d3ca76b1255079426fa490a8f82c33c1484 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:48:29 -0400 Subject: [PATCH 172/285] return super's generalization FAIL --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4a78eb5..37039e8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -44,8 +44,8 @@ def container if number == 1 "bottle" else - "bottles" end + "bottles" end def action From fe798c1b6357798a1f77dbf488f8921b6ee550e1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:48:55 -0400 Subject: [PATCH 173/285] revert previous change --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 37039e8..4a78eb5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -44,8 +44,8 @@ def container if number == 1 "bottle" else + "bottles" end - "bottles" end def action From 59c082e9cb5e92449b175fd636f4d5096962cdb5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:49:45 -0400 Subject: [PATCH 174/285] parse updated factory --- lib/bottles.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4a78eb5..de47028 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,6 +18,15 @@ def verse(number) end def bottle_number_for(number) + case number + when 0 + BottleNumber0 + when 1 + BottleNumber1 + else + BottleNumber + end.new(number) + if number == 0 BottleNumber0 else From ff6ec766a69d705f4881017e998148df33cf568e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:49:56 -0400 Subject: [PATCH 175/285] use updated factory --- lib/bottles.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index de47028..3351422 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -26,12 +26,6 @@ def bottle_number_for(number) else BottleNumber end.new(number) - - if number == 0 - BottleNumber0 - else - BottleNumber - end.new(number) end end From 9f65bc2e78a1be59a96ba83def7e626056294b7a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:50:29 -0400 Subject: [PATCH 176/285] return super's #container generalization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3351422..b82f20a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -47,8 +47,8 @@ def container if number == 1 "bottle" else - "bottles" end + "bottles" end def action From 45ecfe51315549d4ba864b2220bb942137e7875f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:50:37 -0400 Subject: [PATCH 177/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b82f20a..8b24fa2 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -44,10 +44,6 @@ def quantity end def container - if number == 1 - "bottle" - else - end "bottles" end From 2513f12da40af366ef533c2718783c64b68764cb Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:51:09 -0400 Subject: [PATCH 178/285] copy #pronoun to BottleNumber1 --- lib/bottles.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8b24fa2..fb3e7bb 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -82,4 +82,12 @@ class BottleNumber1 < BottleNumber def container "bottle" end + + def pronoun + if number == 1 + "it" + else + "one" + end + end end \ No newline at end of file From c1fb91aa2580190c54a90214007e92475e8cbc50 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:51:20 -0400 Subject: [PATCH 179/285] return specialization --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index fb3e7bb..ae1d888 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -85,9 +85,9 @@ def container def pronoun if number == 1 - "it" else "one" end + "it" end end \ No newline at end of file From 3769e8e0cdcd36a01d03213e2534dd6199090aaa Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:51:48 -0400 Subject: [PATCH 180/285] return super's generalization --- lib/bottles.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ae1d888..24af179 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -55,8 +55,8 @@ def pronoun if number == 1 "it" else - "one" end + "one" end def successor @@ -84,10 +84,6 @@ def container end def pronoun - if number == 1 - else - "one" - end "it" end end \ No newline at end of file From 6ff93e146c11d807485bb0d409e5b92e16dbd34b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:51:56 -0400 Subject: [PATCH 181/285] delete obsolete code --- lib/bottles.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 24af179..c23a980 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -52,10 +52,6 @@ def action end def pronoun - if number == 1 - "it" - else - end "one" end From 796af1495ea53a96c0b9c039faebd2850cb9c2ec Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:52:39 -0400 Subject: [PATCH 182/285] wish for a smarter successor --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index c23a980..dc334fc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,6 +10,7 @@ def verses(upper, lower) def verse(number) bottle_number = bottle_number_for(number) next_bottle_number = bottle_number_for(bottle_number.successor) + # next_bottle_number = bottle_number.successor "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + From 6df27d92afc62cdf6f387db5aaabd1993a6a6f62 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:53:46 -0400 Subject: [PATCH 183/285] copy #bottle_number_for to BottleNumber.for --- lib/bottles.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index dc334fc..4f65ce6 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -31,6 +31,17 @@ def bottle_number_for(number) end class BottleNumber + def self.for(number) + case number + when 0 + BottleNumber0 + when 1 + BottleNumber1 + else + BottleNumber + end.new(number) + end + attr_reader :number def initialize(number) @number = number From d7a590279ae10ddfa33d33196111a39d4d3a3dee Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:54:10 -0400 Subject: [PATCH 184/285] use .for factory once --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4f65ce6..a64a627 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,7 +8,7 @@ def verses(upper, lower) end def verse(number) - bottle_number = bottle_number_for(number) + bottle_number = BottleNumber.for(number) next_bottle_number = bottle_number_for(bottle_number.successor) # next_bottle_number = bottle_number.successor From 65b33826b2d93e921d3aa2bd147528f1bc86ff38 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:54:21 -0400 Subject: [PATCH 185/285] use .for factory twice --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a64a627..748d6e9 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -9,7 +9,7 @@ def verses(upper, lower) def verse(number) bottle_number = BottleNumber.for(number) - next_bottle_number = bottle_number_for(bottle_number.successor) + next_bottle_number = BottleNumber.for(bottle_number.successor) # next_bottle_number = bottle_number.successor "#{bottle_number} of beer on the wall, ".capitalize + From 6e56684a20051c06c25e7f6381d5dbf0c8a2a7b6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:54:36 -0400 Subject: [PATCH 186/285] delete obsolete code --- lib/bottles.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 748d6e9..f292e10 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,17 +17,6 @@ def verse(number) "#{bottle_number.action}, " + "#{next_bottle_number} of beer on the wall.\n" end - - def bottle_number_for(number) - case number - when 0 - BottleNumber0 - when 1 - BottleNumber1 - else - BottleNumber - end.new(number) - end end class BottleNumber From eb3fdfe50dfe031011298320122070210b94f943 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:55:11 -0400 Subject: [PATCH 187/285] add type check guard clause to BottleNumber.for --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index f292e10..ecda9ef 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,6 +21,8 @@ def verse(number) class BottleNumber def self.for(number) + return number if number.kind_of?(BottleNumber) + case number when 0 BottleNumber0 From 887c43b3cbc6a372dc2de13a71954e695551fc3f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:56:24 -0400 Subject: [PATCH 188/285] return a bottle number from BottleNumber0#successor --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ecda9ef..2e34634 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -73,7 +73,7 @@ def action end def successor - 99 + BottleNumber.for(99) end end From 6047d033fc008b3ea265b7fdeae11d2278af5965 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:57:15 -0400 Subject: [PATCH 189/285] return a bottle number from BottleNumber#successor --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 2e34634..4a26791 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -59,7 +59,7 @@ def pronoun end def successor - number - 1 + BottleNumber.for(number - 1) end end From da026bf359fd0c354f631cb52df51ee4ea65a448 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:58:08 -0400 Subject: [PATCH 190/285] see if the successor wish now works --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4a26791..b61f3a4 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,7 +10,7 @@ def verses(upper, lower) def verse(number) bottle_number = BottleNumber.for(number) next_bottle_number = BottleNumber.for(bottle_number.successor) - # next_bottle_number = bottle_number.successor + next_bottle_number = bottle_number.successor "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + From 6f1be7eb4b77553cdb0b019e9e755e6fb014096e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:58:21 -0400 Subject: [PATCH 191/285] delete obsolete code --- lib/bottles.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b61f3a4..3799f19 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -9,7 +9,6 @@ def verses(upper, lower) def verse(number) bottle_number = BottleNumber.for(number) - next_bottle_number = BottleNumber.for(bottle_number.successor) next_bottle_number = bottle_number.successor "#{bottle_number} of beer on the wall, ".capitalize + From bc631cd8dca4f3191c1e83d07159ee679fd7dd78 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:58:43 -0400 Subject: [PATCH 192/285] inline next_bottle_number temp --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3799f19..e1d155d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,7 +14,7 @@ def verse(number) "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + - "#{next_bottle_number} of beer on the wall.\n" + "#{bottle_number.successor} of beer on the wall.\n" end end From c096ebf2904a38070cf87e9fd82176ab61c89c59 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:58:48 -0400 Subject: [PATCH 193/285] delete obsolete code --- lib/bottles.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e1d155d..4757dd8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,8 +8,7 @@ def verses(upper, lower) end def verse(number) - bottle_number = BottleNumber.for(number) - next_bottle_number = bottle_number.successor + bottle_number = BottleNumber.for(number) "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + @@ -84,4 +83,4 @@ def container def pronoun "it" end -end \ No newline at end of file +end From 1231ac9eba9634df4b8db87cb664af162bb0535c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 06:59:04 -0400 Subject: [PATCH 194/285] delete obsolete code --- lib/bottles.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4757dd8..828f6be 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,8 +19,6 @@ def verse(number) class BottleNumber def self.for(number) - return number if number.kind_of?(BottleNumber) - case number when 0 BottleNumber0 From 7c6e55ae5706ec909ece697f0cabcbff147bf15a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 07:07:27 -0400 Subject: [PATCH 195/285] add six-pack to song test --- test/bottles_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 2a4ff63..dac7395 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -361,9 +361,9 @@ def test_the_whole_song Take one down and pass it around, 7 bottles of beer on the wall. 7 bottles of beer on the wall, 7 bottles of beer. - Take one down and pass it around, 6 bottles of beer on the wall. + Take one down and pass it around, 1 six-pack of beer on the wall. - 6 bottles of beer on the wall, 6 bottles of beer. + 1 six-pack of beer on the wall, 1 six-pack of beer. Take one down and pass it around, 5 bottles of beer on the wall. 5 bottles of beer on the wall, 5 bottles of beer. From e14ef3595843ae14cd2ab1a0c126e090b5c57fa7 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 07:08:02 -0400 Subject: [PATCH 196/285] create BottleNumber6 class --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 828f6be..8f175e2 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -82,3 +82,6 @@ def pronoun "it" end end + +class BottleNumber6 < BottleNumber +end From 9fd416b6ede9c07846fc19fcd56245f8c0f99fe6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 07:08:55 -0400 Subject: [PATCH 197/285] add BottleNumber6#container --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8f175e2..0dd5ede 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -84,4 +84,7 @@ def pronoun end class BottleNumber6 < BottleNumber + def container + "six-pack" + end end From 5cb00be386fe58f0a46ce52e080eff62260435d0 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 07:09:23 -0400 Subject: [PATCH 198/285] add BottleNumber6 to factory --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0dd5ede..4fb05a1 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,6 +24,8 @@ def self.for(number) BottleNumber0 when 1 BottleNumber1 + when 6 + BottleNumber6 else BottleNumber end.new(number) From 2e7f20ca22886c1c8e58ed955b8a07f04511678b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 07:09:53 -0400 Subject: [PATCH 199/285] add BottleNumber6#quantity --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4fb05a1..31c7a41 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -86,6 +86,10 @@ def pronoun end class BottleNumber6 < BottleNumber + def quantity + "1" + end + def container "six-pack" end From aef5a8f4d5d1b1434028c44ab44798d9449dc81e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:20:08 -0400 Subject: [PATCH 200/285] parse metaprogrammed factory --- lib/bottles.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 31c7a41..094c025 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,6 +19,12 @@ def verse(number) class BottleNumber def self.for(number) + begin + const_get("BottleNumber#{number}") + rescue NameError + BottleNumber + end.new(number) + case number when 0 BottleNumber0 From 010e4a94b5947e999d2ea554b5ba9dc86ba0c65c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:20:30 -0400 Subject: [PATCH 201/285] use metaprogrammed factory --- lib/bottles.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 094c025..20c46a0 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,17 +24,6 @@ def self.for(number) rescue NameError BottleNumber end.new(number) - - case number - when 0 - BottleNumber0 - when 1 - BottleNumber1 - when 6 - BottleNumber6 - else - BottleNumber - end.new(number) end attr_reader :number From 30b6bcc44519e27602f0d3bf39f4d5d9f65d99e6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:22:19 -0400 Subject: [PATCH 202/285] parse Hash factory --- lib/bottles.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 20c46a0..61c44d4 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,6 +19,11 @@ def verse(number) class BottleNumber def self.for(number) + Hash.new(BottleNumber).merge( + 0 => BottleNumber0, + 1 => BottleNumber1, + 6 => BottleNumber6)[number].new(number) + begin const_get("BottleNumber#{number}") rescue NameError From 5191ef7b8f808a6c56341e23f72698388f20578f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:22:32 -0400 Subject: [PATCH 203/285] use Hash factory --- lib/bottles.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 61c44d4..f7f08ea 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,12 +23,6 @@ def self.for(number) 0 => BottleNumber0, 1 => BottleNumber1, 6 => BottleNumber6)[number].new(number) - - begin - const_get("BottleNumber#{number}") - rescue NameError - BottleNumber - end.new(number) end attr_reader :number From 110c9a1fe2fa77537838031e628ca87cdcc4cb55 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:24:32 -0400 Subject: [PATCH 204/285] add handles? method to BottleNumber6 --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index f7f08ea..e816fd5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -80,6 +80,10 @@ def pronoun end class BottleNumber6 < BottleNumber + def self.handles?(number) + number == 6 + end + def quantity "1" end From acd1b2694e54a6a109ec365e464f4d436da13b30 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:24:44 -0400 Subject: [PATCH 205/285] add handles? method to BottleNumber1 --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index e816fd5..5f5549b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -70,6 +70,10 @@ def successor end class BottleNumber1 < BottleNumber + def self.handles?(number) + number == 1 + end + def container "bottle" end From d5f88ac107219e4c3f78486a6cfdc60f286ff76d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:24:54 -0400 Subject: [PATCH 206/285] add handles? method to BottleNumber0 --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5f5549b..15d7bed 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -56,6 +56,10 @@ def successor end class BottleNumber0 < BottleNumber + def self.handles?(number) + number == 0 + end + def quantity "no more" end From 3e87528315f162f84ff329ca5510c77664bddacf Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:25:07 -0400 Subject: [PATCH 207/285] add handles? method to BottleNumber --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 15d7bed..0b2cb22 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -25,6 +25,10 @@ def self.for(number) 6 => BottleNumber6)[number].new(number) end + def self.handles?(number) + true + end + attr_reader :number def initialize(number) @number = number From 256209ad6de7d0b5be0a77f251cdeea9722bc340 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:26:39 -0400 Subject: [PATCH 208/285] parse dispersed choosing logic factory --- lib/bottles.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0b2cb22..ceffe2a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,6 +19,9 @@ def verse(number) class BottleNumber def self.for(number) + [BottleNumber6, BottleNumber1, BottleNumber0, BottleNumber]. + find {|candidate| candidate.handles?(number)}.new(number) + Hash.new(BottleNumber).merge( 0 => BottleNumber0, 1 => BottleNumber1, From b4547c1f990f2480e10b78837d8a15aa8c19eb3c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:26:55 -0400 Subject: [PATCH 209/285] use dispersed choosing logic factory --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ceffe2a..0970e99 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,11 +21,6 @@ class BottleNumber def self.for(number) [BottleNumber6, BottleNumber1, BottleNumber0, BottleNumber]. find {|candidate| candidate.handles?(number)}.new(number) - - Hash.new(BottleNumber).merge( - 0 => BottleNumber0, - 1 => BottleNumber1, - 6 => BottleNumber6)[number].new(number) end def self.handles?(number) From c6b43f5b7890fbb02feea8118dfc5422f54ac9e3 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:34:09 -0400 Subject: [PATCH 210/285] add BottleNumber.registry --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 0970e99..f017718 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,6 +23,10 @@ def self.for(number) find {|candidate| candidate.handles?(number)}.new(number) end + def self.registry + @registry ||= [] + end + def self.handles?(number) true end From 17eb5ec36a21c2d4093cb9f5d1e781672752d1a5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:34:32 -0400 Subject: [PATCH 211/285] add BottleNumber.register --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index f017718..35df902 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -27,6 +27,10 @@ def self.registry @registry ||= [] end + def self.register(candidate) + registry.prepend(candidate) + end + def self.handles?(number) true end From c28921507777a056d9bcbe4083d807b8ffc96365 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:35:09 -0400 Subject: [PATCH 212/285] register BottleNumber6 --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 35df902..575a7be 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -98,6 +98,8 @@ def pronoun end class BottleNumber6 < BottleNumber + BottleNumber.register(self) + def self.handles?(number) number == 6 end From b84bb4c16d41e192b833be69b932ac873353b3a0 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:35:16 -0400 Subject: [PATCH 213/285] register BottleNumber1 --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 575a7be..c1c7046 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -84,6 +84,8 @@ def successor end class BottleNumber1 < BottleNumber + BottleNumber.register(self) + def self.handles?(number) number == 1 end From 125c2ce4636d9629dfcc6a4a0bdff2dc3e20603f Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:35:50 -0400 Subject: [PATCH 214/285] register BottleNumber0 --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index c1c7046..d5f2027 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -66,6 +66,8 @@ def successor end class BottleNumber0 < BottleNumber + BottleNumber.register(self) + def self.handles?(number) number == 0 end From 041d86e361fc7fe31e1c5b31e474847ffaa45e6e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:36:01 -0400 Subject: [PATCH 215/285] register BottleNumber --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index d5f2027..7f3e393 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -31,6 +31,8 @@ def self.register(candidate) registry.prepend(candidate) end + BottleNumber.register(self) + def self.handles?(number) true end From 5844efab8b7eb67dde53f373c3c9ce415cd0c7c6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:36:56 -0400 Subject: [PATCH 216/285] parse self registering factory --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 7f3e393..c3cce9b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,6 +19,8 @@ def verse(number) class BottleNumber def self.for(number) + registry.find {|candidate| candidate.handles?(number)}.new(number) + [BottleNumber6, BottleNumber1, BottleNumber0, BottleNumber]. find {|candidate| candidate.handles?(number)}.new(number) end From d314080a3708a3aaed5dae6fa011609fe9b74150 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:37:09 -0400 Subject: [PATCH 217/285] use self registering factory --- lib/bottles.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index c3cce9b..a505208 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -20,9 +20,6 @@ def verse(number) class BottleNumber def self.for(number) registry.find {|candidate| candidate.handles?(number)}.new(number) - - [BottleNumber6, BottleNumber1, BottleNumber0, BottleNumber]. - find {|candidate| candidate.handles?(number)}.new(number) end def self.registry From dcd89fa830eeb3849ba5f92fb1f5166c2db5aac9 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:40:43 -0400 Subject: [PATCH 218/285] override inherited hook --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index a505208..febe56f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -30,6 +30,10 @@ def self.register(candidate) registry.prepend(candidate) end + def self.inherited(candidate) + register(candidate) + end + BottleNumber.register(self) def self.handles?(number) From 6a30763de28a9fdecebe2e02c8405684c8e3b8a1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:42:40 -0400 Subject: [PATCH 219/285] delete obsolete code --- lib/bottles.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index febe56f..701965c 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -71,8 +71,6 @@ def successor end class BottleNumber0 < BottleNumber - BottleNumber.register(self) - def self.handles?(number) number == 0 end @@ -91,8 +89,6 @@ def successor end class BottleNumber1 < BottleNumber - BottleNumber.register(self) - def self.handles?(number) number == 1 end @@ -107,8 +103,6 @@ def pronoun end class BottleNumber6 < BottleNumber - BottleNumber.register(self) - def self.handles?(number) number == 6 end From ef3b303fe866b3a1510502ec047b24852d291ef6 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:43:18 -0400 Subject: [PATCH 220/285] initialize registry with BottleNumber --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 701965c..67ba357 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -23,7 +23,7 @@ def self.for(number) end def self.registry - @registry ||= [] + @registry ||= [BottleNumber] end def self.register(candidate) From e2705c215489a2fa58a0f67238cb9d0e7c511e50 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 09:43:25 -0400 Subject: [PATCH 221/285] delete obsolete code --- lib/bottles.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 67ba357..859fc9b 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -34,8 +34,6 @@ def self.inherited(candidate) register(candidate) end - BottleNumber.register(self) - def self.handles?(number) true end From 80a299e0cb55c581ee01d0e46aa1de22674ada5a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:18:35 -0400 Subject: [PATCH 222/285] revert to simplest factory --- lib/bottles.rb | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 859fc9b..31c7a41 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,23 +19,16 @@ def verse(number) class BottleNumber def self.for(number) - registry.find {|candidate| candidate.handles?(number)}.new(number) - end - - def self.registry - @registry ||= [BottleNumber] - end - - def self.register(candidate) - registry.prepend(candidate) - end - - def self.inherited(candidate) - register(candidate) - end - - def self.handles?(number) - true + case number + when 0 + BottleNumber0 + when 1 + BottleNumber1 + when 6 + BottleNumber6 + else + BottleNumber + end.new(number) end attr_reader :number @@ -69,10 +62,6 @@ def successor end class BottleNumber0 < BottleNumber - def self.handles?(number) - number == 0 - end - def quantity "no more" end @@ -87,10 +76,6 @@ def successor end class BottleNumber1 < BottleNumber - def self.handles?(number) - number == 1 - end - def container "bottle" end @@ -101,10 +86,6 @@ def pronoun end class BottleNumber6 < BottleNumber - def self.handles?(number) - number == 6 - end - def quantity "1" end From e197539245d98579411a60cd716a53e51b0a1bc4 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:20:37 -0400 Subject: [PATCH 223/285] create BottleVerse class --- lib/bottles.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 31c7a41..9d66e31 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -17,6 +17,11 @@ def verse(number) end end + +class BottleVerse +end + + class BottleNumber def self.for(number) case number From 05271ab013e7b0508c71ea133e0bc738b73bd7bc Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:35:44 -0400 Subject: [PATCH 224/285] add attr_reader and initialize number --- lib/bottles.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9d66e31..6db0edf 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -19,6 +19,11 @@ def verse(number) class BottleVerse + attr_reader :number + + def initialize(number) + @number = number + end end From 5809b5fa9a4512ba88a9f839fa719e304eed70cd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:36:06 -0400 Subject: [PATCH 225/285] copy #verse from Bottles to BottleVerse --- lib/bottles.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6db0edf..5c5475d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,6 +24,15 @@ class BottleVerse def initialize(number) @number = number end + + def verse(number) + bottle_number = BottleNumber.for(number) + + "#{bottle_number} of beer on the wall, ".capitalize + + "#{bottle_number} of beer.\n" + + "#{bottle_number.action}, " + + "#{bottle_number.successor} of beer on the wall.\n" + end end From 0b4fc0bba04383e874f463824c13d6e550a4b428 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:36:55 -0400 Subject: [PATCH 226/285] parse/exec new #verse from old #verse --- lib/bottles.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 5c5475d..504af33 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,6 +8,8 @@ def verses(upper, lower) end def verse(number) + BottleVerse.new(number).verse(number) + bottle_number = BottleNumber.for(number) "#{bottle_number} of beer on the wall, ".capitalize + From a6fa17f68ec795ccdafdab7875b66b78cc4b75a2 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:37:14 -0400 Subject: [PATCH 227/285] use result of new #verse --- lib/bottles.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 504af33..f976f38 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,12 +10,12 @@ def verses(upper, lower) def verse(number) BottleVerse.new(number).verse(number) - bottle_number = BottleNumber.for(number) + # bottle_number = BottleNumber.for(number) - "#{bottle_number} of beer on the wall, ".capitalize + - "#{bottle_number} of beer.\n" + - "#{bottle_number.action}, " + - "#{bottle_number.successor} of beer on the wall.\n" + # "#{bottle_number} of beer on the wall, ".capitalize + + # "#{bottle_number} of beer.\n" + + # "#{bottle_number.action}, " + + # "#{bottle_number.successor} of beer on the wall.\n" end end From 5500fad38b7ca3c5f8af49e616497170a7b1ff14 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:37:42 -0400 Subject: [PATCH 228/285] revert to old #verse --- lib/bottles.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index f976f38..504af33 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -10,12 +10,12 @@ def verses(upper, lower) def verse(number) BottleVerse.new(number).verse(number) - # bottle_number = BottleNumber.for(number) + bottle_number = BottleNumber.for(number) - # "#{bottle_number} of beer on the wall, ".capitalize + - # "#{bottle_number} of beer.\n" + - # "#{bottle_number.action}, " + - # "#{bottle_number.successor} of beer on the wall.\n" + "#{bottle_number} of beer on the wall, ".capitalize + + "#{bottle_number} of beer.\n" + + "#{bottle_number.action}, " + + "#{bottle_number.successor} of beer on the wall.\n" end end From a0935657da48a3c048ba9bdb606a27984fa2fc9d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:38:00 -0400 Subject: [PATCH 229/285] wish to send #lyrics --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 504af33..e15f486 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,7 +8,7 @@ def verses(upper, lower) end def verse(number) - BottleVerse.new(number).verse(number) + # BottleVerse.new(number).lyrics bottle_number = BottleNumber.for(number) From 51cd64f35f1c35a0d41cfb2a1d7aa0e4b6c6bc79 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:38:29 -0400 Subject: [PATCH 230/285] change BottleVerse#verse(number) to BottleVerse#lyrics --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index e15f486..41bc0dd 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -27,7 +27,7 @@ def initialize(number) @number = number end - def verse(number) + def lyrics bottle_number = BottleNumber.for(number) "#{bottle_number} of beer on the wall, ".capitalize + From 8d6c5e21307b1e26dbc05eb88a15095a6b6809ed Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:38:49 -0400 Subject: [PATCH 231/285] parse/exec sending #lyrics --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 41bc0dd..a747da2 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,7 +8,7 @@ def verses(upper, lower) end def verse(number) - # BottleVerse.new(number).lyrics + BottleVerse.new(number).lyrics bottle_number = BottleNumber.for(number) From d0131e9f60a1e9de699c6684ef66b566bed9ec95 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:39:16 -0400 Subject: [PATCH 232/285] use result of sending #lyrics --- lib/bottles.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index a747da2..9083fa5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -9,13 +9,6 @@ def verses(upper, lower) def verse(number) BottleVerse.new(number).lyrics - - bottle_number = BottleNumber.for(number) - - "#{bottle_number} of beer on the wall, ".capitalize + - "#{bottle_number} of beer.\n" + - "#{bottle_number.action}, " + - "#{bottle_number.successor} of beer on the wall.\n" end end From 806010f26b00faa52950147b516a7a4d495bc1c9 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:39:58 -0400 Subject: [PATCH 233/285] wish to depend of verse template role --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9083fa5..3271427 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -8,6 +8,7 @@ def verses(upper, lower) end def verse(number) + # verse_template.new(number).lyrics BottleVerse.new(number).lyrics end end From 1c8cb799c6b5c1766ecb347a2b39be589762922a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:40:40 -0400 Subject: [PATCH 234/285] inject verse_template role --- lib/bottles.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3271427..349df1f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,4 +1,10 @@ class Bottles + attr_reader :verse_template + + def initialize(verse_template: BottleVerse) + @verse_template = verse_template + end + def song verses(99,0) end From 84b747001e72f05d4d6beec116040bf3e36f78ad Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:41:12 -0400 Subject: [PATCH 235/285] use result from verse template role --- lib/bottles.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 349df1f..cbec539 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,8 +14,7 @@ def verses(upper, lower) end def verse(number) - # verse_template.new(number).lyrics - BottleVerse.new(number).lyrics + verse_template.new(number).lyrics end end From 0645b1d022644c9bcd81d0423555d120aa4baefd Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:41:46 -0400 Subject: [PATCH 236/285] wish for lyrics without Demeter violation --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index cbec539..82076fa 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,6 +14,7 @@ def verses(upper, lower) end def verse(number) + # verse_template.lyrics(number) verse_template.new(number).lyrics end end From b1d8df7b9a23c51d37fc8f0002ce71035658a5d5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:42:42 -0400 Subject: [PATCH 237/285] add BottleVerse.lyrics to make wish possible --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 82076fa..336eabe 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,6 +21,10 @@ def verse(number) class BottleVerse + def self.lyrics(number) + new(number).lyrics + end + attr_reader :number def initialize(number) From 6a7c11b9aa2544c70970765bcb2fbc8209118e35 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:43:36 -0400 Subject: [PATCH 238/285] retrieve lyrics without Demeter violation --- lib/bottles.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 336eabe..6a053b2 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -14,8 +14,7 @@ def verses(upper, lower) end def verse(number) - # verse_template.lyrics(number) - verse_template.new(number).lyrics + verse_template.lyrics(number) end end From 13ac11a21ff603bdc25a3b82753745dd8f61f259 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:44:49 -0400 Subject: [PATCH 239/285] wish to consolidate object creation --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6a053b2..3b12b07 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,6 +21,7 @@ def verse(number) class BottleVerse def self.lyrics(number) + # new(BottleNumber.for(number)).lyrics new(number).lyrics end From 37b5bd77befe3a1c607e59bcac3480d3b9839b2e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:46:19 -0400 Subject: [PATCH 240/285] lyrics works with numbers or bottle numbers --- lib/bottles.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3b12b07..4949abc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -32,7 +32,8 @@ def initialize(number) end def lyrics - bottle_number = BottleNumber.for(number) + bottle_number = + (number.is_a?(BottleNumber) ? number : BottleNumber.for(number)) "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + From e50aef8b30b08be44dcc8fc6222613426ee46a7a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:46:44 -0400 Subject: [PATCH 241/285] parse/exec wish --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4949abc..9ea45a5 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -21,7 +21,7 @@ def verse(number) class BottleVerse def self.lyrics(number) - # new(BottleNumber.for(number)).lyrics + new(BottleNumber.for(number)).lyrics new(number).lyrics end From 18be38bf759002759c32c6b63ce9ff23ec199021 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:47:08 -0400 Subject: [PATCH 242/285] use result of consolidated object creation wish --- lib/bottles.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 9ea45a5..2d33e59 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -22,7 +22,6 @@ def verse(number) class BottleVerse def self.lyrics(number) new(BottleNumber.for(number)).lyrics - new(number).lyrics end attr_reader :number From 16cf1cc826a8b039d3e1319cc0888d23c67c5719 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:48:42 -0400 Subject: [PATCH 243/285] remove number to bottle number conversion from #lyrics --- lib/bottles.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 2d33e59..b18120d 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -31,8 +31,7 @@ def initialize(number) end def lyrics - bottle_number = - (number.is_a?(BottleNumber) ? number : BottleNumber.for(number)) + bottle_number = number "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + From 4ecee97d8228a8adee10d9b230e3a3248e7afa28 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:49:23 -0400 Subject: [PATCH 244/285] add bottle_number attr_reader --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index b18120d..8cdbf71 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,7 +24,7 @@ def self.lyrics(number) new(BottleNumber.for(number)).lyrics end - attr_reader :number + attr_reader :number, :bottle_number def initialize(number) @number = number From 7f9ffca23d9e80b24de8f794ff0beb751719e68c Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:49:44 -0400 Subject: [PATCH 245/285] initialize bottle_number --- lib/bottles.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8cdbf71..552b07a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -28,6 +28,7 @@ def self.lyrics(number) def initialize(number) @number = number + @bottle_number = number end def lyrics From 311964a281dc9a47368fe9311cd2199ec6499bf1 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:50:01 -0400 Subject: [PATCH 246/285] delete obsolete code --- lib/bottles.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 552b07a..ab403a8 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -32,8 +32,6 @@ def initialize(number) end def lyrics - bottle_number = number - "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + "#{bottle_number.action}, " + From df2001d56918109e4e26c481721de5c88ab07890 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:52:45 -0400 Subject: [PATCH 247/285] add alternate initializer --- lib/bottles.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index ab403a8..8c0a68f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -26,6 +26,10 @@ def self.lyrics(number) attr_reader :number, :bottle_number + def initialize(bottle_number) + @bottle_number = bottle_number + end + def initialize(number) @number = number @bottle_number = number From dcfee21cd104e4daff312d3b10aa353d2718b3dc Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:52:59 -0400 Subject: [PATCH 248/285] use alternate initializer --- lib/bottles.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 8c0a68f..ca9251e 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -30,11 +30,6 @@ def initialize(bottle_number) @bottle_number = bottle_number end - def initialize(number) - @number = number - @bottle_number = number - end - def lyrics "#{bottle_number} of beer on the wall, ".capitalize + "#{bottle_number} of beer.\n" + From 2e6bdd2924c887d3019b8a189aa01afc9de2d494 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Sat, 16 May 2020 10:53:19 -0400 Subject: [PATCH 249/285] delete obsolete code --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index ca9251e..a9d8863 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -24,7 +24,7 @@ def self.lyrics(number) new(BottleNumber.for(number)).lyrics end - attr_reader :number, :bottle_number + attr_reader :bottle_number def initialize(bottle_number) @bottle_number = bottle_number From 01e9e912c7e9a8285eb53992a449d0cc91e4976b Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 07:58:48 -0400 Subject: [PATCH 250/285] add BottleVerseTest --- test/bottles_test.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index dac7395..e3654d0 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -3,6 +3,9 @@ require 'minitest/pride' require_relative '../lib/bottles' +class BottleVerseTest < Minitest::Test +end + class BottlesTest < Minitest::Test def test_the_first_verse expected = From a4c95cbda62b0e0029eb18598c513a39b761ddda Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 07:59:33 -0400 Subject: [PATCH 251/285] copy 1st test from BottlesTest to BottleVerseTest --- test/bottles_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index e3654d0..ecf1ca3 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -4,6 +4,14 @@ require_relative '../lib/bottles' class BottleVerseTest < Minitest::Test + def test_the_first_verse + expected = + "99 bottles of beer on the wall, " + + "99 bottles of beer.\n" + + "Take one down and pass it around, " + + "98 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(99) + end end class BottlesTest < Minitest::Test From 3d951ccd73b76ee66aaffb6ee3fd13260489a6ac Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:00:10 -0400 Subject: [PATCH 252/285] use BottleVerse in 1st test --- test/bottles_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index ecf1ca3..e73b70c 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -10,7 +10,7 @@ def test_the_first_verse "99 bottles of beer.\n" + "Take one down and pass it around, " + "98 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(99) + assert_equal expected, BottleVerse.lyrics(99) end end From c26aa74e02e9c8176165b9bb616498306973d0a3 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:00:29 -0400 Subject: [PATCH 253/285] delete obsolete test --- test/bottles_test.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index e73b70c..42c827c 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -15,15 +15,6 @@ def test_the_first_verse end class BottlesTest < Minitest::Test - def test_the_first_verse - expected = - "99 bottles of beer on the wall, " + - "99 bottles of beer.\n" + - "Take one down and pass it around, " + - "98 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(99) - end - def test_another_verse expected = "3 bottles of beer on the wall, " + From f6500a329ff765458120cd148aafd95c0b54ec41 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:01:17 -0400 Subject: [PATCH 254/285] copy all other verse tests into BottleVerseTest --- test/bottles_test.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 42c827c..d9b0b98 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -12,6 +12,42 @@ def test_the_first_verse "98 bottles of beer on the wall.\n" assert_equal expected, BottleVerse.lyrics(99) end + + def test_another_verse + expected = + "3 bottles of beer on the wall, " + + "3 bottles of beer.\n" + + "Take one down and pass it around, " + + "2 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(3) + end + + def test_verse_2 + expected = + "2 bottles of beer on the wall, " + + "2 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 bottle of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(2) + end + + def test_verse_1 + expected = + "1 bottle of beer on the wall, " + + "1 bottle of beer.\n" + + "Take it down and pass it around, " + + "no more bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(1) + end + + def test_verse_0 + expected = + "No more bottles of beer on the wall, " + + "no more bottles of beer.\n" + + "Go to the store and buy some more, " + + "99 bottles of beer on the wall.\n" + assert_equal expected, Bottles.new.verse(0) + end end class BottlesTest < Minitest::Test From 0daf8e592fafcf0cc98c48224e31544cb6bc8c19 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:03:24 -0400 Subject: [PATCH 255/285] make 1 undo regexp change from Bottles to BottleVerse --- test/bottles_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index d9b0b98..6c8f42e 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -19,7 +19,7 @@ def test_another_verse "3 bottles of beer.\n" + "Take one down and pass it around, " + "2 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(3) + assert_equal expected, BottleVerse.lyrics(3) end def test_verse_2 @@ -28,7 +28,7 @@ def test_verse_2 "2 bottles of beer.\n" + "Take one down and pass it around, " + "1 bottle of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(2) + assert_equal expected, BottleVerse.lyrics(2) end def test_verse_1 @@ -37,7 +37,7 @@ def test_verse_1 "1 bottle of beer.\n" + "Take it down and pass it around, " + "no more bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(1) + assert_equal expected, BottleVerse.lyrics(1) end def test_verse_0 @@ -46,7 +46,7 @@ def test_verse_0 "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(0) + assert_equal expected, BottleVerse.lyrics(0) end end From f486a9d7c72fc50853a428bcb574e9c5a09e2077 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:03:51 -0400 Subject: [PATCH 256/285] delete obsolete test --- test/bottles_test.rb | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 6c8f42e..f9b42e3 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -51,42 +51,6 @@ def test_verse_0 end class BottlesTest < Minitest::Test - def test_another_verse - expected = - "3 bottles of beer on the wall, " + - "3 bottles of beer.\n" + - "Take one down and pass it around, " + - "2 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(3) - end - - def test_verse_2 - expected = - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(2) - end - - def test_verse_1 - expected = - "1 bottle of beer on the wall, " + - "1 bottle of beer.\n" + - "Take it down and pass it around, " + - "no more bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(1) - end - - def test_verse_0 - expected = - "No more bottles of beer on the wall, " + - "no more bottles of beer.\n" + - "Go to the store and buy some more, " + - "99 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verse(0) - end - def test_a_couple_verses expected = "99 bottles of beer on the wall, " + From 11a76e5d0024fe5f5f8cbc64ce8496e408e43143 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:04:26 -0400 Subject: [PATCH 257/285] rename lower bound test --- test/bottles_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index f9b42e3..f5ebdd9 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -13,7 +13,7 @@ def test_the_first_verse assert_equal expected, BottleVerse.lyrics(99) end - def test_another_verse + def test_verse_general_rule_lower_bound expected = "3 bottles of beer on the wall, " + "3 bottles of beer.\n" + From 1b0fb4bad2c48b4d8b8f4afcf7dcbe712072b239 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:04:43 -0400 Subject: [PATCH 258/285] rename upper bound test --- test/bottles_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index f5ebdd9..d431661 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -4,7 +4,7 @@ require_relative '../lib/bottles' class BottleVerseTest < Minitest::Test - def test_the_first_verse + def test_verse_general_rule_upper_bound expected = "99 bottles of beer on the wall, " + "99 bottles of beer.\n" + From 8cee69051e4034f05bc73a634c8f25ff31857733 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:06:41 -0400 Subject: [PATCH 259/285] add verse 7 test --- test/bottles_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index d431661..2ce6f56 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -22,6 +22,15 @@ def test_verse_general_rule_lower_bound assert_equal expected, BottleVerse.lyrics(3) end + def test_verse_7 + expected = + "7 bottles of beer on the wall, " + + "7 bottles of beer.\n" + + "Take one down and pass it around, " + + "1 six-pack of beer on the wall.\n" + assert_equal expected, BottleVerse.lyrics(7) + end + def test_verse_2 expected = "2 bottles of beer on the wall, " + From 5a607bdd3bf145dab60d095575aabe7fb27746d5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:09:01 -0400 Subject: [PATCH 260/285] add verse 6 test --- test/bottles_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 2ce6f56..1dc1056 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -31,6 +31,15 @@ def test_verse_7 assert_equal expected, BottleVerse.lyrics(7) end + def test_verse_6 + expected = + "1 six-pack of beer on the wall, " + + "1 six-pack of beer.\n" + + "Take one down and pass it around, " + + "5 bottles of beer on the wall.\n" + assert_equal expected, BottleVerse.lyrics(6) + end + def test_verse_2 expected = "2 bottles of beer on the wall, " + From 2a1343f72cd733281109bc210ab7c92067ce3755 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:09:52 -0400 Subject: [PATCH 261/285] duplicate Bottles as CountdownSong --- lib/bottles.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/bottles.rb b/lib/bottles.rb index a9d8863..279037f 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,3 +1,23 @@ +class CountdownSong + attr_reader :verse_template + + def initialize(verse_template: BottleVerse) + @verse_template = verse_template + end + + def song + verses(99,0) + end + + def verses(upper, lower) + upper.downto(lower).collect {|i| verse(i)}.join("\n") + end + + def verse(number) + verse_template.lyrics(number) + end +end + class Bottles attr_reader :verse_template From 97c47d439cb05f6521143cc7f08ac64819f1b480 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:10:22 -0400 Subject: [PATCH 262/285] change BottlesTest to CountdownSongTest --- test/bottles_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 1dc1056..61c7079 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -68,7 +68,7 @@ def test_verse_0 end end -class BottlesTest < Minitest::Test +class CountdownSongTest < Minitest::Test def test_a_couple_verses expected = "99 bottles of beer on the wall, " + From 7be7c1af51877f1615c71fcbb8b9c6851fc2ac4a Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:12:13 -0400 Subject: [PATCH 263/285] change Bottles to CountdownSong (1 undo change) --- test/bottles_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 61c7079..cc4b80c 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -80,7 +80,7 @@ def test_a_couple_verses "98 bottles of beer.\n" + "Take one down and pass it around, " + "97 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verses(99, 98) + assert_equal expected, CountdownSong.new.verses(99, 98) end def test_a_few_verses @@ -99,7 +99,7 @@ def test_a_few_verses "no more bottles of beer.\n" + "Go to the store and buy some more, " + "99 bottles of beer on the wall.\n" - assert_equal expected, Bottles.new.verses(2, 0) + assert_equal expected, CountdownSong.new.verses(2, 0) end def test_the_whole_song @@ -404,6 +404,6 @@ def test_the_whole_song No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall. SONG - assert_equal expected, Bottles.new.song + assert_equal expected, CountdownSong.new.song end end From 6dcd624662cf687bed55237cfd8bccaf4bf2f123 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:12:39 -0400 Subject: [PATCH 264/285] delete obsolete Bottles class --- lib/bottles.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 279037f..90d9a2a 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -18,26 +18,6 @@ def verse(number) end end -class Bottles - attr_reader :verse_template - - def initialize(verse_template: BottleVerse) - @verse_template = verse_template - end - - def song - verses(99,0) - end - - def verses(upper, lower) - upper.downto(lower).collect {|i| verse(i)}.join("\n") - end - - def verse(number) - verse_template.lyrics(number) - end -end - class BottleVerse def self.lyrics(number) From fed47c53faf83ee4b051a856763820b2bc70c333 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:27:27 -0400 Subject: [PATCH 265/285] add VerseFake --- test/bottles_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index cc4b80c..1d1ff1d 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -68,6 +68,12 @@ def test_verse_0 end end +class VerseFake + def self.lyrics(number) + "This is verse #{number}.\n" + end +end + class CountdownSongTest < Minitest::Test def test_a_couple_verses expected = From 9a0a0bac9844486df7fde822347da801bdbf85be Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:27:40 -0400 Subject: [PATCH 266/285] create alternate test_a_couple_verses method --- test/bottles_test.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 1d1ff1d..ba4763c 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -75,6 +75,9 @@ def self.lyrics(number) end class CountdownSongTest < Minitest::Test + def test_a_couple_verses + end + def test_a_couple_verses expected = "99 bottles of beer on the wall, " + From c23fd06a436bdc2648261a1897f2d5f50e8b5abe Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:28:59 -0400 Subject: [PATCH 267/285] use VerseFake in alternate couple_verses test --- test/bottles_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index ba4763c..27cb9f6 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -76,6 +76,16 @@ def self.lyrics(number) class CountdownSongTest < Minitest::Test def test_a_couple_verses + expected = + "This is verse 99.\n" + + "\n" + + "This is verse 98.\n" + + "\n" + + "This is verse 97.\n" + assert_equal( + expected, + CountdownSong.new(verse_template: VerseFake) + .verses(99, 97)) end def test_a_couple_verses From 2fadf4d23ab3a5ddbdde36e5dd498952d85e5bfc Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:29:17 -0400 Subject: [PATCH 268/285] delete obsolete test --- test/bottles_test.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 27cb9f6..a2c6fb8 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -88,20 +88,6 @@ def test_a_couple_verses .verses(99, 97)) end - def test_a_couple_verses - expected = - "99 bottles of beer on the wall, " + - "99 bottles of beer.\n" + - "Take one down and pass it around, " + - "98 bottles of beer on the wall.\n" + - "\n" + - "98 bottles of beer on the wall, " + - "98 bottles of beer.\n" + - "Take one down and pass it around, " + - "97 bottles of beer on the wall.\n" - assert_equal expected, CountdownSong.new.verses(99, 98) - end - def test_a_few_verses expected = "2 bottles of beer on the wall, " + From e34d2ac61213ad4b301148b877a5ba92c066c217 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:30:47 -0400 Subject: [PATCH 269/285] delete redundant test_a_few_verses --- test/bottles_test.rb | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index a2c6fb8..725d721 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -88,25 +88,6 @@ def test_a_couple_verses .verses(99, 97)) end - def test_a_few_verses - expected = - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" + - "\n" + - "1 bottle of beer on the wall, " + - "1 bottle of beer.\n" + - "Take it down and pass it around, " + - "no more bottles of beer on the wall.\n" + - "\n" + - "No more bottles of beer on the wall, " + - "no more bottles of beer.\n" + - "Go to the store and buy some more, " + - "99 bottles of beer on the wall.\n" - assert_equal expected, CountdownSong.new.verses(2, 0) - end - def test_the_whole_song expected = <<~SONG 99 bottles of beer on the wall, 99 bottles of beer. From 3c27f0a44f5d0f1bd7b2ca4ce92f9fc94b0fa930 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:46:00 -0400 Subject: [PATCH 270/285] add verse test --- test/bottles_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 725d721..f8aa1ea 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -75,6 +75,14 @@ def self.lyrics(number) end class CountdownSongTest < Minitest::Test + def test_verse + expected = "This is verse 500.\n" + assert_equal( + expected, + CountdownSong.new(verse_template: VerseFake) + .verse(500)) + end + def test_a_couple_verses expected = "This is verse 99.\n" + From bd0ebf3eba87efa8c3a27b9a8dfed32796c29249 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:46:23 -0400 Subject: [PATCH 271/285] rename verses test --- test/bottles_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index f8aa1ea..e576543 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -83,7 +83,7 @@ def test_verse .verse(500)) end - def test_a_couple_verses + def test_verses expected = "This is verse 99.\n" + "\n" + From d034b915fdccd4a30ea7de238f6664d92be314aa Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:46:44 -0400 Subject: [PATCH 272/285] create max and min attr_readers --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 90d9a2a..3db0adc 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,5 +1,5 @@ class CountdownSong - attr_reader :verse_template + attr_reader :verse_template, :max, :min def initialize(verse_template: BottleVerse) @verse_template = verse_template From 650cbdd10df01ccea1645fd5245cc1bc128c7416 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:47:48 -0400 Subject: [PATCH 273/285] initialize max and min --- lib/bottles.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 3db0adc..6c36805 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,8 +1,9 @@ class CountdownSong attr_reader :verse_template, :max, :min - def initialize(verse_template: BottleVerse) + def initialize(verse_template: BottleVerse, max: 99, min: 0) @verse_template = verse_template + @max, @min = max, min end def song From db9d1037a6b490e55d35dd659620112635898ae9 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:48:03 -0400 Subject: [PATCH 274/285] use max and min in #song --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 6c36805..edfe185 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -7,7 +7,7 @@ def initialize(verse_template: BottleVerse, max: 99, min: 0) end def song - verses(99,0) + verses(max, min) end def verses(upper, lower) From 413d9dcc87fd13d6c358694ad52fb02927e06c90 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:49:20 -0400 Subject: [PATCH 275/285] add alternate #test_the_whole_song --- test/bottles_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index e576543..1891a36 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -96,6 +96,25 @@ def test_verses .verses(99, 97)) end + def test_the_whole_song + expected = + "This is verse 47.\n" + + "\n" + + "This is verse 46.\n" + + "\n" + + "This is verse 45.\n" + + "\n" + + "This is verse 44.\n" + + "\n" + + "This is verse 43.\n" + assert_equal( + expected, + CountdownSong.new(verse_template: VerseFake, + max: 47, + min: 43) + .song) + end + def test_the_whole_song expected = <<~SONG 99 bottles of beer on the wall, 99 bottles of beer. From 1ce274bf47c9b50dde33cd9c018e1c167fae6037 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Mon, 18 May 2020 08:49:48 -0400 Subject: [PATCH 276/285] delete obsolete test --- test/bottles_test.rb | 305 ------------------------------------------- 1 file changed, 305 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 1891a36..d557963 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -114,309 +114,4 @@ def test_the_whole_song min: 43) .song) end - - def test_the_whole_song - expected = <<~SONG - 99 bottles of beer on the wall, 99 bottles of beer. - Take one down and pass it around, 98 bottles of beer on the wall. - - 98 bottles of beer on the wall, 98 bottles of beer. - Take one down and pass it around, 97 bottles of beer on the wall. - - 97 bottles of beer on the wall, 97 bottles of beer. - Take one down and pass it around, 96 bottles of beer on the wall. - - 96 bottles of beer on the wall, 96 bottles of beer. - Take one down and pass it around, 95 bottles of beer on the wall. - - 95 bottles of beer on the wall, 95 bottles of beer. - Take one down and pass it around, 94 bottles of beer on the wall. - - 94 bottles of beer on the wall, 94 bottles of beer. - Take one down and pass it around, 93 bottles of beer on the wall. - - 93 bottles of beer on the wall, 93 bottles of beer. - Take one down and pass it around, 92 bottles of beer on the wall. - - 92 bottles of beer on the wall, 92 bottles of beer. - Take one down and pass it around, 91 bottles of beer on the wall. - - 91 bottles of beer on the wall, 91 bottles of beer. - Take one down and pass it around, 90 bottles of beer on the wall. - - 90 bottles of beer on the wall, 90 bottles of beer. - Take one down and pass it around, 89 bottles of beer on the wall. - - 89 bottles of beer on the wall, 89 bottles of beer. - Take one down and pass it around, 88 bottles of beer on the wall. - - 88 bottles of beer on the wall, 88 bottles of beer. - Take one down and pass it around, 87 bottles of beer on the wall. - - 87 bottles of beer on the wall, 87 bottles of beer. - Take one down and pass it around, 86 bottles of beer on the wall. - - 86 bottles of beer on the wall, 86 bottles of beer. - Take one down and pass it around, 85 bottles of beer on the wall. - - 85 bottles of beer on the wall, 85 bottles of beer. - Take one down and pass it around, 84 bottles of beer on the wall. - - 84 bottles of beer on the wall, 84 bottles of beer. - Take one down and pass it around, 83 bottles of beer on the wall. - - 83 bottles of beer on the wall, 83 bottles of beer. - Take one down and pass it around, 82 bottles of beer on the wall. - - 82 bottles of beer on the wall, 82 bottles of beer. - Take one down and pass it around, 81 bottles of beer on the wall. - - 81 bottles of beer on the wall, 81 bottles of beer. - Take one down and pass it around, 80 bottles of beer on the wall. - - 80 bottles of beer on the wall, 80 bottles of beer. - Take one down and pass it around, 79 bottles of beer on the wall. - - 79 bottles of beer on the wall, 79 bottles of beer. - Take one down and pass it around, 78 bottles of beer on the wall. - - 78 bottles of beer on the wall, 78 bottles of beer. - Take one down and pass it around, 77 bottles of beer on the wall. - - 77 bottles of beer on the wall, 77 bottles of beer. - Take one down and pass it around, 76 bottles of beer on the wall. - - 76 bottles of beer on the wall, 76 bottles of beer. - Take one down and pass it around, 75 bottles of beer on the wall. - - 75 bottles of beer on the wall, 75 bottles of beer. - Take one down and pass it around, 74 bottles of beer on the wall. - - 74 bottles of beer on the wall, 74 bottles of beer. - Take one down and pass it around, 73 bottles of beer on the wall. - - 73 bottles of beer on the wall, 73 bottles of beer. - Take one down and pass it around, 72 bottles of beer on the wall. - - 72 bottles of beer on the wall, 72 bottles of beer. - Take one down and pass it around, 71 bottles of beer on the wall. - - 71 bottles of beer on the wall, 71 bottles of beer. - Take one down and pass it around, 70 bottles of beer on the wall. - - 70 bottles of beer on the wall, 70 bottles of beer. - Take one down and pass it around, 69 bottles of beer on the wall. - - 69 bottles of beer on the wall, 69 bottles of beer. - Take one down and pass it around, 68 bottles of beer on the wall. - - 68 bottles of beer on the wall, 68 bottles of beer. - Take one down and pass it around, 67 bottles of beer on the wall. - - 67 bottles of beer on the wall, 67 bottles of beer. - Take one down and pass it around, 66 bottles of beer on the wall. - - 66 bottles of beer on the wall, 66 bottles of beer. - Take one down and pass it around, 65 bottles of beer on the wall. - - 65 bottles of beer on the wall, 65 bottles of beer. - Take one down and pass it around, 64 bottles of beer on the wall. - - 64 bottles of beer on the wall, 64 bottles of beer. - Take one down and pass it around, 63 bottles of beer on the wall. - - 63 bottles of beer on the wall, 63 bottles of beer. - Take one down and pass it around, 62 bottles of beer on the wall. - - 62 bottles of beer on the wall, 62 bottles of beer. - Take one down and pass it around, 61 bottles of beer on the wall. - - 61 bottles of beer on the wall, 61 bottles of beer. - Take one down and pass it around, 60 bottles of beer on the wall. - - 60 bottles of beer on the wall, 60 bottles of beer. - Take one down and pass it around, 59 bottles of beer on the wall. - - 59 bottles of beer on the wall, 59 bottles of beer. - Take one down and pass it around, 58 bottles of beer on the wall. - - 58 bottles of beer on the wall, 58 bottles of beer. - Take one down and pass it around, 57 bottles of beer on the wall. - - 57 bottles of beer on the wall, 57 bottles of beer. - Take one down and pass it around, 56 bottles of beer on the wall. - - 56 bottles of beer on the wall, 56 bottles of beer. - Take one down and pass it around, 55 bottles of beer on the wall. - - 55 bottles of beer on the wall, 55 bottles of beer. - Take one down and pass it around, 54 bottles of beer on the wall. - - 54 bottles of beer on the wall, 54 bottles of beer. - Take one down and pass it around, 53 bottles of beer on the wall. - - 53 bottles of beer on the wall, 53 bottles of beer. - Take one down and pass it around, 52 bottles of beer on the wall. - - 52 bottles of beer on the wall, 52 bottles of beer. - Take one down and pass it around, 51 bottles of beer on the wall. - - 51 bottles of beer on the wall, 51 bottles of beer. - Take one down and pass it around, 50 bottles of beer on the wall. - - 50 bottles of beer on the wall, 50 bottles of beer. - Take one down and pass it around, 49 bottles of beer on the wall. - - 49 bottles of beer on the wall, 49 bottles of beer. - Take one down and pass it around, 48 bottles of beer on the wall. - - 48 bottles of beer on the wall, 48 bottles of beer. - Take one down and pass it around, 47 bottles of beer on the wall. - - 47 bottles of beer on the wall, 47 bottles of beer. - Take one down and pass it around, 46 bottles of beer on the wall. - - 46 bottles of beer on the wall, 46 bottles of beer. - Take one down and pass it around, 45 bottles of beer on the wall. - - 45 bottles of beer on the wall, 45 bottles of beer. - Take one down and pass it around, 44 bottles of beer on the wall. - - 44 bottles of beer on the wall, 44 bottles of beer. - Take one down and pass it around, 43 bottles of beer on the wall. - - 43 bottles of beer on the wall, 43 bottles of beer. - Take one down and pass it around, 42 bottles of beer on the wall. - - 42 bottles of beer on the wall, 42 bottles of beer. - Take one down and pass it around, 41 bottles of beer on the wall. - - 41 bottles of beer on the wall, 41 bottles of beer. - Take one down and pass it around, 40 bottles of beer on the wall. - - 40 bottles of beer on the wall, 40 bottles of beer. - Take one down and pass it around, 39 bottles of beer on the wall. - - 39 bottles of beer on the wall, 39 bottles of beer. - Take one down and pass it around, 38 bottles of beer on the wall. - - 38 bottles of beer on the wall, 38 bottles of beer. - Take one down and pass it around, 37 bottles of beer on the wall. - - 37 bottles of beer on the wall, 37 bottles of beer. - Take one down and pass it around, 36 bottles of beer on the wall. - - 36 bottles of beer on the wall, 36 bottles of beer. - Take one down and pass it around, 35 bottles of beer on the wall. - - 35 bottles of beer on the wall, 35 bottles of beer. - Take one down and pass it around, 34 bottles of beer on the wall. - - 34 bottles of beer on the wall, 34 bottles of beer. - Take one down and pass it around, 33 bottles of beer on the wall. - - 33 bottles of beer on the wall, 33 bottles of beer. - Take one down and pass it around, 32 bottles of beer on the wall. - - 32 bottles of beer on the wall, 32 bottles of beer. - Take one down and pass it around, 31 bottles of beer on the wall. - - 31 bottles of beer on the wall, 31 bottles of beer. - Take one down and pass it around, 30 bottles of beer on the wall. - - 30 bottles of beer on the wall, 30 bottles of beer. - Take one down and pass it around, 29 bottles of beer on the wall. - - 29 bottles of beer on the wall, 29 bottles of beer. - Take one down and pass it around, 28 bottles of beer on the wall. - - 28 bottles of beer on the wall, 28 bottles of beer. - Take one down and pass it around, 27 bottles of beer on the wall. - - 27 bottles of beer on the wall, 27 bottles of beer. - Take one down and pass it around, 26 bottles of beer on the wall. - - 26 bottles of beer on the wall, 26 bottles of beer. - Take one down and pass it around, 25 bottles of beer on the wall. - - 25 bottles of beer on the wall, 25 bottles of beer. - Take one down and pass it around, 24 bottles of beer on the wall. - - 24 bottles of beer on the wall, 24 bottles of beer. - Take one down and pass it around, 23 bottles of beer on the wall. - - 23 bottles of beer on the wall, 23 bottles of beer. - Take one down and pass it around, 22 bottles of beer on the wall. - - 22 bottles of beer on the wall, 22 bottles of beer. - Take one down and pass it around, 21 bottles of beer on the wall. - - 21 bottles of beer on the wall, 21 bottles of beer. - Take one down and pass it around, 20 bottles of beer on the wall. - - 20 bottles of beer on the wall, 20 bottles of beer. - Take one down and pass it around, 19 bottles of beer on the wall. - - 19 bottles of beer on the wall, 19 bottles of beer. - Take one down and pass it around, 18 bottles of beer on the wall. - - 18 bottles of beer on the wall, 18 bottles of beer. - Take one down and pass it around, 17 bottles of beer on the wall. - - 17 bottles of beer on the wall, 17 bottles of beer. - Take one down and pass it around, 16 bottles of beer on the wall. - - 16 bottles of beer on the wall, 16 bottles of beer. - Take one down and pass it around, 15 bottles of beer on the wall. - - 15 bottles of beer on the wall, 15 bottles of beer. - Take one down and pass it around, 14 bottles of beer on the wall. - - 14 bottles of beer on the wall, 14 bottles of beer. - Take one down and pass it around, 13 bottles of beer on the wall. - - 13 bottles of beer on the wall, 13 bottles of beer. - Take one down and pass it around, 12 bottles of beer on the wall. - - 12 bottles of beer on the wall, 12 bottles of beer. - Take one down and pass it around, 11 bottles of beer on the wall. - - 11 bottles of beer on the wall, 11 bottles of beer. - Take one down and pass it around, 10 bottles of beer on the wall. - - 10 bottles of beer on the wall, 10 bottles of beer. - Take one down and pass it around, 9 bottles of beer on the wall. - - 9 bottles of beer on the wall, 9 bottles of beer. - Take one down and pass it around, 8 bottles of beer on the wall. - - 8 bottles of beer on the wall, 8 bottles of beer. - Take one down and pass it around, 7 bottles of beer on the wall. - - 7 bottles of beer on the wall, 7 bottles of beer. - Take one down and pass it around, 1 six-pack of beer on the wall. - - 1 six-pack of beer on the wall, 1 six-pack of beer. - Take one down and pass it around, 5 bottles of beer on the wall. - - 5 bottles of beer on the wall, 5 bottles of beer. - Take one down and pass it around, 4 bottles of beer on the wall. - - 4 bottles of beer on the wall, 4 bottles of beer. - Take one down and pass it around, 3 bottles of beer on the wall. - - 3 bottles of beer on the wall, 3 bottles of beer. - Take one down and pass it around, 2 bottles of beer on the wall. - - 2 bottles of beer on the wall, 2 bottles of beer. - Take one down and pass it around, 1 bottle of beer on the wall. - - 1 bottle of beer on the wall, 1 bottle of beer. - Take it down and pass it around, no more bottles of beer on the wall. - - No more bottles of beer on the wall, no more bottles of beer. - Go to the store and buy some more, 99 bottles of beer on the wall. - SONG - assert_equal expected, CountdownSong.new.song - end end From 0ec49e9d3f9ff436c53756f4810619c5a8a4b2f7 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Tue, 19 May 2020 07:10:20 -0400 Subject: [PATCH 277/285] rename song test --- test/bottles_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index d557963..6453a8b 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -96,7 +96,7 @@ def test_verses .verses(99, 97)) end - def test_the_whole_song + def test_song expected = "This is verse 47.\n" + "\n" + From ff4f96c2022d88bf858cf7be5226a8d97219ee12 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Tue, 19 May 2020 07:10:49 -0400 Subject: [PATCH 278/285] move VerseFake to top of file --- test/bottles_test.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 6453a8b..ae57717 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -3,6 +3,14 @@ require 'minitest/pride' require_relative '../lib/bottles' + +class VerseFake + def self.lyrics(number) + "This is verse #{number}.\n" + end +end + + class BottleVerseTest < Minitest::Test def test_verse_general_rule_upper_bound expected = @@ -68,11 +76,6 @@ def test_verse_0 end end -class VerseFake - def self.lyrics(number) - "This is verse #{number}.\n" - end -end class CountdownSongTest < Minitest::Test def test_verse From b8b686407a87f86e2750b5123a43352253da200d Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Tue, 19 May 2020 07:11:50 -0400 Subject: [PATCH 279/285] add verse role test --- test/bottles_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index ae57717..194580d 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -3,6 +3,11 @@ require 'minitest/pride' require_relative '../lib/bottles' +module VerseRoleTest + def test_plays_verse_role + assert_respond_to @role_player, :lyrics + end +end class VerseFake def self.lyrics(number) From 66505164890c26c508c5142203f711ef5c87e159 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Tue, 19 May 2020 07:12:36 -0400 Subject: [PATCH 280/285] set @role_player in BotttleVerseTest#setup --- test/bottles_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index 194580d..bc53cca 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -17,6 +17,10 @@ def self.lyrics(number) class BottleVerseTest < Minitest::Test + def setup + @role_player = BottleVerse + end + def test_verse_general_rule_upper_bound expected = "99 bottles of beer on the wall, " + From cc55fae24523ab9561257a627f0c3f669b1fd01e Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Tue, 19 May 2020 07:13:03 -0400 Subject: [PATCH 281/285] include VerseRoleTest in BottleVerseTest --- test/bottles_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index bc53cca..a10e5a3 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -17,6 +17,8 @@ def self.lyrics(number) class BottleVerseTest < Minitest::Test + include VerseRoleTest + def setup @role_player = BottleVerse end From 4eb1c601c3daecba6c405bf7ec2d12586e0b50a5 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Thu, 28 May 2020 07:24:44 -0400 Subject: [PATCH 282/285] create VerseFakeTest --- test/bottles_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/bottles_test.rb b/test/bottles_test.rb index a10e5a3..0f0e240 100644 --- a/test/bottles_test.rb +++ b/test/bottles_test.rb @@ -15,6 +15,14 @@ def self.lyrics(number) end end +class VerseFakeTest < Minitest::Test + include VerseRoleTest + + def setup + @role_player = VerseFake + end +end + class BottleVerseTest < Minitest::Test include VerseRoleTest From 21affb8ddbeae56e1a28608492d51197dcd4e328 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Wed, 17 Jun 2020 07:53:01 -0400 Subject: [PATCH 283/285] remove verse_template default --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index edfe185..dc8a8af 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,7 +1,7 @@ class CountdownSong attr_reader :verse_template, :max, :min - def initialize(verse_template: BottleVerse, max: 99, min: 0) + def initialize(verse_template:, max: 99, min: 0) @verse_template = verse_template @max, @min = max, min end From 4d130d63d71f6837a8c06f9fa2e502b6fbbc7394 Mon Sep 17 00:00:00 2001 From: Sandi Metz Date: Wed, 17 Jun 2020 07:53:47 -0400 Subject: [PATCH 284/285] set max default to 999999 --- lib/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index dc8a8af..4887894 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -1,7 +1,7 @@ class CountdownSong attr_reader :verse_template, :max, :min - def initialize(verse_template:, max: 99, min: 0) + def initialize(verse_template:, max: 999999, min: 0) @verse_template = verse_template @max, @min = max, min end From 7aaed88f5167cba07e506f235c8d5cc84b1624a7 Mon Sep 17 00:00:00 2001 From: JonahHouseKin <111381622+JonahHouseKin@users.noreply.github.com> Date: Fri, 19 Jan 2024 18:56:31 -0800 Subject: [PATCH 285/285] Initial refactoring --- lib/bottles.rb | 75 ++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/lib/bottles.rb b/lib/bottles.rb index 4887894..d1078fd 100644 --- a/lib/bottles.rb +++ b/lib/bottles.rb @@ -22,7 +22,7 @@ def verse(number) class BottleVerse def self.lyrics(number) - new(BottleNumber.for(number)).lyrics + new(BottleNumber.new(number)).lyrics end attr_reader :bottle_number @@ -41,19 +41,6 @@ def lyrics class BottleNumber - def self.for(number) - case number - when 0 - BottleNumber0 - when 1 - BottleNumber1 - when 6 - BottleNumber6 - else - BottleNumber - end.new(number) - end - attr_reader :number def initialize(number) @number = number @@ -64,56 +51,40 @@ def to_s end def quantity - number.to_s + BOTTLE_NUMBER_DEFAULTS[number]&.[](:quantity) || number.to_s end def container - "bottles" + BOTTLE_NUMBER_DEFAULTS[number]&.[](:container) || "bottles" end def action - "Take #{pronoun} down and pass it around" + BOTTLE_NUMBER_DEFAULTS[number]&.[](:action) || "Take #{pronoun} down and pass it around" end def pronoun - "one" + BOTTLE_NUMBER_DEFAULTS[number]&.[](:pronoun) || "one" end def successor - BottleNumber.for(number - 1) + BOTTLE_NUMBER_DEFAULTS[number]&.[](:successor) ? BottleNumber.new(BOTTLE_NUMBER_DEFAULTS[number]&.[](:successor)) : BottleNumber.new(number - 1) end end -class BottleNumber0 < BottleNumber - def quantity - "no more" - end - - def action - "Go to the store and buy some more" - end - - def successor - BottleNumber.for(99) - end -end - -class BottleNumber1 < BottleNumber - def container - "bottle" - end - - def pronoun - "it" - end -end - -class BottleNumber6 < BottleNumber - def quantity - "1" - end - - def container - "six-pack" - end -end +BOTTLE_NUMBER_DEFAULTS = { + 0 => { + quantity: "no more", + action: "Go to the store and buy some more", + successor: 99 + }, + 1 => { + container: "bottle", + pronoun: "it" + }, + 6 => { + quantity: "1", + container: "six-pack" + } +} + +pp BOTTLE_NUMBER_DEFAULTS[9]&.[](:quantity) \ No newline at end of file