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.
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
2
  module Rational
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -1,22 +1,21 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/rubysl-rational/version', __FILE__)
1
+ # coding: utf-8
2
+ require './lib/rubysl/rational/version'
3
3
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Brian Shirai"]
6
- gem.email = ["brixen@gmail.com"]
7
- gem.description = %q{Ruby Standard Library - rational}
8
- gem.summary = %q{Ruby Standard Library - rational}
9
- gem.homepage = ""
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
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "rubysl-rational"
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
- gem.add_runtime_dependency "redcard", "~> 1.0"
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
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/Rational', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational()" do
5
+ it_behaves_like :kernel_Rational, :Rational
6
+ end
7
+ end
data/spec/abs_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/abs', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#abs" do
5
+ it_behaves_like(:rational_abs, :abs)
6
+ end
7
+ end
data/spec/ceil_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/ceil', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#ceil" do
5
+ it_behaves_like(:rational_ceil, :ceil)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/coerce', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#coerce" do
5
+ it_behaves_like(:rational_coerce, :coerce)
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/denominator', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#denominator" do
5
+ it_behaves_like(:rational_denominator, :denominator)
6
+ end
7
+ 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
@@ -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
@@ -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
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/exponent', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#**" do
5
+ it_behaves_like(:rational_exponent, :**)
6
+ end
7
+ end
data/spec/fdiv_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/fdiv', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#fdiv" do
5
+ it_behaves_like(:rational_fdiv, :fdiv)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/floor', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#floor" do
5
+ it_behaves_like(:rational_floor, :floor)
6
+ end
7
+ end
data/spec/hash_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/hash', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#hash" do
5
+ it_behaves_like(:rational_hash, :hash)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../shared/rational/initialize', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#initialize" do
5
+ it_behaves_like(:rational_initialize, :initialize)
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/inspect', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#inspect" do
5
+ it_behaves_like(:rational_inspect, :inspect)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/minus', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#-" do
5
+ it_behaves_like(:rational_minus, :-)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/modulo', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#%" do
5
+ it_behaves_like(:rational_modulo, :%)
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/numerator', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#numerator" do
5
+ it_behaves_like(:rational_numerator, :numerator)
6
+ end
7
+ 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
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/divide', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#quo" do
5
+ it_behaves_like(:rational_divide, :quo)
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/remainder', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#remainder" do
5
+ it_behaves_like(:rational_remainder, :remainder)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/round', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#round" do
5
+ it_behaves_like(:rational_round, :round)
6
+ end
7
+ end
data/spec/to_f_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/to_f', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#to_f" do
5
+ it_behaves_like(:rational_to_f, :to_f)
6
+ end
7
+ end
data/spec/to_i_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/to_i', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#to_i" do
5
+ it_behaves_like(:rational_to_i, :to_i)
6
+ end
7
+ end
data/spec/to_r_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/to_r', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#to_r" do
5
+ it_behaves_like(:rational_to_r, :to_r)
6
+ end
7
+ end
data/spec/to_s_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/rational/to_s', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Rational#to_s" do
5
+ it_behaves_like(:rational_to_s, :to_s)
6
+ end
7
+ end