Class: NewtonBisectionTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
MoreMath
Defined in:
tests/newton_bisection_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

Instance Method Details

#test_bracketObject



9
10
11
12
13
14
15
16
17
18
19
# File 'tests/newton_bisection_test.rb', line 9

def test_bracket
  solver = NewtonBisection.new { |x| x ** 2 - 3 }
  assert_raises(ArgumentError) { solver.bracket(1..1) }
  assert_raises(ArgumentError) { solver.bracket(1..-1) }
  range = solver.bracket(0..0.1)
  assert_in_delta range.first, 0, 1E-6
  assert_in_delta range.last, 1.7576, 1E-6
  range = solver.bracket(2..3)
  assert_in_delta range.first, 0.4, 1E-6
  assert_in_delta range.last, 3, 1E-6
end

#test_zeroObject



21
22
23
24
25
26
27
# File 'tests/newton_bisection_test.rb', line 21

def test_zero
  solver = NewtonBisection.new { |x| x ** 2 - 3 }
  assert_in_delta 1.73205, solver.solve, 1E-6
  assert_in_delta(-1.73205, solver.solve(-5..-1), 1E-6)
  assert_in_delta 1.73205, solver.solve(solver.bracket(0..0.1)), 1E-6
  assert_in_delta 1.73205, solver.solve(solver.bracket(2..3)), 1E-6
end