-
Notifications
You must be signed in to change notification settings - Fork 0
Classical fizzbuzz lilly #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # count to 100 | ||
| class FizzBuzz | ||
|
|
||
| # Counts to 100. | ||
| # Makes an array of length 100 where each value is the fizzbuzz value. | ||
| def to_array | ||
| # Start with an empty array. | ||
| array = [] | ||
| # Count from 1 to 100. | ||
| (1..100).each do |x| | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try moving this out of the class
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if I do this, should I just get rid of the array? |
||
| # If the number matches any of the fizzbuzz numbers, add the string. | ||
| if fizzbuzz? (x) | ||
| array.push "fizzbuzz" | ||
| elsif fizz? (x) | ||
| array.push "fizz" | ||
| elsif buzz? (x) | ||
| array.push "buzz" | ||
| # Otherwise just add the number to our array. | ||
| else | ||
| array.push x | ||
| end | ||
| end | ||
| # Return the finished array of 100 values. | ||
| array | ||
| end | ||
|
|
||
| # FizzBuzz divisible by 3 and 5 | ||
| # % is modulo division. It divides a number and returns the remainder. | ||
| # If the remainder is 0, the number was equally divisible. | ||
| def fizzbuzz?(x) | ||
| x % 3 == 0 && x % 5 == 0 | ||
| end | ||
|
|
||
| # Fizz divisible by 3 | ||
| def fizz?(x) | ||
| x % 3 == 0 | ||
| end | ||
|
|
||
| # Buzz divisible by 5 | ||
| def buzz?(x) | ||
| x % 5 == 0 | ||
| end | ||
| end | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| require 'rspec' | ||
| require_relative "../models/fizzbuzz" | ||
|
|
||
|
|
||
| describe FizzBuzz do | ||
| describe '.fizzbuzz' do | ||
| it 'returns FizzBuzz on numbers divisible by 3 and 5' do | ||
| fizzbuzz = FizzBuzz.new | ||
| expect(fizzbuzz.fizzbuzz?(15)).to be true | ||
| expect(fizzbuzz.fizzbuzz?(16)).to be false | ||
| end | ||
| end | ||
|
|
||
| describe '.fizz' do | ||
| it 'returns fizz on numbers divisible by 3' do | ||
| fizz = FizzBuzz.new | ||
| expect(fizz.fizz?(3)).to be true | ||
| expect(fizz.fizz?(4)).to be false | ||
| end | ||
| end | ||
|
|
||
| describe '.buzz' do | ||
| it 'returns buzz on numbers divisible by 5' do | ||
| buzz = FizzBuzz.new | ||
| expect(buzz.buzz?(5)).to be true | ||
| expect(buzz.buzz?(74)).to be false | ||
| end | ||
| end | ||
|
|
||
| describe '.to_array' do | ||
| it 'makes a fizzbuzz array' do | ||
| fizzbuzz = FizzBuzz.new | ||
| array = fizzbuzz.to_array | ||
| expect(array.count).to eq(100) | ||
| # These tests will work because counting of the array starts at 0. | ||
| # Eg. 88 is the key, 89 is the value. | ||
| expect(array[88]).to eq(89) | ||
| expect(array[77]).to eq('fizz') | ||
| expect(array[79]).to eq('buzz') | ||
| expect(array[74]).to eq('fizzbuzz') | ||
| end | ||
| end | ||
|
|
||
| # Unused play area | ||
| # describe 'play area' do | ||
| # it 'returns 1 - 100 with fizzbuzz, fizz and buzz' do | ||
| # count = FizzBuzz.new | ||
| # (1..100).each do |x| | ||
| # if count.fizzbuzz (x) | ||
| # puts "fizzbuzz" | ||
| # elsif count.fizz (x) | ||
| # puts "fizz" | ||
| # elsif count.buzz (x) | ||
| # puts "buzz" | ||
| # else | ||
| # puts x | ||
| # end | ||
| # end | ||
| # end | ||
| # end | ||
| end |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can add the array method after you define the fizz/buzz's