rubysl-complex 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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +2 -0
  8. data/lib/complex.rb +1 -0
  9. data/lib/rubysl/complex.rb +2 -0
  10. data/lib/rubysl/complex/complex.rb +659 -0
  11. data/lib/rubysl/complex/version.rb +5 -0
  12. data/rubysl-complex.gemspec +23 -0
  13. data/spec/Complex_spec.rb +9 -0
  14. data/spec/abs2_spec.rb +10 -0
  15. data/spec/abs_spec.rb +10 -0
  16. data/spec/angle_spec.rb +7 -0
  17. data/spec/arg_spec.rb +7 -0
  18. data/spec/coerce_spec.rb +11 -0
  19. data/spec/comparison_spec.rb +23 -0
  20. data/spec/conj_spec.rb +7 -0
  21. data/spec/conjugate_spec.rb +7 -0
  22. data/spec/constants_spec.rb +9 -0
  23. data/spec/denominator_spec.rb +20 -0
  24. data/spec/divide_spec.rb +9 -0
  25. data/spec/equal_value_spec.rb +9 -0
  26. data/spec/exponent_spec.rb +10 -0
  27. data/spec/float/angle_spec.rb +9 -0
  28. data/spec/float/arg_spec.rb +9 -0
  29. data/spec/generic_spec.rb +25 -0
  30. data/spec/hash_spec.rb +10 -0
  31. data/spec/imag_spec.rb +10 -0
  32. data/spec/image_spec.rb +7 -0
  33. data/spec/inspect_spec.rb +10 -0
  34. data/spec/math/acos_spec.rb +30 -0
  35. data/spec/math/acosh_spec.rb +30 -0
  36. data/spec/math/asin_spec.rb +30 -0
  37. data/spec/math/asinh_spec.rb +30 -0
  38. data/spec/math/atan2_spec.rb +30 -0
  39. data/spec/math/atan_spec.rb +30 -0
  40. data/spec/math/atanh_spec.rb +34 -0
  41. data/spec/math/cos_spec.rb +30 -0
  42. data/spec/math/cosh_spec.rb +30 -0
  43. data/spec/math/exp_spec.rb +30 -0
  44. data/spec/math/fixtures/classes.rb +3 -0
  45. data/spec/math/log10_spec.rb +30 -0
  46. data/spec/math/log_spec.rb +30 -0
  47. data/spec/math/shared/acos.rb +41 -0
  48. data/spec/math/shared/acosh.rb +37 -0
  49. data/spec/math/shared/asin.rb +47 -0
  50. data/spec/math/shared/asinh.rb +32 -0
  51. data/spec/math/shared/atan.rb +32 -0
  52. data/spec/math/shared/atan2.rb +34 -0
  53. data/spec/math/shared/atanh.rb +30 -0
  54. data/spec/math/shared/cos.rb +30 -0
  55. data/spec/math/shared/cosh.rb +28 -0
  56. data/spec/math/shared/exp.rb +28 -0
  57. data/spec/math/shared/log.rb +39 -0
  58. data/spec/math/shared/log10.rb +41 -0
  59. data/spec/math/shared/sin.rb +30 -0
  60. data/spec/math/shared/sinh.rb +28 -0
  61. data/spec/math/shared/sqrt.rb +34 -0
  62. data/spec/math/shared/tan.rb +28 -0
  63. data/spec/math/shared/tanh.rb +32 -0
  64. data/spec/math/sin_spec.rb +30 -0
  65. data/spec/math/sinh_spec.rb +30 -0
  66. data/spec/math/sqrt_spec.rb +30 -0
  67. data/spec/math/tan_spec.rb +30 -0
  68. data/spec/math/tanh_spec.rb +30 -0
  69. data/spec/minus_spec.rb +9 -0
  70. data/spec/modulo_spec.rb +29 -0
  71. data/spec/multiply_spec.rb +9 -0
  72. data/spec/new_spec.rb +41 -0
  73. data/spec/numerator_spec.rb +12 -0
  74. data/spec/numeric/angle_spec.rb +11 -0
  75. data/spec/numeric/arg_spec.rb +11 -0
  76. data/spec/numeric/conj_spec.rb +11 -0
  77. data/spec/numeric/conjugate_spec.rb +11 -0
  78. data/spec/numeric/im_spec.rb +9 -0
  79. data/spec/numeric/imag_spec.rb +11 -0
  80. data/spec/numeric/image_spec.rb +11 -0
  81. data/spec/numeric/polar_spec.rb +11 -0
  82. data/spec/numeric/real_spec.rb +11 -0
  83. data/spec/plus_spec.rb +9 -0
  84. data/spec/polar_spec.rb +13 -0
  85. data/spec/real_spec.rb +10 -0
  86. data/spec/to_s_spec.rb +9 -0
  87. metadata +259 -0
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module Complex
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/complex/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-complex"
6
+ spec.version = RubySL::Complex::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library complex.}
10
+ spec.summary = %q{Ruby standard library complex.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-complex"
12
+ spec.license = "BSD"
13
+
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"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
+ spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
23
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../shared/complex/Complex', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require 'complex'
5
+
6
+ describe "Complex()" do
7
+ it_behaves_like :kernel_Complex, :Complex
8
+ end
9
+ end
data/spec/abs2_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../shared/complex/abs2', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+
7
+ describe "Complex#abs2" do
8
+ it_behaves_like(:complex_abs2, :abs2)
9
+ end
10
+ end
data/spec/abs_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../shared/complex/abs', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+
7
+ describe "Complex#abs" do
8
+ it_behaves_like(:complex_abs, :abs)
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/complex/arg', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Complex#angle" do
5
+ it_behaves_like(:complex_arg, :angle)
6
+ end
7
+ end
data/spec/arg_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/complex/arg', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Complex#arg" do
5
+ it_behaves_like(:complex_arg, :arg)
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../../shared/complex/coerce', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+ require "rational"
7
+
8
+ describe "Complex#coerce" do
9
+ it_behaves_like(:complex_coerce, :coerce)
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+
2
+ ruby_version_is ""..."1.9" do
3
+
4
+ require 'complex'
5
+
6
+ describe "Complex#<=>" do
7
+ it "compares the absolute values of self and other" do
8
+ (Complex(1, 2) <=> Complex(2, 1)).should == 0
9
+ (Complex(-3, -10) <=> Complex(2, 1)).should > 0
10
+ (Complex(3, 5) <=> Complex(100.0, -190.5)).should < 0
11
+
12
+ (Complex(3, 4) <=> 5).should == 0
13
+ (Complex(3, 4) <=> -5).should == 0
14
+ (Complex(-3, -4) <=> -5).should == 0
15
+
16
+ (Complex(3, 4) <=> 6).should < 0
17
+ (Complex(3, 4) <=> -4).should > 0
18
+
19
+ (Complex(3, 4) <=> 6.0).should < 0
20
+ (Complex(3, 4) <=> -4.0).should > 0
21
+ end
22
+ end
23
+ end
data/spec/conj_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/complex/conjugate', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Complex#conj" do
5
+ it_behaves_like(:complex_conjugate, :conj)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/complex/conjugate', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ describe "Complex#conjugate" do
5
+ it_behaves_like(:complex_conjugate, :conjugate)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../shared/complex/constants', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require 'complex'
5
+
6
+ describe "Complex::I" do
7
+ it_behaves_like :complex_I, :I
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../../../shared/complex/denominator', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+
7
+ # FIXME:
8
+ # Complex#denominator requires the rational library,
9
+ # as Integer#denominator is defined by it.
10
+ # I think this method is pretty buggy, as there is no
11
+ # denominator for Floats and rational might not always
12
+ # be loaded, both resulting in a method missing exception.
13
+ # Also, the documentation for Complex#denominator does
14
+ # not mention a dependency for rational.
15
+ require "rational"
16
+
17
+ describe "Complex#denominator" do
18
+ it_behaves_like(:complex_denominator, :denominator)
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../shared/complex/divide', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require 'complex'
5
+
6
+ describe "Complex#/" do
7
+ it_behaves_like :complex_divide, :/
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../shared/complex/equal_value', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require 'complex'
5
+
6
+ describe "Complex#==" do
7
+ it_behaves_like :complex_equal_value, :==
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../shared/complex/exponent', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require "complex"
5
+ require "rational"
6
+
7
+ describe "Complex#**" do
8
+ it_behaves_like :complex_exponent, :**
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../../shared/complex/float/arg', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require 'complex'
5
+
6
+ describe "Float#angle" do
7
+ it_behaves_like :float_arg, :angle
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../../../shared/complex/float/arg', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+ require 'complex'
5
+
6
+ describe "Float#arg" do
7
+ it_behaves_like :float_arg, :arg
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ ruby_version_is ""..."1.9" do
2
+
3
+ require 'complex'
4
+ require "rational"
5
+
6
+ describe "Complex.generic?" do
7
+ it "returns true when given an Integer, Float or Rational" do
8
+ Complex.generic?(1).should == true
9
+ Complex.generic?(-1).should == true
10
+
11
+ Complex.generic?(20.3).should == true
12
+ Complex.generic?(-20.3).should == true
13
+
14
+ Complex.generic?(bignum_value).should == true
15
+ Complex.generic?(-bignum_value).should == true
16
+
17
+ Complex.generic?(Rational(3, 4)).should == true
18
+ Complex.generic?(-Rational(3, 4)).should == true
19
+
20
+ Complex.generic?(:symbol).should == false
21
+ Complex.generic?("string").should == false
22
+ Complex.generic?(mock("Object")).should == false
23
+ end
24
+ end
25
+ end
data/spec/hash_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../shared/complex/hash', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+
7
+ describe "Complex#hash" do
8
+ it_behaves_like(:complex_hash, :hash)
9
+ end
10
+ end
data/spec/imag_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../shared/complex/image', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+
7
+ describe "Complex#imag" do
8
+ it_behaves_like(:complex_image, :imag)
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../../shared/complex/image', __FILE__)
2
+
3
+ require 'complex'
4
+
5
+ describe "Complex#image" do
6
+ it_behaves_like(:complex_image, :image)
7
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../shared/complex/inspect', __FILE__)
2
+
3
+ ruby_version_is ""..."1.9" do
4
+
5
+ require 'complex'
6
+
7
+ describe "Complex#inspect" do
8
+ it_behaves_like(:complex_inspect, :inspect)
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/acos', __FILE__)
3
+
4
+ describe "Math#acos" do
5
+ it_behaves_like :complex_math_acos, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:acos)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#acos!" do
14
+ it_behaves_like :complex_math_acos_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:acos!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.acos" do
23
+ it_behaves_like :complex_math_acos, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.acos!" do
28
+ it_behaves_like :complex_math_acos_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/acosh', __FILE__)
3
+
4
+ describe "Math#acosh" do
5
+ it_behaves_like :complex_math_acosh, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:acosh)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#acosh!" do
14
+ it_behaves_like :complex_math_acosh_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:acosh!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.acosh" do
23
+ it_behaves_like :complex_math_acosh, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.acosh!" do
28
+ it_behaves_like :complex_math_acosh_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/asin', __FILE__)
3
+
4
+ describe "Math#asin" do
5
+ it_behaves_like :complex_math_asin, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:asin)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#asin!" do
14
+ it_behaves_like :complex_math_asin_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:asin!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.asin" do
23
+ it_behaves_like :complex_math_asin, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.asin!" do
28
+ it_behaves_like :complex_math_asin_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/asinh', __FILE__)
3
+
4
+ describe "Math#asinh" do
5
+ it_behaves_like :complex_math_asinh, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:asinh)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#asinh!" do
14
+ it_behaves_like :complex_math_asinh_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:asinh!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.asinh" do
23
+ it_behaves_like :complex_math_asinh, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.asinh!" do
28
+ it_behaves_like :complex_math_asinh_bang, :_, Math
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'complex'
2
+ require File.expand_path('../shared/atan2', __FILE__)
3
+
4
+ describe "Math#atan2" do
5
+ it_behaves_like :complex_math_atan2, :_, IncludesMath.new
6
+
7
+ it "is a private instance method" do
8
+ IncludesMath.should have_private_instance_method(:atan2)
9
+ end
10
+ end
11
+
12
+ ruby_version_is ""..."1.9" do
13
+ describe "Math#atan2!" do
14
+ it_behaves_like :complex_math_atan2_bang, :_, IncludesMath.new
15
+
16
+ it "is a private instance method" do
17
+ IncludesMath.should have_private_instance_method(:atan2!)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Math.atan2" do
23
+ it_behaves_like :complex_math_atan2, :_, Math
24
+ end
25
+
26
+ ruby_version_is ""..."1.9" do
27
+ describe "Math.atan2!" do
28
+ it_behaves_like :complex_math_atan2_bang, :_, Math
29
+ end
30
+ end