fizz-buzz 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fizz-buzz.gemspec +2 -2
- data/lib/fizz-buzz.rb +14 -12
- data/test/test_fizz-buzz.rb +22 -22
- metadata +11 -11
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/fizz-buzz.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fizz-buzz}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kerri Miller"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2012-01-11}
|
13
13
|
s.description = %q{I got sick of doing this test in interviews, so next time someone asks me to do so, I'm going to instead hand them a business card with a URL for this gem on it.}
|
14
14
|
s.email = %q{kerrizor@kerrizor.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/fizz-buzz.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Returns an array solving the classic 1 to 100 FizzBuzz problem.
|
4
|
-
def crunch(start=1, stop=100)
|
5
|
-
return nil unless start < stop
|
6
|
-
|
1
|
+
module FizzBuzz
|
2
|
+
def fizzbuzz
|
7
3
|
return_values = Array.new
|
8
4
|
|
9
|
-
|
5
|
+
self.each do |n|
|
10
6
|
if n.fizzbuzz?
|
11
7
|
return_values << "FizzBuzz"
|
12
8
|
elsif n.buzz?
|
@@ -23,7 +19,7 @@ class FizzBuzz
|
|
23
19
|
end
|
24
20
|
|
25
21
|
|
26
|
-
module
|
22
|
+
module FizzBuzzNumerics
|
27
23
|
# For testing the Fizz-, Buzz-, or Fizzbuzz-ness of a Fixnum
|
28
24
|
# 3.fizz? # => true
|
29
25
|
# 3.buzz? # => false
|
@@ -45,13 +41,19 @@ module FizzBuzziness
|
|
45
41
|
end
|
46
42
|
|
47
43
|
|
48
|
-
class
|
49
|
-
include
|
44
|
+
class Range
|
45
|
+
include FizzBuzz
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
class Array
|
50
|
+
include FizzBuzz
|
50
51
|
end
|
51
52
|
|
52
53
|
|
53
|
-
class
|
54
|
-
include
|
54
|
+
class Numeric
|
55
|
+
include FizzBuzzNumerics
|
55
56
|
end
|
56
57
|
|
57
58
|
|
59
|
+
|
data/test/test_fizz-buzz.rb
CHANGED
@@ -2,36 +2,36 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestFizzBuzz < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def test_new_fizzbuzz
|
6
|
-
assert_instance_of FizzBuzz, FizzBuzz.new
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
5
|
def setup
|
11
|
-
@
|
6
|
+
@fizzbuzz_range = (1..100).fizzbuzz
|
7
|
+
@fizzbuzz_array = Array(1..100).fizzbuzz
|
12
8
|
end
|
13
9
|
|
10
|
+
def test_generic_fizzbuzz
|
11
|
+
assert_respond_to Array.new, :fizzbuzz
|
12
|
+
assert_respond_to Numeric.new, :fizz?
|
13
|
+
end
|
14
14
|
|
15
|
-
def
|
16
|
-
assert_respond_to @
|
17
|
-
assert_kind_of Array, @
|
15
|
+
def test_fizzbuzz_range
|
16
|
+
assert_respond_to @fizzbuzz_range, :fizzbuzz
|
17
|
+
assert_kind_of Array, @fizzbuzz_range
|
18
18
|
|
19
|
-
assert_equal 100, @
|
20
|
-
assert_equal "Fizz", @
|
21
|
-
assert_equal "4", @
|
22
|
-
assert_equal "Buzz", @
|
23
|
-
assert_equal "FizzBuzz", @
|
19
|
+
assert_equal 100, @fizzbuzz_range.length
|
20
|
+
assert_equal "Fizz", @fizzbuzz_range[2]
|
21
|
+
assert_equal "4", @fizzbuzz_range[3].to_s
|
22
|
+
assert_equal "Buzz", @fizzbuzz_range[4]
|
23
|
+
assert_equal "FizzBuzz", @fizzbuzz_range[14]
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_fizzbuzz_array
|
27
|
+
assert_respond_to @fizzbuzz_array, :fizzbuzz
|
28
|
+
assert_kind_of Array, @fizzbuzz_array
|
26
29
|
|
27
|
-
|
28
|
-
assert_equal
|
29
|
-
assert_equal "
|
30
|
-
assert_equal "
|
31
|
-
assert_equal "
|
32
|
-
assert_equal "FizzBuzz", @fizzbuzz.crunch(4,17)[11]
|
33
|
-
|
34
|
-
assert_nil @fizzbuzz.crunch(44,17)
|
30
|
+
assert_equal 100, @fizzbuzz_array.length
|
31
|
+
assert_equal "Fizz", @fizzbuzz_array[2]
|
32
|
+
assert_equal "4", @fizzbuzz_array[3].to_s
|
33
|
+
assert_equal "Buzz", @fizzbuzz_array[4]
|
34
|
+
assert_equal "FizzBuzz", @fizzbuzz_array[14]
|
35
35
|
end
|
36
36
|
|
37
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fizz-buzz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-11 00:00:00.000000000 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &2167207300 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2167207300
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &2167206820 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2167206820
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &2167206340 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.6.4
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2167206340
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &2167205860 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2167205860
|
59
59
|
description: I got sick of doing this test in interviews, so next time someone asks
|
60
60
|
me to do so, I'm going to instead hand them a business card with a URL for this
|
61
61
|
gem on it.
|
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash:
|
97
|
+
hash: 2225280517144778850
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|