From 476a8657891ea59d09c0da02395b638bfdc47477 Mon Sep 17 00:00:00 2001 From: Saria Beutel Date: Tue, 21 Mar 2017 22:37:39 +1000 Subject: [PATCH 1/4] first run of tests --- .ruby-version | 2 +- models/sarahb_fizzbuzz.rb | 31 ++++++++++++++++++++++++++++ specs/models/sarahb_fizzbuzz_spec.rb | 26 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 models/sarahb_fizzbuzz.rb create mode 100644 specs/models/sarahb_fizzbuzz_spec.rb diff --git a/.ruby-version b/.ruby-version index 7208c21..197c4d5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4 \ No newline at end of file +2.4.0 diff --git a/models/sarahb_fizzbuzz.rb b/models/sarahb_fizzbuzz.rb new file mode 100644 index 0000000..fb29c08 --- /dev/null +++ b/models/sarahb_fizzbuzz.rb @@ -0,0 +1,31 @@ + +class Fizzbuzz + + def initialize number + @fizzbuzz = number + end + + def string + x = @fizzbuzz + if x % 3 == 0 && x % 5 == 0 + return "fizz" + elsif x == 5 + return "buzz" + elsif x == 15 + return "fizzbuzz" + else + return x + end + end + +end + +# if x % 3 == 0 && x % 5 == 0 +# puts "Fizzbuzz!" +# elsif x % 3 == 0 +# puts "Fizz" +# elsif x % 5 == 0 +# puts "Buzz" +# else +# puts x +# end diff --git a/specs/models/sarahb_fizzbuzz_spec.rb b/specs/models/sarahb_fizzbuzz_spec.rb new file mode 100644 index 0000000..4097706 --- /dev/null +++ b/specs/models/sarahb_fizzbuzz_spec.rb @@ -0,0 +1,26 @@ +require 'rspec' +require_relative "../../models/sarahb_fizzbuzz" + +describe 'fizzbuzz' do + it "a fizzbuzz of 1 returns 1" do + fb = Fizzbuzz.new(1) + expect(fb.string).to eq(1) + end + it "returns fizz for 3" do + fb = Fizzbuzz.new(3) + expect(fb.string).to eq('fizz') + end + it 'returns buzz for 5' do + fb = Fizzbuzz.new(5) + expect(fb.string).to eq('buzz') + + end + it 'returns fizzbuzz for 15' do + fb = Fizzbuzz.new(15) + expect(fb.string).to eq('fizzbuzz') + end + # it 'returns fizz for 21' do + # fb = Fizzbuzz.new(21) + # expect(fb.string).to eq('fizz') + # end +end From e99f566d982b6f614f5b102b6917ec92ac1ec4fd Mon Sep 17 00:00:00 2001 From: Saria Beutel Date: Tue, 21 Mar 2017 22:50:23 +1000 Subject: [PATCH 2/4] second round of tests --- models/sarahb_fizzbuzz.rb | 6 +++--- specs/models/sarahb_fizzbuzz_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/models/sarahb_fizzbuzz.rb b/models/sarahb_fizzbuzz.rb index fb29c08..c65d593 100644 --- a/models/sarahb_fizzbuzz.rb +++ b/models/sarahb_fizzbuzz.rb @@ -8,11 +8,11 @@ def initialize number def string x = @fizzbuzz if x % 3 == 0 && x % 5 == 0 + return "fizzbuzz" + elsif x % 3 == 0 return "fizz" - elsif x == 5 + elsif x % 5 == 0 return "buzz" - elsif x == 15 - return "fizzbuzz" else return x end diff --git a/specs/models/sarahb_fizzbuzz_spec.rb b/specs/models/sarahb_fizzbuzz_spec.rb index 4097706..175dcbc 100644 --- a/specs/models/sarahb_fizzbuzz_spec.rb +++ b/specs/models/sarahb_fizzbuzz_spec.rb @@ -19,8 +19,8 @@ fb = Fizzbuzz.new(15) expect(fb.string).to eq('fizzbuzz') end - # it 'returns fizz for 21' do - # fb = Fizzbuzz.new(21) - # expect(fb.string).to eq('fizz') - # end + it 'returns fizz for 21' do + fb = Fizzbuzz.new(21) + expect(fb.string).to eq('fizz') + end end From 3c4d09623b852f21511506c8f1828c9a43c8d1a1 Mon Sep 17 00:00:00 2001 From: Saria Beutel Date: Fri, 24 Mar 2017 13:29:41 +1000 Subject: [PATCH 3/4] Added loop --- models/sarahb_fizzbuzz.rb | 14 +++++--------- specs/models/sarahb_fizzbuzz_spec.rb | 15 +++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/models/sarahb_fizzbuzz.rb b/models/sarahb_fizzbuzz.rb index c65d593..d8b003a 100644 --- a/models/sarahb_fizzbuzz.rb +++ b/models/sarahb_fizzbuzz.rb @@ -20,12 +20,8 @@ def string end -# if x % 3 == 0 && x % 5 == 0 -# puts "Fizzbuzz!" -# elsif x % 3 == 0 -# puts "Fizz" -# elsif x % 5 == 0 -# puts "Buzz" -# else -# puts x -# end + +(1..100).each do |n| + fb = Fizzbuzz.new(n) + puts (fb.string) +end diff --git a/specs/models/sarahb_fizzbuzz_spec.rb b/specs/models/sarahb_fizzbuzz_spec.rb index 175dcbc..0b416f5 100644 --- a/specs/models/sarahb_fizzbuzz_spec.rb +++ b/specs/models/sarahb_fizzbuzz_spec.rb @@ -2,25 +2,24 @@ require_relative "../../models/sarahb_fizzbuzz" describe 'fizzbuzz' do - it "a fizzbuzz of 1 returns 1" do + it " returns 1" do fb = Fizzbuzz.new(1) expect(fb.string).to eq(1) end - it "returns fizz for 3" do + it "returns fizz for a multiple of 3" do fb = Fizzbuzz.new(3) expect(fb.string).to eq('fizz') end - it 'returns buzz for 5' do + it 'returns buzz for a multiple 5' do fb = Fizzbuzz.new(5) expect(fb.string).to eq('buzz') end - it 'returns fizzbuzz for 15' do + it 'returns fizzbuzz for multiples of 3 and 5' do fb = Fizzbuzz.new(15) expect(fb.string).to eq('fizzbuzz') end - it 'returns fizz for 21' do - fb = Fizzbuzz.new(21) - expect(fb.string).to eq('fizz') - end + end + +puts Fizzbuzz.new(15).string From 2973a8387ab9222ede7e17727e126baef0b71b72 Mon Sep 17 00:00:00 2001 From: Saria Beutel Date: Mon, 27 Mar 2017 10:58:50 +1000 Subject: [PATCH 4/4] changed to case statement --- models/sarahb_fizzbuzz.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/models/sarahb_fizzbuzz.rb b/models/sarahb_fizzbuzz.rb index d8b003a..9165a3f 100644 --- a/models/sarahb_fizzbuzz.rb +++ b/models/sarahb_fizzbuzz.rb @@ -7,17 +7,17 @@ def initialize number def string x = @fizzbuzz - if x % 3 == 0 && x % 5 == 0 - return "fizzbuzz" - elsif x % 3 == 0 - return "fizz" - elsif x % 5 == 0 - return "buzz" - else - return x - end - end - + case + when x % 3 == 0 && x % 5 == 0 + "fizzbuzz" + when x % 3 == 0 + "fizz" + when x % 5 == 0 + "buzz" + else + x + end + end end