Skip to content

Instantly share code, notes, and snippets.

@ykon
Created November 17, 2019 12:53
Show Gist options
  • Save ykon/dc2624d58c1f6d7b8db015aa7e470630 to your computer and use it in GitHub Desktop.
Save ykon/dc2624d58c1f6d7b8db015aa7e470630 to your computer and use it in GitHub Desktop.
# typed: ignore
require_relative '../fizzbuzz'
describe 'FizzBuzz' do
it 'check_number' do
f = ->(n) { FizzBuzz.check_number(n) }
expect{f.(-1)}.to raise_error ArgumentError
expect{f.(0)}.to raise_error ArgumentError
expect{f.(1)}.to_not raise_error
end
it 'is_fizz' do
f = ->(n) { FizzBuzz.is_fizz(n) }
expect{f.(-1)}.to raise_error ArgumentError
expect{f.(0)}.to raise_error ArgumentError
expect(f.(1)).to eq false
expect(f.(2)).to eq false
expect(f.(3)).to eq true
expect(f.(4)).to eq false
expect(f.(5)).to eq false
expect(f.(6)).to eq true
end
it 'is_buzz' do
f = ->(n) { FizzBuzz.is_buzz(n) }
expect{f.(-1)}.to raise_error ArgumentError
expect{f.(0)}.to raise_error ArgumentError
expect(f.(1)).to eq false
expect(f.(4)).to eq false
expect(f.(5)).to eq true
expect(f.(6)).to eq false
expect(f.(9)).to eq false
expect(f.(10)).to eq true
expect(f.(11)).to eq false
end
it 'is_fizzbuzz' do
f = ->(n) { FizzBuzz.is_fizzbuzz(n) }
expect{f.(-1)}.to raise_error ArgumentError
expect{f.(0)}.to raise_error ArgumentError
expect(f.(1)).to eq false
expect(f.(14)).to eq false
expect(f.(15)).to eq true
expect(f.(16)).to eq false
expect(f.(29)).to eq false
expect(f.(30)).to eq true
expect(f.(31)).to eq false
end
it 'number_as' do
f = ->(n) { FizzBuzz.number_as(n) }
expect{f.(-1)}.to raise_error ArgumentError
expect{f.(0)}.to raise_error ArgumentError
expect(f.(1)).to eq [:Number, 1]
expect(f.(2)).to eq [:Number, 2]
expect(f.(3)).to eq [:Fizz, 3]
expect(f.(4)).to eq [:Number, 4]
expect(f.(5)).to eq [:Buzz, 5]
expect(f.(6)).to eq [:Fizz, 6]
expect(f.(7)).to eq [:Number, 7]
expect(f.(8)).to eq [:Number, 8]
expect(f.(9)).to eq [:Fizz, 9]
expect(f.(10)).to eq [:Buzz, 10]
expect(f.(11)).to eq [:Number, 11]
expect(f.(12)).to eq [:Fizz, 12]
expect(f.(13)).to eq [:Number, 13]
expect(f.(14)).to eq [:Number, 14]
expect(f.(15)).to eq [:FizzBuzz, 15]
expect(f.(16)).to eq [:Number, 16]
expect(f.(30)).to eq [:FizzBuzz, 30]
expect(f.(31)).to eq [:Number, 31]
end
it 'to_str' do
f = ->(fz) { FizzBuzz.to_str(fz) }
expect{f.([:Test, 10])}.to raise_error ArgumentError
expect(f.([:Number, 1])).to eq '1'
expect(f.([:Number, 2])).to eq '2'
expect(f.([:Fizz, 3])).to eq 'Fizz'
expect(f.([:Number, 4])).to eq '4'
expect(f.([:Buzz, 5])).to eq 'Buzz'
expect(f.([:Fizz, 6])).to eq 'Fizz'
expect(f.([:Number, 7])).to eq '7'
expect(f.([:Number, 8])).to eq '8'
expect(f.([:Fizz, 9])).to eq 'Fizz'
expect(f.([:Buzz, 10])).to eq 'Buzz'
expect(f.([:Number, 11])).to eq '11'
expect(f.([:Fizz, 12])).to eq 'Fizz'
expect(f.([:Number, 13])).to eq '13'
expect(f.([:Number, 14])).to eq '14'
expect(f.([:FizzBuzz, 15])).to eq 'FizzBuzz'
expect(f.([:Number, 16])).to eq '16'
expect(f.([:FizzBuzz, 30])).to eq 'FizzBuzz'
expect(f.([:Number, 31])).to eq '31'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment