rubysl-rational 0.0.1 → 1.0.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 +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rational.rb +1 -0
- data/lib/rubysl/rational.rb +2 -0
- data/lib/rubysl/rational/rational.rb +562 -0
- data/lib/{rubysl-rational → rubysl/rational}/version.rb +1 -1
- data/rubysl-rational.gemspec +17 -18
- data/spec/Rational_spec.rb +7 -0
- data/spec/abs_spec.rb +7 -0
- data/spec/ceil_spec.rb +7 -0
- data/spec/coerce_spec.rb +7 -0
- data/spec/comparison_spec.rb +23 -0
- data/spec/denominator_spec.rb +7 -0
- data/spec/div_spec.rb +19 -0
- data/spec/divide_spec.rb +19 -0
- data/spec/divmod_spec.rb +15 -0
- data/spec/equal_value_spec.rb +19 -0
- data/spec/exponent_spec.rb +7 -0
- data/spec/fdiv_spec.rb +7 -0
- data/spec/floor_spec.rb +7 -0
- data/spec/hash_spec.rb +7 -0
- data/spec/initialize_spec.rb +9 -0
- data/spec/inspect_spec.rb +7 -0
- data/spec/minus_spec.rb +7 -0
- data/spec/modulo_spec.rb +7 -0
- data/spec/multiply_spec.rb +19 -0
- data/spec/new_spec.rb +20 -0
- data/spec/numerator_spec.rb +7 -0
- data/spec/plus_spec.rb +18 -0
- data/spec/quo_spec.rb +7 -0
- data/spec/reduce_spec.rb +32 -0
- data/spec/remainder_spec.rb +7 -0
- data/spec/round_spec.rb +7 -0
- data/spec/to_f_spec.rb +7 -0
- data/spec/to_i_spec.rb +7 -0
- data/spec/to_r_spec.rb +7 -0
- data/spec/to_s_spec.rb +7 -0
- data/spec/truncate_spec.rb +7 -0
- metadata +116 -89
- data/lib/rubysl-rational.rb +0 -7
data/rubysl-rational.gemspec
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/rational/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-rational"
|
6
|
+
spec.version = RubySL::Rational::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library rational.}
|
10
|
+
spec.summary = %q{Ruby standard library rational.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-rational"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = RubySL::Rational::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
gem.add_development_dependency "rake", "~> 10.0"
|
21
|
-
gem.add_development_dependency "mspec", "~> 1.5"
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
21
|
end
|
data/spec/abs_spec.rb
ADDED
data/spec/ceil_spec.rb
ADDED
data/spec/coerce_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/comparison', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#<=> when passed a Rational object" do
|
5
|
+
it_behaves_like(:rational_cmp_rat, :<=>)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#<=> when passed a Integer object" do
|
9
|
+
it_behaves_like(:rational_cmp_int, :<=>)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Rational#<=> when passed a Float object" do
|
13
|
+
it_behaves_like(:rational_cmp_float, :<=>)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Rational#<=> when passed an Object that responds to #coerce" do
|
17
|
+
it_behaves_like(:rational_cmp_coerce, :<=>)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Rational#<=> when passed a non-Numeric Object that doesn't respond to #coerce" do
|
21
|
+
it_behaves_like(:rational_cmp_other, :<=>)
|
22
|
+
end
|
23
|
+
end
|
data/spec/div_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/div', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#div" do
|
5
|
+
it_behaves_like(:rational_div, :div)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#div passed a Rational" do
|
9
|
+
it_behaves_like(:rational_div_rat, :div)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Rational#div passed an Integer" do
|
13
|
+
it_behaves_like(:rational_div_int, :div)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Rational#div passed a Float" do
|
17
|
+
it_behaves_like(:rational_div_float, :div)
|
18
|
+
end
|
19
|
+
end
|
data/spec/divide_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/divide', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#/" do
|
5
|
+
it_behaves_like(:rational_divide, :/)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#/ when passed an Integer" do
|
9
|
+
it_behaves_like(:rational_divide_int, :/)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Rational#/ when passed a Rational" do
|
13
|
+
it_behaves_like(:rational_divide_rat, :/)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Rational#/ when passed a Float" do
|
17
|
+
it_behaves_like(:rational_divide_float, :/)
|
18
|
+
end
|
19
|
+
end
|
data/spec/divmod_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/divmod', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#divmod when passed a Rational" do
|
5
|
+
it_behaves_like(:rational_divmod_rat, :divmod)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#divmod when passed an Integer" do
|
9
|
+
it_behaves_like(:rational_divmod_int, :divmod)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Rational#divmod when passed a Float" do
|
13
|
+
it_behaves_like(:rational_divmod_float, :divmod)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/equal_value', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#==" do
|
5
|
+
it_behaves_like(:rational_equal_value, :==)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#== when passed a Rational" do
|
9
|
+
it_behaves_like(:rational_equal_value_rat, :==)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Rational#== when passed a Float" do
|
13
|
+
it_behaves_like(:rational_equal_value_float, :==)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Rational#== when passed an Integer" do
|
17
|
+
it_behaves_like(:rational_equal_value_int, :==)
|
18
|
+
end
|
19
|
+
end
|
data/spec/fdiv_spec.rb
ADDED
data/spec/floor_spec.rb
ADDED
data/spec/hash_spec.rb
ADDED
data/spec/minus_spec.rb
ADDED
data/spec/modulo_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/multiply', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#*" do
|
5
|
+
it_behaves_like(:rational_multiply, :*)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#* passed a Rational" do
|
9
|
+
it_behaves_like(:rational_multiply_rat, :*)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Rational#* passed a Float" do
|
13
|
+
it_behaves_like(:rational_multiply_float, :*)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Rational#* passed an Integer" do
|
17
|
+
it_behaves_like(:rational_multiply_int, :*)
|
18
|
+
end
|
19
|
+
end
|
data/spec/new_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
describe "Rational.new" do
|
3
|
+
it "is private" do
|
4
|
+
Rational.should have_private_method(:new)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational.new!" do
|
9
|
+
it "returns a Rational with the passed numerator and denominator not reduced to their lowest terms" do
|
10
|
+
Rational.new!(2, 4).should_not eql(Rational(1, 4))
|
11
|
+
Rational.new!(6, 8).should_not eql(Rational(3, 4))
|
12
|
+
Rational.new!(-5, 10).should_not eql(Rational(-1, 2))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not check for divisions by 0" do
|
16
|
+
lambda { Rational.new!(4, 0) }.should_not raise_error(ZeroDivisionError)
|
17
|
+
lambda { Rational.new!(0, 0) }.should_not raise_error(ZeroDivisionError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/plus_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../../../shared/rational/plus', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational#+" do
|
5
|
+
it_behaves_like(:rational_plus, :+)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Rational#+ with a Rational" do
|
9
|
+
it_behaves_like(:rational_plus_rat, :+)
|
10
|
+
end
|
11
|
+
describe "Rational#+ with a Float" do
|
12
|
+
it_behaves_like(:rational_plus_float, :+)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Rational#+ with an Integer" do
|
16
|
+
it_behaves_like(:rational_plus_int, :+)
|
17
|
+
end
|
18
|
+
end
|
data/spec/quo_spec.rb
ADDED
data/spec/reduce_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rational'
|
2
|
+
|
3
|
+
ruby_version_is ""..."1.9" do
|
4
|
+
describe "Rational.reduce" do
|
5
|
+
it "returns a new Rational with the passed numerator and denominator reduced to their lowest terms" do
|
6
|
+
Rational(6, 8).should eql(Rational(3, 4))
|
7
|
+
Rational(-5, 10).should eql(Rational(-1, 2))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "raises a ZeroDivisionError when the passed denominator is 0" do
|
11
|
+
lambda { Rational.reduce(4, 0) }.should raise_error(ZeroDivisionError)
|
12
|
+
lambda { Rational.reduce(-1, 0) }.should raise_error(ZeroDivisionError)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Rational.reduce when Unify is defined" do
|
17
|
+
# This is not consistent with the Complex library, Complex checks
|
18
|
+
# Complex::Unify and not the top-level Unify.
|
19
|
+
it "returns an Integer when the reduced denominator is 1" do
|
20
|
+
begin
|
21
|
+
Unify = true
|
22
|
+
|
23
|
+
Rational.reduce(3, 1).should eql(3)
|
24
|
+
Rational.reduce(5, 1).should eql(5)
|
25
|
+
Rational.reduce(4, 2).should eql(2)
|
26
|
+
Rational.reduce(-9, 3).should eql(-3)
|
27
|
+
ensure
|
28
|
+
Object.send :remove_const, :Unify
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/round_spec.rb
ADDED
data/spec/to_f_spec.rb
ADDED
data/spec/to_i_spec.rb
ADDED
data/spec/to_r_spec.rb
ADDED