ruby-fizzbuzz 0.0.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/CHANGES +41 -20
- data/CHANGES.rdoc +41 -20
- data/COPYRIGHT +1 -1
- data/README.rdoc +2 -2
- data/Rakefile +5 -4
- data/TODO +4 -4
- data/VERSION +1 -1
- data/benchmark/benchmark_fizzbuzz.rb +4 -4
- data/bin/fizzbuzz +1 -1
- data/ext/fizzbuzz/common.h +1 -1
- data/ext/fizzbuzz/extconf.rb +10 -3
- data/ext/fizzbuzz/fizzbuzz.c +34 -10
- data/ext/fizzbuzz/fizzbuzz.h +4 -4
- data/lib/fizzbuzz.rb +146 -15
- data/lib/fizzbuzz/{array.rb → core/array.rb} +5 -5
- data/lib/fizzbuzz/{bignum.rb → core/bignum.rb} +2 -2
- data/lib/fizzbuzz/{integer.rb → core/integer.rb} +2 -2
- data/lib/fizzbuzz/{range.rb → core/range.rb} +11 -13
- data/lib/fizzbuzz/version.rb +2 -2
- data/ruby-fizzbuzz.gemspec +6 -12
- data/test/test_fizzbuzz.rb +363 -238
- metadata +14 -98
data/ext/fizzbuzz/fizzbuzz.h
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
/*
|
4
4
|
* fizzbuzz.h
|
5
5
|
*
|
6
|
-
* Copyright 2012-
|
6
|
+
* Copyright 2012-2014 Krzysztof Wilczynski
|
7
7
|
*
|
8
8
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
9
9
|
* you may not use this file except in compliance with the License.
|
@@ -116,9 +116,9 @@ struct fizzbuzz_exception {
|
|
116
116
|
typedef struct fizzbuzz_exception fizzbuzz_exception_t;
|
117
117
|
|
118
118
|
static const char *errors[] = {
|
119
|
-
"must be
|
120
|
-
"must be
|
121
|
-
"must be
|
119
|
+
"must be a Fixnum or Bignum type",
|
120
|
+
"must be a Fixnum or Bignum type for start",
|
121
|
+
"must be a Fixnum or Bignum type for stop",
|
122
122
|
"start value is higher than stop value",
|
123
123
|
"stop value is lower than start value",
|
124
124
|
NULL
|
data/lib/fizzbuzz.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# fizzbuzz.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -22,12 +22,16 @@
|
|
22
22
|
|
23
23
|
# :startdoc:
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
require '
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
gem 'json', '>= 1.8.1'
|
26
|
+
|
27
|
+
require 'json'
|
28
|
+
|
29
|
+
require_relative 'fizzbuzz/fizzbuzz'
|
30
|
+
require_relative 'fizzbuzz/version'
|
31
|
+
require_relative 'fizzbuzz/core/integer'
|
32
|
+
require_relative 'fizzbuzz/core/bignum'
|
33
|
+
require_relative 'fizzbuzz/core/array'
|
34
|
+
require_relative 'fizzbuzz/core/range'
|
31
35
|
|
32
36
|
#
|
33
37
|
# Yet another _FizzBuzz_ in Ruby.
|
@@ -37,12 +41,12 @@ require 'fizzbuzz/range'
|
|
37
41
|
class FizzBuzz
|
38
42
|
#
|
39
43
|
# call-seq:
|
40
|
-
# FizzBuzz.fizzbuzz( start, stop, reverse ) -> array
|
41
44
|
# FizzBuzz.fizzbuzz( start, stop, reverse ) {|value| block } -> self
|
45
|
+
# FizzBuzz.fizzbuzz( start, stop, reverse ) -> array
|
42
46
|
#
|
43
|
-
# Returns either an array or accepts a block if such is given. When a block is
|
44
|
-
# then it will call the block once for each subsequent value for a given
|
45
|
-
# +start+ to +stop+, passing the value as a parameter to the block.
|
47
|
+
# Returns either an +array+ or accepts a block if such is given. When a block is
|
48
|
+
# given then it will call the block once for each subsequent value for a given
|
49
|
+
# range from +start+ to +stop+, passing the value as a parameter to the block.
|
46
50
|
#
|
47
51
|
# Additionally, if the value of +reverse+ is set to be +true+ then the results will
|
48
52
|
# be given in an <em>reverse order</em> whether in a resulting array or when passing
|
@@ -77,15 +81,142 @@ class FizzBuzz
|
|
77
81
|
#
|
78
82
|
# See also: FizzBuzz::[], FizzBuzz::new, FizzBuzz#to_a, FizzBuzz#each and FizzBuzz#reverse_each
|
79
83
|
#
|
80
|
-
def self.fizzbuzz(start, stop, reverse = false)
|
81
|
-
fb =
|
84
|
+
def self.fizzbuzz(start, stop, reverse = false, &block)
|
85
|
+
fb = new(start, stop)
|
82
86
|
|
83
87
|
if block_given?
|
84
|
-
fb.send(reverse ? :reverse_each : :each)
|
88
|
+
fb.send(reverse ? :reverse_each : :each, &block)
|
89
|
+
self
|
85
90
|
else
|
86
|
-
|
91
|
+
fb.to_a.send(reverse ? :reverse : :to_a)
|
87
92
|
end
|
88
93
|
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# call-seq:
|
97
|
+
# fizzbuzz.to_hash -> hash
|
98
|
+
#
|
99
|
+
# Returns a +hash+ representing the _FizzBuzz_ object.
|
100
|
+
#
|
101
|
+
# Example:
|
102
|
+
#
|
103
|
+
# fb = FizzBuzz.new(1, 15) #=> #<FizzBuzz:0x007fbe84 @start=1, @stop=15>
|
104
|
+
# fb.to_hash
|
105
|
+
#
|
106
|
+
# Produces:
|
107
|
+
#
|
108
|
+
# {
|
109
|
+
# "fizzbuzz" => {
|
110
|
+
# "start" => 1,
|
111
|
+
# "stop" => 15
|
112
|
+
# }
|
113
|
+
# }
|
114
|
+
#
|
115
|
+
# See also: FizzBuzz#as_json and FizzBuzz#to_json
|
116
|
+
#
|
117
|
+
def to_hash
|
118
|
+
{
|
119
|
+
'fizzbuzz' => {
|
120
|
+
'start' => @start,
|
121
|
+
'stop' => @stop
|
122
|
+
}
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# call-seq:
|
128
|
+
# fizzbuzz.as_json -> hash
|
129
|
+
#
|
130
|
+
# Returns a +hash+ representing the _FizzBuzz_ object that will be
|
131
|
+
# used when generating a _JSON_ string representation.
|
132
|
+
#
|
133
|
+
# Example:
|
134
|
+
#
|
135
|
+
# fb = FizzBuzz.new(1, 15) #=> #<FizzBuzz:0x007f90c1 @start=1, @stop=15>
|
136
|
+
# fb.as_json
|
137
|
+
#
|
138
|
+
# Produces:
|
139
|
+
#
|
140
|
+
# {
|
141
|
+
# "json_class" => "FizzBuzz",
|
142
|
+
# "fizzbuzz" => {
|
143
|
+
# "start" => 1,
|
144
|
+
# "stop" => 15
|
145
|
+
# }
|
146
|
+
# }
|
147
|
+
#
|
148
|
+
# See also: FizzBuzz#to_json and FizzBuzz#to_hash
|
149
|
+
#
|
150
|
+
def as_json(*arguments)
|
151
|
+
{ JSON.create_id => self.class.name }.merge(to_hash)
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# call-seq:
|
156
|
+
# fizzbuzz.to_json -> string
|
157
|
+
#
|
158
|
+
# Returns a _JSON_ string representing the _FizzBuzz_ object.
|
159
|
+
#
|
160
|
+
# Example:
|
161
|
+
#
|
162
|
+
# fb = FizzBuzz.new(1, 15) #=> #<FizzBuzz:0x007fce83 @start=1, @stop=15>
|
163
|
+
# fb.to_json
|
164
|
+
#
|
165
|
+
# Produces:
|
166
|
+
#
|
167
|
+
# {
|
168
|
+
# "json_class": "FizzBuzz",
|
169
|
+
# "fizzbuzz": {
|
170
|
+
# "start": 1,
|
171
|
+
# "stop": 15
|
172
|
+
# }
|
173
|
+
# }
|
174
|
+
#
|
175
|
+
# See also: FizzBuzz::json_create, FizzBuzz#as_json and FizzBuzz#to_hash
|
176
|
+
#
|
177
|
+
def to_json(*arguments)
|
178
|
+
as_json.to_json(*arguments)
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# call-seq:
|
183
|
+
# FizzBuzz.json_create( object ) -> FizzBuzz
|
184
|
+
#
|
185
|
+
# Creates a new _FizzBuzz_ object with both the +start+ and +stop+ values
|
186
|
+
# set accordingly given a _JSON_ string that is an representation of the
|
187
|
+
# _FizzBuzz_ object.
|
188
|
+
#
|
189
|
+
# Example:
|
190
|
+
#
|
191
|
+
# json = <<-EOS
|
192
|
+
# {
|
193
|
+
# "json_class": "FizzBuzz",
|
194
|
+
# "fizzbuzz": {
|
195
|
+
# "start": 1,
|
196
|
+
# "stop": 15
|
197
|
+
# }
|
198
|
+
# }
|
199
|
+
# EOS
|
200
|
+
#
|
201
|
+
# fb = JSON.load(json) #=> #<FizzBuzz:0x007fc082 @start=1, @stop=15>
|
202
|
+
# fb.to_hash
|
203
|
+
#
|
204
|
+
# Produces:
|
205
|
+
#
|
206
|
+
# {
|
207
|
+
# "fizzbuzz" => {
|
208
|
+
# "start" => 1,
|
209
|
+
# "stop" => 15
|
210
|
+
# }
|
211
|
+
# }
|
212
|
+
#
|
213
|
+
# See also: FizzBuzz#to_json, FizzBuzz::[], FizzBuzz::new and FizzBuzz::fizzbuzz
|
214
|
+
#
|
215
|
+
def self.json_create(object)
|
216
|
+
new(*object['fizzbuzz'].values_at('start', 'stop'))
|
217
|
+
end
|
218
|
+
|
219
|
+
alias_method :to_h, :to_hash
|
89
220
|
end
|
90
221
|
|
91
222
|
# :enddoc:
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# :stopdoc:
|
4
4
|
|
5
5
|
#
|
6
|
-
# array.rb
|
6
|
+
# core/array.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -28,10 +28,10 @@
|
|
28
28
|
class Array
|
29
29
|
#
|
30
30
|
# call-seq:
|
31
|
-
# array.fizzbuzz( reverse ) -> array
|
32
31
|
# array.fizzbuzz( reverse ) {|value| block } -> self
|
32
|
+
# array.fizzbuzz( reverse ) -> array
|
33
33
|
#
|
34
|
-
# Returns either an array or accepts a block if such is given. When a block is given
|
34
|
+
# Returns either an +array+ or accepts a block if such is given. When a block is given
|
35
35
|
# then it will call the block once for each subsequent value for a given array, passing
|
36
36
|
# the value as a parameter to the block.
|
37
37
|
#
|
@@ -71,7 +71,7 @@ class Array
|
|
71
71
|
# See also: FizzBuzz::fizzbuzz, FizzBuzz#to_a, FizzBuzz#each and FizzBuzz#reverse_each
|
72
72
|
#
|
73
73
|
def fizzbuzz(reverse = false)
|
74
|
-
values = self.send(reverse ? :reverse : :
|
74
|
+
values = self.send(reverse ? :reverse : :to_a)
|
75
75
|
|
76
76
|
if block_given?
|
77
77
|
values.each {|i| yield FizzBuzz[i] }
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# :stopdoc:
|
4
4
|
|
5
5
|
#
|
6
|
-
# bignum.rb
|
6
|
+
# core/bignum.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# :stopdoc:
|
4
4
|
|
5
5
|
#
|
6
|
-
# integer.rb
|
6
|
+
# core/integer.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# :stopdoc:
|
4
4
|
|
5
5
|
#
|
6
|
-
# range.rb
|
6
|
+
# core/range.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -28,12 +28,12 @@
|
|
28
28
|
class Range
|
29
29
|
#
|
30
30
|
# call-seq:
|
31
|
-
# range.fizzbuzz( reverse ) -> array
|
32
31
|
# range.fizzbuzz( reverse ) {|value| block } -> self
|
32
|
+
# range.fizzbuzz( reverse ) -> an Enumerator
|
33
33
|
#
|
34
|
-
# Returns either an
|
35
|
-
# then it will call the block once for each subsequent value for a given range,
|
36
|
-
# the value as a parameter to the block.
|
34
|
+
# Returns either an +Enumerator+ or accepts a block if such is given. When a block is
|
35
|
+
# given then it will call the block once for each subsequent value for a given range,
|
36
|
+
# passing the value as a parameter to the block.
|
37
37
|
#
|
38
38
|
# Additionally, if the value of +reverse+ is set to be +true+ then the results will
|
39
39
|
# be given in an <em>reverse order</em> whether in a resulting array or when passing
|
@@ -41,8 +41,8 @@ class Range
|
|
41
41
|
#
|
42
42
|
# Example:
|
43
43
|
#
|
44
|
-
# (1..15).fizzbuzz #=>
|
45
|
-
# (1..15).fizzbuzz(true) #=>
|
44
|
+
# (1..15).fizzbuzz #=> #<Enumerator: 1..15:fizzbuzz(false)>
|
45
|
+
# (1..15).fizzbuzz(true) #=> #<Enumerator: 1..15:fizzbuzz(true)>
|
46
46
|
#
|
47
47
|
# Example:
|
48
48
|
#
|
@@ -68,14 +68,12 @@ class Range
|
|
68
68
|
#
|
69
69
|
# See also: FizzBuzz::fizzbuzz, FizzBuzz#to_a, FizzBuzz#each and FizzBuzz#reverse_each
|
70
70
|
#
|
71
|
-
def fizzbuzz(reverse = false)
|
72
|
-
values = self.collect {|i| FizzBuzz[i] }.send(reverse ? :reverse : :entries)
|
73
|
-
|
71
|
+
def fizzbuzz(reverse = false, &block)
|
74
72
|
if block_given?
|
75
|
-
|
73
|
+
FizzBuzz.fizzbuzz(self.begin, self.end, reverse, &block)
|
76
74
|
self
|
77
75
|
else
|
78
|
-
|
76
|
+
enum_for(:fizzbuzz, reverse)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
end
|
data/lib/fizzbuzz/version.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# version.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -26,7 +26,7 @@ class FizzBuzz
|
|
26
26
|
#
|
27
27
|
# Current version of _FizzBuzz_.
|
28
28
|
#
|
29
|
-
VERSION = '0.0.
|
29
|
+
VERSION = '0.7.0'.freeze
|
30
30
|
end
|
31
31
|
|
32
32
|
# :enddoc:
|
data/ruby-fizzbuzz.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# ruby-fizzbuzz.gemspec
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -23,7 +23,8 @@
|
|
23
23
|
signing_key = File.expand_path('~/.gem/kwilczynski-private.pem')
|
24
24
|
|
25
25
|
Gem::Specification.new do |s|
|
26
|
-
s.name
|
26
|
+
s.name = 'ruby-fizzbuzz'
|
27
|
+
s.summary = 'Yet another FizzBuzz in Ruby'
|
27
28
|
|
28
29
|
s.description = <<-EOS
|
29
30
|
Yet another FizzBuzz in Ruby.
|
@@ -40,12 +41,10 @@ arbitrary large numeric values via the Bignum class.
|
|
40
41
|
s.author = 'Krzysztof Wilczynski'
|
41
42
|
s.email = 'krzysztof.wilczynski@linux.com'
|
42
43
|
s.homepage = 'http://about.me/kwilczynski'
|
44
|
+
s.has_rdoc = true
|
43
45
|
|
44
|
-
s.
|
45
|
-
s.rubygems_version
|
46
|
-
s.has_rdoc = true
|
47
|
-
|
48
|
-
s.summary = 'Yet another FizzBuzz in Ruby'
|
46
|
+
s.required_ruby_version = '>= 1.9.2'
|
47
|
+
s.rubygems_version = '~> 2.2.0'
|
49
48
|
|
50
49
|
s.files = Dir['ext/**/*.{c,h,rb}'] +
|
51
50
|
Dir['lib/**/*.rb'] +
|
@@ -59,11 +58,6 @@ arbitrary large numeric values via the Bignum class.
|
|
59
58
|
s.require_paths << 'lib'
|
60
59
|
s.extensions << 'ext/fizzbuzz/extconf.rb'
|
61
60
|
|
62
|
-
s.add_development_dependency 'rake', '~> 10.1', '>= 10.1.1'
|
63
|
-
s.add_development_dependency 'rdoc', '~> 4.1', '>= 4.1.1'
|
64
|
-
s.add_development_dependency 'test-unit', '~> 2.5', '>= 2.5.5'
|
65
|
-
s.add_development_dependency 'rake-compiler', '~> 0.9', '>= 0.9.2'
|
66
|
-
|
67
61
|
s.signing_key = signing_key if File.exists?(signing_key)
|
68
62
|
end
|
69
63
|
|
data/test/test_fizzbuzz.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# test_fizzbuzz.rb
|
7
7
|
#
|
8
|
-
# Copyright 2012-
|
8
|
+
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
9
|
#
|
10
10
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
11
|
# you may not use this file except in compliance with the License.
|
@@ -27,161 +27,225 @@ rescue LoadError
|
|
27
27
|
STDERR.puts 'The Coveralls gem is not installed, skipping ...'
|
28
28
|
end
|
29
29
|
|
30
|
-
gem 'test-unit', '>=
|
30
|
+
gem 'test-unit', '>= 3.0.0'
|
31
31
|
|
32
32
|
require 'test/unit'
|
33
33
|
require 'fizzbuzz'
|
34
34
|
|
35
|
-
DEFAULT_START = 1
|
36
|
-
DEFAULT_STOP = 15
|
37
|
-
DEFAULT_WORDS = ['Fizz', 'Buzz', 'FizzBuzz']
|
38
|
-
DEFAULT_EXPECTED = [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz']
|
39
|
-
|
40
|
-
DEFAULT_SINGLETON_METHODS = [:fizzbuzz, :is_fizz?, :is_buzz?, :is_fizzbuzz?]
|
41
|
-
DEFAULT_INSTANCE_METHODS = [:to_a, :each, :reverse_each]
|
42
|
-
|
43
|
-
DEFAULT_INSTANCE_METHODS_ADDED = [:fizz?, :buzz?, :fizzbuzz?]
|
44
|
-
|
45
35
|
class Fixnum
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
2 ** (bits - 1) - 1
|
50
|
-
end
|
36
|
+
def self.overflow_size_with_sign
|
37
|
+
bits = [''].pack('p').size * 8
|
38
|
+
2 ** (bits - 1) - 1
|
51
39
|
end
|
52
40
|
end
|
53
41
|
|
54
42
|
class FizzBuzzTest < Test::Unit::TestCase
|
55
43
|
def setup
|
56
|
-
@
|
44
|
+
@fixnum = 1
|
45
|
+
|
57
46
|
@bignum = 1_000_000_000_000
|
58
47
|
@large_bignum = 1_000_000_000_000_000
|
59
48
|
|
60
|
-
if Fixnum
|
49
|
+
if Fixnum.overflow_size_with_sign + 1 > 2147483647
|
61
50
|
@bignum = @bignum ** 2
|
62
51
|
@large_bignum = @large_bignum ** 2
|
63
52
|
end
|
64
|
-
end
|
65
53
|
|
66
|
-
|
67
|
-
assert(FB == FizzBuzz)
|
68
|
-
end
|
54
|
+
@words = %w(Fizz Buzz FizzBuzz).freeze
|
69
55
|
|
70
|
-
|
71
|
-
|
56
|
+
@expected = [
|
57
|
+
1, 2, 'Fizz',
|
58
|
+
4, 'Buzz', 'Fizz',
|
59
|
+
7, 8, 'Fizz',
|
60
|
+
'Buzz', 11, 'Fizz',
|
61
|
+
13, 14, 'FizzBuzz'
|
62
|
+
].freeze
|
72
63
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
assert(fb.class == FizzBuzz)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_fizzbuzz_instance_methods
|
84
|
-
fb = FizzBuzz.new(DEFAULT_START, DEFAULT_STOP)
|
64
|
+
@expected_bignum = [
|
65
|
+
@bignum + 1, 'Fizz', @bignum + 3,
|
66
|
+
@bignum + 4, 'FizzBuzz', @bignum + 6,
|
67
|
+
@bignum + 7, 'Fizz', @bignum + 9,
|
68
|
+
'Buzz', 'Fizz', @bignum + 12,
|
69
|
+
@bignum + 13, 'Fizz', 'Buzz'
|
70
|
+
]
|
85
71
|
|
86
|
-
|
87
|
-
DEFAULT_INSTANCE_METHODS.all? {|i| fb.respond_to?(i) }
|
88
|
-
end
|
72
|
+
@fizzbuzz = FizzBuzz.new(1, 15)
|
89
73
|
end
|
90
74
|
|
91
|
-
def
|
92
|
-
|
93
|
-
DEFAULT_INSTANCE_METHODS_ADDED.all? {|i| @integer.respond_to?(i) }
|
94
|
-
end
|
75
|
+
def test_fizzbuzz_alias
|
76
|
+
assert_same(FB, FizzBuzz)
|
95
77
|
end
|
96
78
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
79
|
+
def test_fizzbuzz_singleton_methods
|
80
|
+
[
|
81
|
+
:fizzbuzz,
|
82
|
+
:is_fizz?,
|
83
|
+
:is_buzz?,
|
84
|
+
:is_fizzbuzz?
|
85
|
+
].each {|i| assert_respond_to(FizzBuzz, i) }
|
100
86
|
end
|
101
87
|
|
102
|
-
def
|
103
|
-
|
104
|
-
assert_equal(15.buzz?, false)
|
88
|
+
def test_fizzbuzz_new_instance
|
89
|
+
assert(@fizzbuzz.class == FizzBuzz)
|
105
90
|
end
|
106
91
|
|
107
|
-
def
|
92
|
+
def test_fizzbuzz_instance_methods
|
93
|
+
[
|
94
|
+
:to_a,
|
95
|
+
:each,
|
96
|
+
:reverse_each,
|
97
|
+
:to_hash,
|
98
|
+
:as_json,
|
99
|
+
:to_json
|
100
|
+
].each {|i| assert_respond_to(@fizzbuzz, i) }
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_fixnum_integration
|
104
|
+
[
|
105
|
+
:fizz?,
|
106
|
+
:buzz?,
|
107
|
+
:fizzbuzz?
|
108
|
+
].each {|i| assert_respond_to(@fixnum, i) }
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_to_hash
|
112
|
+
obtained = @fizzbuzz.to_hash
|
113
|
+
assert({
|
114
|
+
'fizzbuzz' => {
|
115
|
+
'start' => 1,
|
116
|
+
'stop' => 15
|
117
|
+
}
|
118
|
+
} == obtained)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_as_json
|
122
|
+
obtained = @fizzbuzz.as_json
|
123
|
+
assert({
|
124
|
+
'json_class' => 'FizzBuzz',
|
125
|
+
'fizzbuzz' => {
|
126
|
+
'start' => 1,
|
127
|
+
'stop' => 15
|
128
|
+
}
|
129
|
+
} == obtained)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_to_json
|
133
|
+
obtained = @fizzbuzz.to_json
|
134
|
+
assert({
|
135
|
+
'json_class' => 'FizzBuzz',
|
136
|
+
'fizzbuzz' => {
|
137
|
+
'start' => 1,
|
138
|
+
'stop' => 15
|
139
|
+
}
|
140
|
+
}.to_json == obtained)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_singleton_from_json
|
144
|
+
# About JSON::parse, see:
|
145
|
+
# https://www.ruby-lang.org/en/news/2013/02/22/json-dos-cve-2013-0269/
|
146
|
+
obtained = @fizzbuzz.to_json
|
147
|
+
assert({
|
148
|
+
'fizzbuzz' => {
|
149
|
+
'start' => 1,
|
150
|
+
'stop' => 15
|
151
|
+
}
|
152
|
+
} == JSON.load(obtained).to_hash)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_fixnum_is_fizz
|
156
|
+
assert_true(3.fizz?)
|
157
|
+
assert_false(15.fizz?)
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_fixnum_is_buzz
|
161
|
+
assert_true(5.buzz?)
|
162
|
+
assert_false(15.buzz?)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_fixnum_is_fizzbuzz
|
108
166
|
assert_equal(15.fizzbuzz?, true)
|
109
|
-
|
110
|
-
|
167
|
+
assert_false(3.fizzbuzz?, false)
|
168
|
+
assert_false(5.fizzbuzz?, false)
|
111
169
|
end
|
112
170
|
|
113
171
|
def test_bignum_integration
|
114
|
-
|
115
|
-
|
116
|
-
|
172
|
+
[
|
173
|
+
:fizz?,
|
174
|
+
:buzz?,
|
175
|
+
:fizzbuzz?
|
176
|
+
].each {|i| assert_respond_to(@bignum, i) }
|
117
177
|
end
|
118
178
|
|
119
179
|
def test_bignum_is_fizz
|
120
|
-
|
121
|
-
|
180
|
+
assert_true((@bignum + 2).fizz?)
|
181
|
+
assert_false((@bignum + 15).fizz?)
|
122
182
|
end
|
123
183
|
|
124
184
|
def test_bignum_is_buzz
|
125
|
-
|
126
|
-
|
185
|
+
assert_true((@bignum + 15).buzz?)
|
186
|
+
assert_false((@bignum + 5).buzz?)
|
127
187
|
end
|
128
188
|
|
129
189
|
def test_bignum_is_fizzbuzz
|
130
|
-
|
131
|
-
|
132
|
-
|
190
|
+
assert_true((@bignum + 5).fizzbuzz?)
|
191
|
+
assert_false((@bignum + 2).fizzbuzz?)
|
192
|
+
assert_false((@bignum + 15).fizzbuzz?)
|
133
193
|
end
|
134
194
|
|
135
195
|
def test_array_integration
|
136
|
-
|
196
|
+
assert_respond_to([], :fizzbuzz)
|
137
197
|
end
|
138
198
|
|
139
199
|
def test_array_integration_fizzbuzz
|
140
|
-
|
141
|
-
|
200
|
+
obtained = Array(1..15).fizzbuzz
|
201
|
+
assert_kind_of(Array, obtained)
|
202
|
+
assert_equal(obtained, @expected)
|
142
203
|
end
|
143
204
|
|
144
205
|
def test_array_integration_fizzbuzz_reverse
|
145
|
-
|
146
|
-
|
206
|
+
obtained = Array(1..15).fizzbuzz(true)
|
207
|
+
assert_kind_of(Array, obtained)
|
208
|
+
assert_equal(obtained, @expected.reverse)
|
147
209
|
end
|
148
210
|
|
149
211
|
def test_array_integration_fizzbuzz_block
|
150
|
-
|
151
|
-
|
152
|
-
assert_equal(
|
212
|
+
obtained = []
|
213
|
+
Array(1..15).fizzbuzz {|i| obtained << i }
|
214
|
+
assert_equal(obtained, @expected)
|
153
215
|
end
|
154
216
|
|
155
217
|
def test_array_integration_fizzbuzz_block_reverse
|
156
|
-
|
157
|
-
|
158
|
-
assert_equal(
|
218
|
+
obtained = []
|
219
|
+
Array(1..15).fizzbuzz(true) {|i| obtained << i }
|
220
|
+
assert_equal(obtained, @expected.reverse)
|
159
221
|
end
|
160
222
|
|
161
223
|
def test_range_integration
|
162
|
-
|
224
|
+
assert_respond_to((0..0), :fizzbuzz)
|
163
225
|
end
|
164
226
|
|
165
227
|
def test_range_integration_fizzbuzz
|
166
|
-
|
167
|
-
|
228
|
+
obtained = (1..15).fizzbuzz
|
229
|
+
assert_kind_of(Enumerator, obtained)
|
230
|
+
assert_equal(obtained.to_a, @expected)
|
168
231
|
end
|
169
232
|
|
170
233
|
def test_range_integration_fizzbuzz_reverse
|
171
|
-
|
172
|
-
|
234
|
+
obtained = (1..15).fizzbuzz(true)
|
235
|
+
assert_kind_of(Enumerator, obtained)
|
236
|
+
assert_equal(obtained.to_a, @expected.reverse)
|
173
237
|
end
|
174
238
|
|
175
239
|
def test_range_integration_fizzbuzz_block
|
176
|
-
|
177
|
-
(
|
178
|
-
assert_equal(
|
240
|
+
obtained = []
|
241
|
+
(1..15).fizzbuzz {|i| obtained << i }
|
242
|
+
assert_equal(obtained, @expected)
|
179
243
|
end
|
180
244
|
|
181
245
|
def test_range_integration_fizzbuzz_block_reverse
|
182
|
-
|
183
|
-
(
|
184
|
-
assert_equal(
|
246
|
+
obtained = []
|
247
|
+
(1..15).fizzbuzz(true) {|i| obtained << i }
|
248
|
+
assert_equal(obtained, @expected.reverse)
|
185
249
|
end
|
186
250
|
|
187
251
|
def test_singleton_fizzbuzz_incorrect_range_error
|
@@ -196,201 +260,263 @@ class FizzBuzzTest < Test::Unit::TestCase
|
|
196
260
|
end
|
197
261
|
end
|
198
262
|
|
199
|
-
def
|
200
|
-
|
201
|
-
|
202
|
-
assert_equal(
|
263
|
+
def test_singleton_fizzbuzz_fixnum
|
264
|
+
obtained = FizzBuzz.fizzbuzz(15, 15)
|
265
|
+
assert_kind_of(Array, obtained)
|
266
|
+
assert_equal(obtained, ['FizzBuzz'])
|
203
267
|
end
|
204
268
|
|
205
269
|
def test_singleton_fizzbuzz_bignum
|
206
|
-
|
207
|
-
|
208
|
-
assert_equal(
|
270
|
+
obtained = FizzBuzz.fizzbuzz(@bignum + 5, @bignum + 5)
|
271
|
+
assert_kind_of(Array, obtained)
|
272
|
+
assert_equal(obtained, ['FizzBuzz'])
|
209
273
|
end
|
210
274
|
|
211
275
|
def test_singleton_fizzbuzz_large_bignum
|
212
|
-
|
213
|
-
|
214
|
-
assert_equal(
|
276
|
+
obtained = FizzBuzz.fizzbuzz(@large_bignum + 5, @large_bignum + 5)
|
277
|
+
assert_kind_of(Array, obtained)
|
278
|
+
assert_equal(obtained, ['FizzBuzz'])
|
215
279
|
end
|
216
280
|
|
217
281
|
def test_singleton_fizzbuzz_array
|
218
|
-
obtained = FizzBuzz.fizzbuzz(
|
219
|
-
|
282
|
+
obtained = FizzBuzz.fizzbuzz(1, 15)
|
283
|
+
assert_kind_of(Array, obtained)
|
284
|
+
assert_equal(obtained, @expected)
|
220
285
|
end
|
221
286
|
|
222
287
|
def test_singleton_fizzbuzz_array_reverse
|
223
|
-
obtained = FizzBuzz.fizzbuzz(
|
224
|
-
|
288
|
+
obtained = FizzBuzz.fizzbuzz(1, 15, true)
|
289
|
+
assert_kind_of(Array, obtained)
|
290
|
+
assert_equal(obtained, @expected.reverse)
|
225
291
|
end
|
226
292
|
|
227
293
|
def test_singleton_fizzbuzz_block
|
228
|
-
|
229
|
-
FizzBuzz.fizzbuzz(
|
230
|
-
assert_equal(
|
294
|
+
obtained = []
|
295
|
+
FizzBuzz.fizzbuzz(1, 15) {|i| obtained << i }
|
296
|
+
assert_equal(obtained, @expected)
|
231
297
|
end
|
232
298
|
|
233
299
|
def test_singleton_fizzbuzz_block_reverse
|
234
|
-
|
235
|
-
FizzBuzz.fizzbuzz(
|
236
|
-
assert_equal(
|
300
|
+
obtained = []
|
301
|
+
FizzBuzz.fizzbuzz(1, 15, true) {|i| obtained << i }
|
302
|
+
assert_equal(obtained, @expected.reverse)
|
237
303
|
end
|
238
304
|
|
239
|
-
def
|
240
|
-
|
241
|
-
obtained_buzz = FizzBuzz[5]
|
242
|
-
obtained_fizzbuzz = FizzBuzz[15]
|
305
|
+
def test_singleton_squre_fixnum
|
306
|
+
obtained = []
|
243
307
|
|
244
|
-
obtained
|
308
|
+
obtained << FizzBuzz[3]
|
309
|
+
obtained << FizzBuzz[5]
|
310
|
+
obtained << FizzBuzz[15]
|
245
311
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
312
|
+
assert_kind_of(Fixnum, FizzBuzz[0])
|
313
|
+
|
314
|
+
obtained.each_with_index do |v,i|
|
315
|
+
assert_kind_of(String, v)
|
316
|
+
assert_equal(obtained[i], @words[i])
|
251
317
|
end
|
252
318
|
end
|
253
319
|
|
254
320
|
def test_singleton_squre_bignum
|
255
|
-
|
256
|
-
|
257
|
-
|
321
|
+
obtained = []
|
322
|
+
|
323
|
+
obtained << FizzBuzz[@bignum + 2]
|
324
|
+
obtained << FizzBuzz[@bignum + 15]
|
325
|
+
obtained << FizzBuzz[@bignum + 5]
|
258
326
|
|
259
|
-
|
327
|
+
assert_kind_of(Bignum, FizzBuzz[@bignum + 3])
|
260
328
|
|
261
|
-
|
262
|
-
|
263
|
-
obtained
|
264
|
-
v.is_a?(String) && obtained[i] == DEFAULT_WORDS[i]
|
265
|
-
end
|
329
|
+
obtained.each_with_index do |v,i|
|
330
|
+
assert_kind_of(String, v)
|
331
|
+
assert_equal(obtained[i], @words[i])
|
266
332
|
end
|
267
333
|
end
|
268
334
|
|
269
335
|
def test_singleton_squre_large_bignum
|
270
|
-
|
271
|
-
obtained_buzz = FizzBuzz[@large_bignum + 15]
|
272
|
-
obtained_fizzbuzz = FizzBuzz[@large_bignum + 5]
|
336
|
+
obtained = []
|
273
337
|
|
274
|
-
obtained
|
338
|
+
obtained << FizzBuzz[@large_bignum + 2]
|
339
|
+
obtained << FizzBuzz[@large_bignum + 15]
|
340
|
+
obtained << FizzBuzz[@large_bignum + 5]
|
275
341
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
342
|
+
assert_kind_of(Bignum, FizzBuzz[@large_bignum + 3])
|
343
|
+
|
344
|
+
obtained.each_with_index do |v,i|
|
345
|
+
assert_kind_of(String, v)
|
346
|
+
assert_equal(obtained[i], @words[i])
|
281
347
|
end
|
282
348
|
end
|
283
349
|
|
284
350
|
def test_singleton_is_fizz
|
285
|
-
|
286
|
-
|
351
|
+
assert_true(FizzBuzz.is_fizz?(3))
|
352
|
+
assert_false(FizzBuzz.is_fizz?(15))
|
287
353
|
end
|
288
354
|
|
289
355
|
def test_singleton_is_buzz
|
290
|
-
|
291
|
-
|
356
|
+
assert_true(FizzBuzz.is_buzz?(5))
|
357
|
+
assert_false(FizzBuzz.is_buzz?(15))
|
292
358
|
end
|
293
359
|
|
294
360
|
def test_singleton_is_fizzbuzz
|
295
|
-
|
296
|
-
|
297
|
-
|
361
|
+
assert_true(FizzBuzz.is_fizzbuzz?(15))
|
362
|
+
assert_false(FizzBuzz.is_fizzbuzz?(3))
|
363
|
+
assert_false(FizzBuzz.is_fizzbuzz?(5))
|
298
364
|
end
|
299
365
|
|
300
366
|
def test_fizzbuzz_for_0
|
301
367
|
obtained_square = FizzBuzz[0]
|
302
368
|
obtained_is_fizzbuzz = FizzBuzz.is_fizzbuzz?(0)
|
303
369
|
|
304
|
-
|
305
|
-
|
370
|
+
assert_kind_of(Fixnum, obtained_square)
|
371
|
+
assert_equal(obtained_square, 0)
|
372
|
+
assert_false(obtained_is_fizzbuzz)
|
306
373
|
end
|
307
374
|
|
308
|
-
def
|
309
|
-
|
310
|
-
|
375
|
+
def test_fizzbuzz_for_negative_fixnum
|
376
|
+
obtained_square = FizzBuzz[-1]
|
377
|
+
obtained_is_fizzbuzz = FizzBuzz.is_fizzbuzz?(-1)
|
378
|
+
|
379
|
+
assert_kind_of(Fixnum, obtained_square)
|
380
|
+
assert_equal(obtained_square, -1)
|
381
|
+
assert_false(obtained_is_fizzbuzz)
|
311
382
|
end
|
312
383
|
|
313
|
-
def
|
314
|
-
|
384
|
+
def test_to_a_fixnum
|
385
|
+
obtained = @fizzbuzz.to_a
|
315
386
|
|
316
|
-
|
317
|
-
|
387
|
+
assert_kind_of(Array, obtained)
|
388
|
+
assert_equal(obtained, @expected)
|
389
|
+
end
|
318
390
|
|
319
|
-
|
391
|
+
def test_each_fixnum
|
392
|
+
obtained = []
|
393
|
+
@fizzbuzz.each {|i| obtained << i }
|
394
|
+
assert_equal(obtained, @expected)
|
320
395
|
end
|
321
396
|
|
322
|
-
def
|
323
|
-
|
397
|
+
def test_reverse_each_fixnum
|
398
|
+
obtained = []
|
399
|
+
@fizzbuzz.reverse_each {|i| obtained << i }
|
400
|
+
assert_equal(obtained, @expected.reverse)
|
401
|
+
end
|
324
402
|
|
325
|
-
|
326
|
-
|
403
|
+
def test_to_a_bignum
|
404
|
+
@fizzbuzz = FizzBuzz.new(@bignum + 1, @bignum + 15)
|
405
|
+
obtained = @fizzbuzz.to_a
|
327
406
|
|
328
|
-
|
407
|
+
assert_kind_of(Array, obtained)
|
408
|
+
assert_equal(obtained, @expected_bignum)
|
329
409
|
end
|
330
410
|
|
331
|
-
def
|
332
|
-
|
333
|
-
|
411
|
+
def test_each_bignum
|
412
|
+
@fizzbuzz = FizzBuzz.new(@bignum + 1, @bignum + 15)
|
413
|
+
|
414
|
+
obtained = []
|
415
|
+
@fizzbuzz.each {|i| obtained << i }
|
416
|
+
|
417
|
+
assert_equal(obtained, @expected_bignum)
|
418
|
+
end
|
419
|
+
|
420
|
+
def test_reverse_each_bignum
|
421
|
+
@fizzbuzz = FizzBuzz.new(@bignum + 1, @bignum + 15)
|
422
|
+
|
423
|
+
obtained = []
|
424
|
+
@fizzbuzz.reverse_each {|i| obtained << i }
|
425
|
+
|
426
|
+
assert_equal(obtained, @expected_bignum.reverse)
|
427
|
+
end
|
428
|
+
|
429
|
+
def test_for_fizzbuzz_fixnum
|
430
|
+
obtained = @fizzbuzz.to_a
|
431
|
+
|
432
|
+
assert_kind_of(Array, obtained)
|
433
|
+
assert_equal(obtained[14], 'FizzBuzz')
|
334
434
|
end
|
335
435
|
|
336
436
|
def test_for_fizzbuzz_bignum
|
337
|
-
|
338
|
-
|
437
|
+
@fizzbuzz = FizzBuzz.new(@bignum + 5, @bignum + 5)
|
438
|
+
|
439
|
+
obtained = @fizzbuzz.to_a
|
440
|
+
|
441
|
+
assert_kind_of(Array, obtained)
|
442
|
+
assert_equal(obtained[0], 'FizzBuzz')
|
339
443
|
end
|
340
444
|
|
341
445
|
def test_for_fizzbuzz_large_bignum
|
342
|
-
|
343
|
-
|
446
|
+
@fizzbuzz = FizzBuzz.new(@large_bignum + 5, @large_bignum + 5)
|
447
|
+
|
448
|
+
obtained = @fizzbuzz.to_a
|
449
|
+
|
450
|
+
assert_kind_of(Array, obtained)
|
451
|
+
assert_equal(obtained[0], 'FizzBuzz')
|
344
452
|
end
|
345
453
|
|
346
|
-
def
|
347
|
-
|
454
|
+
def test_correct_start_fixnum
|
455
|
+
assert_kind_of(Fixnum, @fizzbuzz.start)
|
456
|
+
assert_equal(@fizzbuzz.start, 1)
|
457
|
+
|
458
|
+
@fizzbuzz.start = 2
|
348
459
|
|
349
|
-
|
350
|
-
|
351
|
-
assert(fb.start.is_a?(Integer) && fb.start == 2)
|
460
|
+
assert_kind_of(Fixnum, @fizzbuzz.start)
|
461
|
+
assert_equal(@fizzbuzz.start, 2)
|
352
462
|
end
|
353
463
|
|
354
464
|
def test_correct_start_bignum
|
355
|
-
|
465
|
+
@fizzbuzz = FizzBuzz.new(@bignum, @bignum)
|
356
466
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
467
|
+
assert_kind_of(Bignum, @fizzbuzz.start)
|
468
|
+
assert_equal(@fizzbuzz.start, @bignum)
|
469
|
+
|
470
|
+
@fizzbuzz.start = @bignum - 5
|
471
|
+
|
472
|
+
assert_kind_of(Bignum, @fizzbuzz.start)
|
473
|
+
assert_equal(@fizzbuzz.start, @bignum - 5)
|
362
474
|
end
|
363
475
|
|
364
476
|
def test_correct_start_large_bignum
|
365
|
-
|
477
|
+
@fizzbuzz = FizzBuzz.new(@large_bignum, @large_bignum)
|
478
|
+
|
479
|
+
assert_kind_of(Bignum, @fizzbuzz.start)
|
480
|
+
assert_equal(@fizzbuzz.start, @large_bignum)
|
366
481
|
|
367
|
-
|
368
|
-
|
369
|
-
|
482
|
+
@fizzbuzz.start = @large_bignum - 5
|
483
|
+
|
484
|
+
assert_kind_of(Bignum, @fizzbuzz.start)
|
485
|
+
assert_equal(@fizzbuzz.start, @large_bignum - 5)
|
370
486
|
end
|
371
487
|
|
372
|
-
def
|
373
|
-
|
488
|
+
def test_correct_stop_fixnum
|
489
|
+
assert_kind_of(Fixnum, @fizzbuzz.stop)
|
490
|
+
assert_equal(@fizzbuzz.stop, 15)
|
491
|
+
|
492
|
+
@fizzbuzz.stop = 5
|
374
493
|
|
375
|
-
|
376
|
-
|
377
|
-
assert(fb.stop.is_a?(Integer) && fb.stop == 5)
|
494
|
+
assert_kind_of(Fixnum, @fizzbuzz.stop)
|
495
|
+
assert_equal(@fizzbuzz.stop, 5)
|
378
496
|
end
|
379
497
|
|
380
498
|
def test_correct_stop_bignum
|
381
|
-
|
499
|
+
@fizzbuzz = FizzBuzz.new(@bignum, @bignum)
|
382
500
|
|
383
|
-
|
384
|
-
|
385
|
-
|
501
|
+
assert_kind_of(Bignum, @fizzbuzz.stop)
|
502
|
+
assert_equal(@fizzbuzz.stop, @bignum)
|
503
|
+
|
504
|
+
@fizzbuzz.stop = @bignum + 5
|
505
|
+
|
506
|
+
assert_kind_of(Bignum, @fizzbuzz.stop)
|
507
|
+
assert_equal(@fizzbuzz.stop, @bignum + 5)
|
386
508
|
end
|
387
509
|
|
388
510
|
def test_correct_stop_large_bignum
|
389
|
-
|
511
|
+
@fizzbuzz = FizzBuzz.new(@large_bignum, @large_bignum)
|
512
|
+
|
513
|
+
assert_kind_of(Bignum, @fizzbuzz.stop)
|
514
|
+
assert_equal(@fizzbuzz.stop, @large_bignum)
|
515
|
+
|
516
|
+
@fizzbuzz.stop = @large_bignum + 5
|
390
517
|
|
391
|
-
|
392
|
-
|
393
|
-
assert(fb.stop.is_a?(Bignum) && fb.stop == (@large_bignum + 5))
|
518
|
+
assert_kind_of(Bignum, @fizzbuzz.stop)
|
519
|
+
assert_equal(@fizzbuzz.stop, @large_bignum + 5)
|
394
520
|
end
|
395
521
|
|
396
522
|
def test_missing_arguments
|
@@ -405,6 +531,12 @@ class FizzBuzzTest < Test::Unit::TestCase
|
|
405
531
|
end
|
406
532
|
end
|
407
533
|
|
534
|
+
def test_arguments_type_error_message
|
535
|
+
FizzBuzz['']
|
536
|
+
rescue FizzBuzz::TypeError => error
|
537
|
+
assert_equal(error.message, 'must be a Fixnum or Bignum type')
|
538
|
+
end
|
539
|
+
|
408
540
|
def test_arguments_type_error_nils
|
409
541
|
assert_raise FizzBuzz::TypeError do
|
410
542
|
FizzBuzz.new(nil, nil)
|
@@ -419,94 +551,87 @@ class FizzBuzzTest < Test::Unit::TestCase
|
|
419
551
|
|
420
552
|
def test_start_type_error
|
421
553
|
assert_raise FizzBuzz::TypeError do
|
422
|
-
|
423
|
-
fb.start = ''
|
554
|
+
@fizzbuzz.start = ''
|
424
555
|
end
|
425
556
|
end
|
426
557
|
|
427
558
|
def test_stop_type_error
|
428
559
|
assert_raise FizzBuzz::TypeError do
|
429
|
-
|
430
|
-
fb.stop = ''
|
560
|
+
@fizzbuzz.stop = ''
|
431
561
|
end
|
432
562
|
end
|
433
563
|
|
434
564
|
def test_correct_start_stop
|
435
|
-
|
565
|
+
@fizzbuzz.start = 2
|
566
|
+
@fizzbuzz.stop = 3
|
567
|
+
|
568
|
+
assert_kind_of(Fixnum, @fizzbuzz.start)
|
569
|
+
assert_kind_of(Fixnum, @fizzbuzz.stop)
|
570
|
+
assert_equal(@fizzbuzz.start, 2)
|
571
|
+
assert_equal(@fizzbuzz.stop, 3)
|
572
|
+
end
|
436
573
|
|
437
|
-
|
438
|
-
|
574
|
+
def test_fizzbuzz_error
|
575
|
+
message = 'The quick brown fox jumps over the lazy dog'
|
576
|
+
error = FizzBuzz::Error.new(message)
|
439
577
|
|
440
|
-
|
441
|
-
|
578
|
+
assert_respond_to(error, :start)
|
579
|
+
assert_respond_to(error, :stop)
|
580
|
+
assert_equal(error.message, message)
|
581
|
+
assert_nil(error.start)
|
582
|
+
assert_nil(error.stop)
|
442
583
|
end
|
443
584
|
|
444
585
|
def test_start_range_error
|
445
|
-
fb = FizzBuzz.new(DEFAULT_START, DEFAULT_STOP)
|
446
|
-
|
447
586
|
assert_raise FizzBuzz::RangeError do
|
448
|
-
|
587
|
+
@fizzbuzz.start = 16
|
449
588
|
end
|
450
589
|
end
|
451
590
|
|
452
591
|
def test_stop_range_error
|
453
|
-
fb = FizzBuzz.new(DEFAULT_START, DEFAULT_STOP)
|
454
|
-
|
455
592
|
assert_raise FizzBuzz::RangeError do
|
456
|
-
|
593
|
+
@fizzbuzz.stop = -1
|
457
594
|
end
|
458
595
|
end
|
459
596
|
|
460
|
-
def
|
597
|
+
def test_for_not_raising_range_error
|
461
598
|
assert_nothing_raised do
|
462
|
-
FizzBuzz.new(
|
463
|
-
FizzBuzz.new(-@large_bignum,
|
599
|
+
FizzBuzz.new(1, @bignum ** 2)
|
600
|
+
FizzBuzz.new(-@large_bignum, 15)
|
464
601
|
end
|
465
602
|
end
|
466
603
|
|
467
604
|
def test_error_attributes_not_nil
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
rescue FizzBuzz::RangeError => error
|
474
|
-
assert_equal(error.start, 1)
|
475
|
-
assert_equal(error.stop, 0)
|
476
|
-
end
|
605
|
+
@fizzbuzz.start = 1
|
606
|
+
@fizzbuzz.stop = 0
|
607
|
+
rescue FizzBuzz::RangeError => error
|
608
|
+
assert_equal(error.start, 1)
|
609
|
+
assert_equal(error.stop, 0)
|
477
610
|
end
|
478
611
|
|
479
612
|
def test_error_attributes_nil
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
assert_equal(error.stop, nil)
|
485
|
-
end
|
613
|
+
FizzBuzz.new('', '')
|
614
|
+
rescue FizzBuzz::TypeError => error
|
615
|
+
assert_nil(error.start)
|
616
|
+
assert_nil(error.stop)
|
486
617
|
end
|
487
618
|
|
488
619
|
def test_start_type_error_message
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
assert_equal(error.message, 'must be an Integer or Bignum type for start')
|
493
|
-
end
|
620
|
+
FizzBuzz.new('', 15)
|
621
|
+
rescue FizzBuzz::TypeError => error
|
622
|
+
assert_equal(error.message, 'must be a Fixnum or Bignum type for start')
|
494
623
|
end
|
495
624
|
|
496
625
|
def test_stop_type_error_message
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
assert_equal(error.message, 'must be an Integer or Bignum type for stop')
|
501
|
-
end
|
626
|
+
FizzBuzz.new(1, '')
|
627
|
+
rescue FizzBuzz::TypeError => error
|
628
|
+
assert_equal(error.message, 'must be a Fixnum or Bignum type for stop')
|
502
629
|
end
|
503
630
|
|
504
631
|
def test_range_error_message
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
assert_equal(error.message, 'start value is higher than stop value')
|
509
|
-
end
|
632
|
+
FizzBuzz.new(15, 1)
|
633
|
+
rescue FizzBuzz::RangeError => error
|
634
|
+
assert_equal(error.message, 'start value is higher than stop value')
|
510
635
|
end
|
511
636
|
end
|
512
637
|
|