Class: ContinuedFractionTest
- Includes:
- MoreMath
- Defined in:
- tests/continued_fraction_test.rb
Constant Summary
Constants included from MoreMath
MoreMath::Infinity, MoreMath::STD_NORMAL_DISTRIBUTION, MoreMath::VERSION, MoreMath::VERSION_ARRAY, MoreMath::VERSION_BUILD, MoreMath::VERSION_MAJOR, MoreMath::VERSION_MINOR
Instance Method Summary collapse
- #setup ⇒ Object
- #test_continued_fractions ⇒ Object
- #test_invalid_arguments ⇒ Object
- #test_to_proc ⇒ Object
Instance Method Details
#setup ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'tests/continued_fraction_test.rb', line 9 def setup @zero = ContinuedFraction.for_a([-1,2,3]).for_b([2,3,3]) @none1 = ContinuedFraction.for_a proc {} @none2 = ContinuedFraction.for_a {} @phi = ContinuedFraction.new @finite = ContinuedFraction.for_a [3, 4, 12, 3, 1] @sqrt_2 = ContinuedFraction.for_a { |n| n == 0 ? 1 : 2 } @pi_finite = ContinuedFraction.for_a [3, 7, 15, 1, 292, 1, 1, 1, 2] @e = ContinuedFraction.for_a { |n| (n + 1) }.for_b { |n| (n + 1) } @a113011 = ContinuedFraction.for_a { |n| 2 * n + 1 }.for_b { |n| 2 * n } @a073333 = ContinuedFraction.for_a { |n| n }.for_b { |n| n } @atan = ContinuedFraction.for_a do |n, x| n == 0 ? 0 : 2 * n - 1 end.for_b do |n, x| n <= 1 ? x : ((n - 1) * x) ** 2 end @pi = lambda { 4 * @atan[1] } end |
#test_continued_fractions ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'tests/continued_fraction_test.rb', line 28 def test_continued_fractions assert @zero[].zero? assert @none1[1].nan? assert @none2[1].nan? assert_in_delta 1.618033, @phi[], 1E-6 assert_in_delta 3.245, @finite[], 1E-4 assert_in_delta Math.sqrt(2), @sqrt_2[], 1E-10 assert_in_delta Math::PI, @pi_finite[], 1E-10 assert_in_delta Math::E, 1 + @e[], 1E-10 assert_in_delta 1.541494, @a113011[], 1E-6 assert_in_delta 0.581976, @a073333[], 1E-6 assert_in_delta Math.atan(0.5), @atan[0.5], 1E-10 assert_in_delta Math::PI, @pi[], 1E-10 end |
#test_invalid_arguments ⇒ Object
43 44 45 46 |
# File 'tests/continued_fraction_test.rb', line 43 def test_invalid_arguments assert_raise(ArgumentError) { ContinuedFraction.for_a } assert_raise(ArgumentError) { ContinuedFraction.for_b } end |
#test_to_proc ⇒ Object
49 50 51 52 53 |
# File 'tests/continued_fraction_test.rb', line 49 def test_to_proc atan = @atan.to_proc assert_kind_of Proc, atan assert_in_delta Math::PI, 4 * atan[1], 1E-10 end |