ruby-fizzbuzz 0.7.0 → 0.8.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 -5
- checksums.yaml.gz.sig +5 -0
- data.tar.gz.sig +0 -0
- data/AUTHORS +1 -1
- data/CHANGELOG.md +175 -0
- data/COPYRIGHT +1 -1
- data/README.md +46 -0
- data/VERSION +1 -1
- data/bin/fizzbuzz +33 -61
- data/ext/fizzbuzz/common.h +39 -29
- data/ext/fizzbuzz/extconf.rb +24 -43
- data/ext/fizzbuzz/fizzbuzz.c +100 -117
- data/ext/fizzbuzz/fizzbuzz.h +60 -118
- data/kwilczynski-public.pem +25 -0
- data/lib/fizzbuzz.rb +106 -40
- data/lib/fizzbuzz/core/array.rb +9 -36
- data/lib/fizzbuzz/core/bignum.rb +9 -38
- data/lib/fizzbuzz/core/integer.rb +9 -38
- data/lib/fizzbuzz/core/range.rb +2 -31
- data/lib/fizzbuzz/version.rb +2 -29
- metadata +51 -24
- metadata.gz.sig +0 -0
- data/CHANGES +0 -84
- data/CHANGES.rdoc +0 -84
- data/README +0 -5
- data/README.rdoc +0 -12
- data/Rakefile +0 -97
- data/TODO +0 -16
- data/benchmark/benchmark_fizzbuzz.rb +0 -107
- data/ruby-fizzbuzz.gemspec +0 -65
- data/test/test_fizzbuzz.rb +0 -639
data/CHANGES.rdoc
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
fizzbuzz (0.7.0)
|
2
|
-
|
3
|
-
* Added to_hash, as_json, to_json and from_json (singleton) to the FizzBuzz class.
|
4
|
-
* Add rudimentary Vagrantfile that can be used to build a development environment.
|
5
|
-
* Re-factored fizzbuzz (singleton) from the FizzBuzz class to speed it up.
|
6
|
-
* No longer use of Enumerable#entries in the Array integration, achieving better performance.
|
7
|
-
* Correctly return Enumerator when integrating with the Range class.
|
8
|
-
* Updated Rakefile to no longer run test before benchmark.
|
9
|
-
* Fixed benchmarks concerning Array and Range integration.
|
10
|
-
* Retired testing with Ruby 1.9.2 and 2.1.0, and added 2.1.5 on Travis CI.
|
11
|
-
* Fixed Travis CI build against Rubinius.
|
12
|
-
* Re-factored tests to utilise modern version of the "test-unit" Ruby gem.
|
13
|
-
* Fixed build to make it work with C++ compilers.
|
14
|
-
* Added the Guard Ruby gem for convenience, with an appropriate Guardfile.
|
15
|
-
* Added LLVM (clang) compiler to build with to Travis CI.
|
16
|
-
* Fixed version number to comply with Semantic Versioning 2 (http://semver.org/).
|
17
|
-
* Re-factored and cleaned up small portions of code and documentation.
|
18
|
-
* Removed BitDeli badge.
|
19
|
-
|
20
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Mon, 15 Dec 2014 00:27:26 +0000
|
21
|
-
|
22
|
-
fizzbuzz (0.0.6)
|
23
|
-
|
24
|
-
* Fixed issue reported by LLVM (clang).
|
25
|
-
* Updated development dependencies.
|
26
|
-
* Added Ruby 2.1.0 to Travis CI.
|
27
|
-
* Added BitDeli and Gemnasium integration.
|
28
|
-
* Re-factored and cleaned up small portions of code.
|
29
|
-
* Made Rake "test" task to be the default tasks.
|
30
|
-
* Updated the ".gitignore" file to cover Bundler, rbenv, etc.
|
31
|
-
|
32
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Sun, 23 Feb 2014 13:52:08 +0000
|
33
|
-
|
34
|
-
fizzbuzz (0.0.5)
|
35
|
-
|
36
|
-
* Added integration with Array and Range types.
|
37
|
-
* Added simple benchmark.
|
38
|
-
|
39
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Tue, 26 Nov 2013 12:40:34 +0000
|
40
|
-
|
41
|
-
fizzbuzz (0.0.4)
|
42
|
-
|
43
|
-
* Retired support for Ruby 1.8.x (no support for MRI, Ruby Enterprise Edition and Rubinius).
|
44
|
-
* Added Coveralls and Code Climate integration (and hence improved code test coverage).
|
45
|
-
* Improved error handling and made code more resilient to errors.
|
46
|
-
* Fixed formatting and white spaces.
|
47
|
-
|
48
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Mon, 18 Nov 2013 11:22:26 +0000
|
49
|
-
|
50
|
-
fizzbuzz (0.0.3)
|
51
|
-
|
52
|
-
* Added custom exceptions and improved error handling.
|
53
|
-
* Added more variety of Rubies on which tests are being run with Travis CI.
|
54
|
-
* Added project to Rubygems (http://rubygems.org) so it can be installed
|
55
|
-
with just "gem install ruby-fizzbuzz" command.
|
56
|
-
* Renamed project from "fizzbuzz" to "ruby-fizzbuzz" to avoid clashes with
|
57
|
-
other Ruby gems hosted on Rubygems web site.
|
58
|
-
* Made "mkmf" in extconf.rb more user-friendly (it now reports missing
|
59
|
-
build-time dependencies better).
|
60
|
-
* Split Ruby gem specification (or gemspec if you wish) away from Rakefile
|
61
|
-
into its own file (namely ruby-fizzbuzz.gemspec).
|
62
|
-
* Improved documentation and removed bunch of small code smells.
|
63
|
-
|
64
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Sat, 31 Aug 2013 17:54:54 +0000
|
65
|
-
|
66
|
-
fizzbuzz (0.0.2)
|
67
|
-
|
68
|
-
* Added is_fizz?, is_buzz? and is_fizzbuzz? singleton methods to FizzBuzz class.
|
69
|
-
* Added fizz?, buzz? and fizzbuzz? methods to the Integer class via a monkey-patch
|
70
|
-
for convenience.
|
71
|
-
* Changed behaviour of the FizzBuzz#[] singleton method, so it will yield a FizzBuzz
|
72
|
-
result for a given arbitrary Integer value.
|
73
|
-
* Re-factored code to make it cleaner, and added more tests and improved coverage.
|
74
|
-
* Re-factored FizzBuzz so it now does not assume that we always want to calculate
|
75
|
-
results from 1 to n -- it is now possible to calculate FizzBuzz results for given
|
76
|
-
n, m values, where n denotes start and m denotes stop value.
|
77
|
-
|
78
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Sat, 29 Sep 2012 14:53:35 +0100
|
79
|
-
|
80
|
-
fizzbuzz (0.0.1)
|
81
|
-
|
82
|
-
* First version.
|
83
|
-
|
84
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Thu, 27 Sep 2012 12:54:45 +0200
|
data/README
DELETED
data/README.rdoc
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
Yet another FizzBuzz in Ruby. Provides simple and fast solution
|
2
|
-
to a popular FizzBuzz problem for Ruby.
|
3
|
-
|
4
|
-
Written in C as an example of using Ruby's C API - with the support
|
5
|
-
for arbitrary large numeric values via the Bignum class.
|
6
|
-
|
7
|
-
{<img src="https://travis-ci.org/kwilczynski/ruby-fizzbuzz.png?branch=master" alt="Build Status"/>}[https://travis-ci.org/kwilczynski/ruby-fizzbuzz]
|
8
|
-
{<img src="http://inch-ci.org/github/kwilczynski/ruby-fizzbuzz.svg?branch=master" alt="Documentation Status" />}[http://inch-ci.org/github/kwilczynski/ruby-fizzbuzz]
|
9
|
-
{<img src="https://badge.fury.io/rb/ruby-fizzbuzz.png" alt="Gem Version" />}[http://badge.fury.io/rb/ruby-fizzbuzz]
|
10
|
-
{<img src="https://coveralls.io/repos/kwilczynski/ruby-fizzbuzz/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/kwilczynski/ruby-fizzbuzz?branch=master]
|
11
|
-
{<img src="https://codeclimate.com/github/kwilczynski/ruby-fizzbuzz.png" alt="Code Quality" />}[https://codeclimate.com/github/kwilczynski/ruby-fizzbuzz]
|
12
|
-
{<img src="https://gemnasium.com/kwilczynski/ruby-fizzbuzz.png" alt="Dependency Status" />}[https://gemnasium.com/kwilczynski/ruby-fizzbuzz]
|
data/Rakefile
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
# :enddoc:
|
4
|
-
|
5
|
-
#
|
6
|
-
# Rakefile
|
7
|
-
#
|
8
|
-
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
#
|
22
|
-
|
23
|
-
gem 'rdoc', '>= 4.1.1'
|
24
|
-
|
25
|
-
begin
|
26
|
-
require 'rake'
|
27
|
-
require 'rdoc/task'
|
28
|
-
require 'rake/testtask'
|
29
|
-
require 'rake/extensiontask'
|
30
|
-
rescue LoadError
|
31
|
-
require 'rubygems'
|
32
|
-
require 'rake'
|
33
|
-
require 'rdoc/task'
|
34
|
-
require 'rake/testtask'
|
35
|
-
require 'rake/extensiontask'
|
36
|
-
end
|
37
|
-
|
38
|
-
CLEAN.include '*{.h,.o,.log,.so}', 'ext/**/*{.o,.log,.so}', 'Makefile', 'ext/**/Makefile'
|
39
|
-
CLOBBER.include 'lib/**/*.so', 'doc/**/*'
|
40
|
-
|
41
|
-
gem = eval File.read('ruby-fizzbuzz.gemspec')
|
42
|
-
|
43
|
-
RDoc::Task.new do |d|
|
44
|
-
files = %w(AUTHORS CHANGES.rdoc COPYRIGHT LICENSE README.rdoc TODO)
|
45
|
-
|
46
|
-
d.title = 'Yet another FizzBuzz in Ruby'
|
47
|
-
d.main = 'README.rdoc'
|
48
|
-
|
49
|
-
d.rdoc_dir = 'doc/rdoc'
|
50
|
-
|
51
|
-
d.rdoc_files.include 'ext/**/*.{c,h}', 'lib/**/*.rb'
|
52
|
-
d.rdoc_files.include.add(files)
|
53
|
-
|
54
|
-
d.options << '--line-numbers'
|
55
|
-
end
|
56
|
-
|
57
|
-
Rake::TestTask.new do |t|
|
58
|
-
t.verbose = true
|
59
|
-
t.warning = true
|
60
|
-
t.test_files = Dir['test/**/test_*']
|
61
|
-
end
|
62
|
-
|
63
|
-
Gem::PackageTask.new(gem) do |p|
|
64
|
-
p.need_zip = true
|
65
|
-
p.need_tar = true
|
66
|
-
end
|
67
|
-
|
68
|
-
Rake::ExtensionTask.new('fizzbuzz', gem) do |e|
|
69
|
-
e.ext_dir = 'ext/fizzbuzz'
|
70
|
-
e.lib_dir = 'lib/fizzbuzz'
|
71
|
-
end
|
72
|
-
|
73
|
-
desc 'Run benchmarks'
|
74
|
-
task :benchmark, [:first] do |t,argument|
|
75
|
-
glob = File.expand_path("../benchmark/*.rb", __FILE__)
|
76
|
-
Dir[glob].each do |f|
|
77
|
-
process = ['ruby', f]
|
78
|
-
process << argument[:first] if argument[:first]
|
79
|
-
|
80
|
-
STDOUT.sync = true
|
81
|
-
STDERR.sync = true
|
82
|
-
|
83
|
-
IO.popen(process) do |stream|
|
84
|
-
stream.each {|line| puts line }
|
85
|
-
end
|
86
|
-
|
87
|
-
Process.waitpid rescue Errno::ECHILD
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
Rake::Task[:test].prerequisites << :clobber
|
92
|
-
Rake::Task[:test].prerequisites << :compile
|
93
|
-
|
94
|
-
task :default => :test
|
95
|
-
|
96
|
-
# vim: set ts=2 sw=2 sts=2 et :
|
97
|
-
# encoding: utf-8
|
data/TODO
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
fizzbuzz (0.9.0)
|
2
|
-
|
3
|
-
* Improve github project page;
|
4
|
-
* Re-factor unit tests to make them more idiomatic (maybe move to Rspec and BDD?).
|
5
|
-
|
6
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Mon, 15 Dec 2014 00:27:26 +0000
|
7
|
-
|
8
|
-
fizzbuzz (0.8.0)
|
9
|
-
|
10
|
-
* Move to YARD from RDoc (as RDoc is very bad, really);
|
11
|
-
* Add pure-Ruby implementation;
|
12
|
-
* Add some examples;
|
13
|
-
* Add Doxygen style comments for other functions in the source code;
|
14
|
-
* Improve documentation i.e. source code commenting, README file, etc.
|
15
|
-
|
16
|
-
-- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Mon, 15 Dec 2014 00:27:26 +0000
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
# :enddoc:
|
4
|
-
|
5
|
-
#
|
6
|
-
# benchmark_fizzbuzz.rb
|
7
|
-
#
|
8
|
-
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
#
|
22
|
-
|
23
|
-
$: << File.expand_path('../../lib', __FILE__)
|
24
|
-
|
25
|
-
require 'time'
|
26
|
-
require 'benchmark'
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'fizzbuzz'
|
30
|
-
rescue LoadError
|
31
|
-
require 'rubygems'
|
32
|
-
require 'fizzbuzz'
|
33
|
-
end
|
34
|
-
|
35
|
-
CAPTION = "%8s%12s%11s%10s\n" % %w(User System Total Real)
|
36
|
-
|
37
|
-
n = (ARGV.shift || 1_000_000).to_i
|
38
|
-
|
39
|
-
start = Time.now
|
40
|
-
array = (1..n).to_a
|
41
|
-
reports = []
|
42
|
-
|
43
|
-
puts "FizzBuzz #{FizzBuzz::VERSION}, n = #{n}\n\n"
|
44
|
-
|
45
|
-
Benchmark.benchmark(CAPTION, 24) do |bm|
|
46
|
-
reports << bm.report('FizzBuzz::fizzbuzz') do
|
47
|
-
FizzBuzz.fizzbuzz(1, n)
|
48
|
-
end
|
49
|
-
|
50
|
-
reports << bm.report('FizzBuzz#each') do
|
51
|
-
FizzBuzz.new(1, n).each {|i| i }
|
52
|
-
end
|
53
|
-
|
54
|
-
reports << bm.report('FizzBuzz#reverse_each') do
|
55
|
-
FizzBuzz.new(1, n).reverse_each {|i| i }
|
56
|
-
end
|
57
|
-
|
58
|
-
reports << bm.report('FizzBuzz#to_a') do
|
59
|
-
FizzBuzz.new(1, n).to_a
|
60
|
-
end
|
61
|
-
|
62
|
-
reports << bm.report('FizzBuzz::[]') do
|
63
|
-
n.times {|i| FizzBuzz[i] }
|
64
|
-
end
|
65
|
-
|
66
|
-
reports << bm.report('FizzBuzz::is_fizz?') do
|
67
|
-
n.times {|i| FizzBuzz.is_fizz?(i) }
|
68
|
-
end
|
69
|
-
|
70
|
-
reports << bm.report('FizzBuzz::is_buzz?') do
|
71
|
-
n.times {|i| FizzBuzz.is_buzz?(i) }
|
72
|
-
end
|
73
|
-
|
74
|
-
reports << bm.report('FizzBuzz::is_fizzbuzz?') do
|
75
|
-
n.times {|i| FizzBuzz.is_fizzbuzz?(i) }
|
76
|
-
end
|
77
|
-
|
78
|
-
reports << bm.report('Array#fizzbuzz') do
|
79
|
-
array.fizzbuzz
|
80
|
-
end
|
81
|
-
|
82
|
-
reports << bm.report('Range#fizzbuzz') do
|
83
|
-
(1..n).fizzbuzz {|i| i }
|
84
|
-
end
|
85
|
-
|
86
|
-
[]
|
87
|
-
end
|
88
|
-
|
89
|
-
reports.sort_by! {|i| i.real }
|
90
|
-
|
91
|
-
overall = reports.reduce(:+)
|
92
|
-
average = overall / reports.size
|
93
|
-
|
94
|
-
fastest, slowest = reports.shift, reports.pop
|
95
|
-
|
96
|
-
padding = [fastest.label, slowest.label].max
|
97
|
-
padding = padding.size > 16 ? 24 : 16
|
98
|
-
|
99
|
-
puts "\n%15s%s%16s\n" % ['', CAPTION.strip, 'Name'] +
|
100
|
-
"%s%48s [ %-#{padding}s ]\n" % ['Fastest:', fastest.to_s.strip, fastest.label.strip] +
|
101
|
-
"%s%48s [ %-#{padding}s ]\n" % ['Slowest:', slowest.to_s.strip, slowest.label.strip] +
|
102
|
-
"%s%48s\n" % ['Average:', average.to_s.strip] +
|
103
|
-
"%s%48s\n" % ['Overall:', overall.to_s.strip] +
|
104
|
-
"\n%s%13.6f\n" % ['Wall Clock Time:', Time.now.to_f - start.to_f]
|
105
|
-
|
106
|
-
# vim: set ts=2 sw=2 sts=2 et :
|
107
|
-
# encoding: utf-8
|
data/ruby-fizzbuzz.gemspec
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
# :enddoc:
|
4
|
-
|
5
|
-
#
|
6
|
-
# ruby-fizzbuzz.gemspec
|
7
|
-
#
|
8
|
-
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
#
|
22
|
-
|
23
|
-
signing_key = File.expand_path('~/.gem/kwilczynski-private.pem')
|
24
|
-
|
25
|
-
Gem::Specification.new do |s|
|
26
|
-
s.name = 'ruby-fizzbuzz'
|
27
|
-
s.summary = 'Yet another FizzBuzz in Ruby'
|
28
|
-
|
29
|
-
s.description = <<-EOS
|
30
|
-
Yet another FizzBuzz in Ruby.
|
31
|
-
|
32
|
-
Provides simple and fast solution to a popular FizzBuzz problem for Ruby.
|
33
|
-
|
34
|
-
Written in C as an example of using Ruby's C API - with the support for
|
35
|
-
arbitrary large numeric values via the Bignum class.
|
36
|
-
EOS
|
37
|
-
|
38
|
-
s.platform = Gem::Platform::RUBY
|
39
|
-
s.version = File.read('VERSION').strip
|
40
|
-
s.license = 'Apache License, Version 2.0'
|
41
|
-
s.author = 'Krzysztof Wilczynski'
|
42
|
-
s.email = 'krzysztof.wilczynski@linux.com'
|
43
|
-
s.homepage = 'http://about.me/kwilczynski'
|
44
|
-
s.has_rdoc = true
|
45
|
-
|
46
|
-
s.required_ruby_version = '>= 1.9.2'
|
47
|
-
s.rubygems_version = '~> 2.2.0'
|
48
|
-
|
49
|
-
s.files = Dir['ext/**/*.{c,h,rb}'] +
|
50
|
-
Dir['lib/**/*.rb'] +
|
51
|
-
Dir['benchmark/**/*.rb'] +
|
52
|
-
Dir['test/**/*.rb'] +
|
53
|
-
%w(Rakefile ruby-fizzbuzz.gemspec AUTHORS
|
54
|
-
CHANGES CHANGES.rdoc COPYRIGHT LICENSE
|
55
|
-
README README.rdoc TODO VERSION)
|
56
|
-
|
57
|
-
s.executables << 'fizzbuzz'
|
58
|
-
s.require_paths << 'lib'
|
59
|
-
s.extensions << 'ext/fizzbuzz/extconf.rb'
|
60
|
-
|
61
|
-
s.signing_key = signing_key if File.exists?(signing_key)
|
62
|
-
end
|
63
|
-
|
64
|
-
# vim: set ts=2 sw=2 sts=2 et :
|
65
|
-
# encoding: utf-8
|
data/test/test_fizzbuzz.rb
DELETED
@@ -1,639 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
# :enddoc:
|
4
|
-
|
5
|
-
#
|
6
|
-
# test_fizzbuzz.rb
|
7
|
-
#
|
8
|
-
# Copyright 2012-2014 Krzysztof Wilczynski
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
#
|
22
|
-
|
23
|
-
begin
|
24
|
-
require 'coveralls'
|
25
|
-
Coveralls.wear!
|
26
|
-
rescue LoadError
|
27
|
-
STDERR.puts 'The Coveralls gem is not installed, skipping ...'
|
28
|
-
end
|
29
|
-
|
30
|
-
gem 'test-unit', '>= 3.0.0'
|
31
|
-
|
32
|
-
require 'test/unit'
|
33
|
-
require 'fizzbuzz'
|
34
|
-
|
35
|
-
class Fixnum
|
36
|
-
def self.overflow_size_with_sign
|
37
|
-
bits = [''].pack('p').size * 8
|
38
|
-
2 ** (bits - 1) - 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class FizzBuzzTest < Test::Unit::TestCase
|
43
|
-
def setup
|
44
|
-
@fixnum = 1
|
45
|
-
|
46
|
-
@bignum = 1_000_000_000_000
|
47
|
-
@large_bignum = 1_000_000_000_000_000
|
48
|
-
|
49
|
-
if Fixnum.overflow_size_with_sign + 1 > 2147483647
|
50
|
-
@bignum = @bignum ** 2
|
51
|
-
@large_bignum = @large_bignum ** 2
|
52
|
-
end
|
53
|
-
|
54
|
-
@words = %w(Fizz Buzz FizzBuzz).freeze
|
55
|
-
|
56
|
-
@expected = [
|
57
|
-
1, 2, 'Fizz',
|
58
|
-
4, 'Buzz', 'Fizz',
|
59
|
-
7, 8, 'Fizz',
|
60
|
-
'Buzz', 11, 'Fizz',
|
61
|
-
13, 14, 'FizzBuzz'
|
62
|
-
].freeze
|
63
|
-
|
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
|
-
]
|
71
|
-
|
72
|
-
@fizzbuzz = FizzBuzz.new(1, 15)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_fizzbuzz_alias
|
76
|
-
assert_same(FB, FizzBuzz)
|
77
|
-
end
|
78
|
-
|
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) }
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_fizzbuzz_new_instance
|
89
|
-
assert(@fizzbuzz.class == FizzBuzz)
|
90
|
-
end
|
91
|
-
|
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
|
166
|
-
assert_equal(15.fizzbuzz?, true)
|
167
|
-
assert_false(3.fizzbuzz?, false)
|
168
|
-
assert_false(5.fizzbuzz?, false)
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_bignum_integration
|
172
|
-
[
|
173
|
-
:fizz?,
|
174
|
-
:buzz?,
|
175
|
-
:fizzbuzz?
|
176
|
-
].each {|i| assert_respond_to(@bignum, i) }
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_bignum_is_fizz
|
180
|
-
assert_true((@bignum + 2).fizz?)
|
181
|
-
assert_false((@bignum + 15).fizz?)
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_bignum_is_buzz
|
185
|
-
assert_true((@bignum + 15).buzz?)
|
186
|
-
assert_false((@bignum + 5).buzz?)
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_bignum_is_fizzbuzz
|
190
|
-
assert_true((@bignum + 5).fizzbuzz?)
|
191
|
-
assert_false((@bignum + 2).fizzbuzz?)
|
192
|
-
assert_false((@bignum + 15).fizzbuzz?)
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_array_integration
|
196
|
-
assert_respond_to([], :fizzbuzz)
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_array_integration_fizzbuzz
|
200
|
-
obtained = Array(1..15).fizzbuzz
|
201
|
-
assert_kind_of(Array, obtained)
|
202
|
-
assert_equal(obtained, @expected)
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_array_integration_fizzbuzz_reverse
|
206
|
-
obtained = Array(1..15).fizzbuzz(true)
|
207
|
-
assert_kind_of(Array, obtained)
|
208
|
-
assert_equal(obtained, @expected.reverse)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_array_integration_fizzbuzz_block
|
212
|
-
obtained = []
|
213
|
-
Array(1..15).fizzbuzz {|i| obtained << i }
|
214
|
-
assert_equal(obtained, @expected)
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_array_integration_fizzbuzz_block_reverse
|
218
|
-
obtained = []
|
219
|
-
Array(1..15).fizzbuzz(true) {|i| obtained << i }
|
220
|
-
assert_equal(obtained, @expected.reverse)
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_range_integration
|
224
|
-
assert_respond_to((0..0), :fizzbuzz)
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_range_integration_fizzbuzz
|
228
|
-
obtained = (1..15).fizzbuzz
|
229
|
-
assert_kind_of(Enumerator, obtained)
|
230
|
-
assert_equal(obtained.to_a, @expected)
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_range_integration_fizzbuzz_reverse
|
234
|
-
obtained = (1..15).fizzbuzz(true)
|
235
|
-
assert_kind_of(Enumerator, obtained)
|
236
|
-
assert_equal(obtained.to_a, @expected.reverse)
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_range_integration_fizzbuzz_block
|
240
|
-
obtained = []
|
241
|
-
(1..15).fizzbuzz {|i| obtained << i }
|
242
|
-
assert_equal(obtained, @expected)
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_range_integration_fizzbuzz_block_reverse
|
246
|
-
obtained = []
|
247
|
-
(1..15).fizzbuzz(true) {|i| obtained << i }
|
248
|
-
assert_equal(obtained, @expected.reverse)
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_singleton_fizzbuzz_incorrect_range_error
|
252
|
-
assert_raise FizzBuzz::RangeError do
|
253
|
-
FizzBuzz.fizzbuzz(2, 1)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_singleton_fizzbuzz_incorrect_type_error
|
258
|
-
assert_raise FizzBuzz::TypeError do
|
259
|
-
FizzBuzz.fizzbuzz('', '')
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_singleton_fizzbuzz_fixnum
|
264
|
-
obtained = FizzBuzz.fizzbuzz(15, 15)
|
265
|
-
assert_kind_of(Array, obtained)
|
266
|
-
assert_equal(obtained, ['FizzBuzz'])
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_singleton_fizzbuzz_bignum
|
270
|
-
obtained = FizzBuzz.fizzbuzz(@bignum + 5, @bignum + 5)
|
271
|
-
assert_kind_of(Array, obtained)
|
272
|
-
assert_equal(obtained, ['FizzBuzz'])
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_singleton_fizzbuzz_large_bignum
|
276
|
-
obtained = FizzBuzz.fizzbuzz(@large_bignum + 5, @large_bignum + 5)
|
277
|
-
assert_kind_of(Array, obtained)
|
278
|
-
assert_equal(obtained, ['FizzBuzz'])
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_singleton_fizzbuzz_array
|
282
|
-
obtained = FizzBuzz.fizzbuzz(1, 15)
|
283
|
-
assert_kind_of(Array, obtained)
|
284
|
-
assert_equal(obtained, @expected)
|
285
|
-
end
|
286
|
-
|
287
|
-
def test_singleton_fizzbuzz_array_reverse
|
288
|
-
obtained = FizzBuzz.fizzbuzz(1, 15, true)
|
289
|
-
assert_kind_of(Array, obtained)
|
290
|
-
assert_equal(obtained, @expected.reverse)
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_singleton_fizzbuzz_block
|
294
|
-
obtained = []
|
295
|
-
FizzBuzz.fizzbuzz(1, 15) {|i| obtained << i }
|
296
|
-
assert_equal(obtained, @expected)
|
297
|
-
end
|
298
|
-
|
299
|
-
def test_singleton_fizzbuzz_block_reverse
|
300
|
-
obtained = []
|
301
|
-
FizzBuzz.fizzbuzz(1, 15, true) {|i| obtained << i }
|
302
|
-
assert_equal(obtained, @expected.reverse)
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_singleton_squre_fixnum
|
306
|
-
obtained = []
|
307
|
-
|
308
|
-
obtained << FizzBuzz[3]
|
309
|
-
obtained << FizzBuzz[5]
|
310
|
-
obtained << FizzBuzz[15]
|
311
|
-
|
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])
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_singleton_squre_bignum
|
321
|
-
obtained = []
|
322
|
-
|
323
|
-
obtained << FizzBuzz[@bignum + 2]
|
324
|
-
obtained << FizzBuzz[@bignum + 15]
|
325
|
-
obtained << FizzBuzz[@bignum + 5]
|
326
|
-
|
327
|
-
assert_kind_of(Bignum, FizzBuzz[@bignum + 3])
|
328
|
-
|
329
|
-
obtained.each_with_index do |v,i|
|
330
|
-
assert_kind_of(String, v)
|
331
|
-
assert_equal(obtained[i], @words[i])
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_singleton_squre_large_bignum
|
336
|
-
obtained = []
|
337
|
-
|
338
|
-
obtained << FizzBuzz[@large_bignum + 2]
|
339
|
-
obtained << FizzBuzz[@large_bignum + 15]
|
340
|
-
obtained << FizzBuzz[@large_bignum + 5]
|
341
|
-
|
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])
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
def test_singleton_is_fizz
|
351
|
-
assert_true(FizzBuzz.is_fizz?(3))
|
352
|
-
assert_false(FizzBuzz.is_fizz?(15))
|
353
|
-
end
|
354
|
-
|
355
|
-
def test_singleton_is_buzz
|
356
|
-
assert_true(FizzBuzz.is_buzz?(5))
|
357
|
-
assert_false(FizzBuzz.is_buzz?(15))
|
358
|
-
end
|
359
|
-
|
360
|
-
def test_singleton_is_fizzbuzz
|
361
|
-
assert_true(FizzBuzz.is_fizzbuzz?(15))
|
362
|
-
assert_false(FizzBuzz.is_fizzbuzz?(3))
|
363
|
-
assert_false(FizzBuzz.is_fizzbuzz?(5))
|
364
|
-
end
|
365
|
-
|
366
|
-
def test_fizzbuzz_for_0
|
367
|
-
obtained_square = FizzBuzz[0]
|
368
|
-
obtained_is_fizzbuzz = FizzBuzz.is_fizzbuzz?(0)
|
369
|
-
|
370
|
-
assert_kind_of(Fixnum, obtained_square)
|
371
|
-
assert_equal(obtained_square, 0)
|
372
|
-
assert_false(obtained_is_fizzbuzz)
|
373
|
-
end
|
374
|
-
|
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)
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_to_a_fixnum
|
385
|
-
obtained = @fizzbuzz.to_a
|
386
|
-
|
387
|
-
assert_kind_of(Array, obtained)
|
388
|
-
assert_equal(obtained, @expected)
|
389
|
-
end
|
390
|
-
|
391
|
-
def test_each_fixnum
|
392
|
-
obtained = []
|
393
|
-
@fizzbuzz.each {|i| obtained << i }
|
394
|
-
assert_equal(obtained, @expected)
|
395
|
-
end
|
396
|
-
|
397
|
-
def test_reverse_each_fixnum
|
398
|
-
obtained = []
|
399
|
-
@fizzbuzz.reverse_each {|i| obtained << i }
|
400
|
-
assert_equal(obtained, @expected.reverse)
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_to_a_bignum
|
404
|
-
@fizzbuzz = FizzBuzz.new(@bignum + 1, @bignum + 15)
|
405
|
-
obtained = @fizzbuzz.to_a
|
406
|
-
|
407
|
-
assert_kind_of(Array, obtained)
|
408
|
-
assert_equal(obtained, @expected_bignum)
|
409
|
-
end
|
410
|
-
|
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')
|
434
|
-
end
|
435
|
-
|
436
|
-
def test_for_fizzbuzz_bignum
|
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')
|
443
|
-
end
|
444
|
-
|
445
|
-
def test_for_fizzbuzz_large_bignum
|
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')
|
452
|
-
end
|
453
|
-
|
454
|
-
def test_correct_start_fixnum
|
455
|
-
assert_kind_of(Fixnum, @fizzbuzz.start)
|
456
|
-
assert_equal(@fizzbuzz.start, 1)
|
457
|
-
|
458
|
-
@fizzbuzz.start = 2
|
459
|
-
|
460
|
-
assert_kind_of(Fixnum, @fizzbuzz.start)
|
461
|
-
assert_equal(@fizzbuzz.start, 2)
|
462
|
-
end
|
463
|
-
|
464
|
-
def test_correct_start_bignum
|
465
|
-
@fizzbuzz = FizzBuzz.new(@bignum, @bignum)
|
466
|
-
|
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)
|
474
|
-
end
|
475
|
-
|
476
|
-
def test_correct_start_large_bignum
|
477
|
-
@fizzbuzz = FizzBuzz.new(@large_bignum, @large_bignum)
|
478
|
-
|
479
|
-
assert_kind_of(Bignum, @fizzbuzz.start)
|
480
|
-
assert_equal(@fizzbuzz.start, @large_bignum)
|
481
|
-
|
482
|
-
@fizzbuzz.start = @large_bignum - 5
|
483
|
-
|
484
|
-
assert_kind_of(Bignum, @fizzbuzz.start)
|
485
|
-
assert_equal(@fizzbuzz.start, @large_bignum - 5)
|
486
|
-
end
|
487
|
-
|
488
|
-
def test_correct_stop_fixnum
|
489
|
-
assert_kind_of(Fixnum, @fizzbuzz.stop)
|
490
|
-
assert_equal(@fizzbuzz.stop, 15)
|
491
|
-
|
492
|
-
@fizzbuzz.stop = 5
|
493
|
-
|
494
|
-
assert_kind_of(Fixnum, @fizzbuzz.stop)
|
495
|
-
assert_equal(@fizzbuzz.stop, 5)
|
496
|
-
end
|
497
|
-
|
498
|
-
def test_correct_stop_bignum
|
499
|
-
@fizzbuzz = FizzBuzz.new(@bignum, @bignum)
|
500
|
-
|
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)
|
508
|
-
end
|
509
|
-
|
510
|
-
def test_correct_stop_large_bignum
|
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
|
517
|
-
|
518
|
-
assert_kind_of(Bignum, @fizzbuzz.stop)
|
519
|
-
assert_equal(@fizzbuzz.stop, @large_bignum + 5)
|
520
|
-
end
|
521
|
-
|
522
|
-
def test_missing_arguments
|
523
|
-
assert_raise ArgumentError do
|
524
|
-
FizzBuzz.new
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
def test_arguments_type_error_strings
|
529
|
-
assert_raise FizzBuzz::TypeError do
|
530
|
-
FizzBuzz.new('', '')
|
531
|
-
end
|
532
|
-
end
|
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
|
-
|
540
|
-
def test_arguments_type_error_nils
|
541
|
-
assert_raise FizzBuzz::TypeError do
|
542
|
-
FizzBuzz.new(nil, nil)
|
543
|
-
end
|
544
|
-
end
|
545
|
-
|
546
|
-
def test_incorrect_range_error
|
547
|
-
assert_raise FizzBuzz::RangeError do
|
548
|
-
FizzBuzz.new(2, 1)
|
549
|
-
end
|
550
|
-
end
|
551
|
-
|
552
|
-
def test_start_type_error
|
553
|
-
assert_raise FizzBuzz::TypeError do
|
554
|
-
@fizzbuzz.start = ''
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
def test_stop_type_error
|
559
|
-
assert_raise FizzBuzz::TypeError do
|
560
|
-
@fizzbuzz.stop = ''
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
def test_correct_start_stop
|
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
|
573
|
-
|
574
|
-
def test_fizzbuzz_error
|
575
|
-
message = 'The quick brown fox jumps over the lazy dog'
|
576
|
-
error = FizzBuzz::Error.new(message)
|
577
|
-
|
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)
|
583
|
-
end
|
584
|
-
|
585
|
-
def test_start_range_error
|
586
|
-
assert_raise FizzBuzz::RangeError do
|
587
|
-
@fizzbuzz.start = 16
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def test_stop_range_error
|
592
|
-
assert_raise FizzBuzz::RangeError do
|
593
|
-
@fizzbuzz.stop = -1
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
def test_for_not_raising_range_error
|
598
|
-
assert_nothing_raised do
|
599
|
-
FizzBuzz.new(1, @bignum ** 2)
|
600
|
-
FizzBuzz.new(-@large_bignum, 15)
|
601
|
-
end
|
602
|
-
end
|
603
|
-
|
604
|
-
def test_error_attributes_not_nil
|
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)
|
610
|
-
end
|
611
|
-
|
612
|
-
def test_error_attributes_nil
|
613
|
-
FizzBuzz.new('', '')
|
614
|
-
rescue FizzBuzz::TypeError => error
|
615
|
-
assert_nil(error.start)
|
616
|
-
assert_nil(error.stop)
|
617
|
-
end
|
618
|
-
|
619
|
-
def test_start_type_error_message
|
620
|
-
FizzBuzz.new('', 15)
|
621
|
-
rescue FizzBuzz::TypeError => error
|
622
|
-
assert_equal(error.message, 'must be a Fixnum or Bignum type for start')
|
623
|
-
end
|
624
|
-
|
625
|
-
def test_stop_type_error_message
|
626
|
-
FizzBuzz.new(1, '')
|
627
|
-
rescue FizzBuzz::TypeError => error
|
628
|
-
assert_equal(error.message, 'must be a Fixnum or Bignum type for stop')
|
629
|
-
end
|
630
|
-
|
631
|
-
def test_range_error_message
|
632
|
-
FizzBuzz.new(15, 1)
|
633
|
-
rescue FizzBuzz::RangeError => error
|
634
|
-
assert_equal(error.message, 'start value is higher than stop value')
|
635
|
-
end
|
636
|
-
end
|
637
|
-
|
638
|
-
# vim: set ts=2 sw=2 sts=2 et :
|
639
|
-
# encoding: utf-8
|