Sha256: a8690e1d86e0c19c6df7e0a031a2d031350d54dee0454f445ba4a8ac34131034

Contents?: true

Size: 891 Bytes

Versions: 16

Compression:

Stored size: 891 Bytes

Contents

#!/usr/bin/env ruby

require 'test_helper'
require 'more_math'

class NewtonBisectionTest < Test::Unit::TestCase
  include MoreMath

  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

  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
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
more_math-1.3.0 tests/newton_bisection_test.rb
more_math-1.2.2 tests/newton_bisection_test.rb
more_math-1.2.1 tests/newton_bisection_test.rb
more_math-1.2.0 tests/newton_bisection_test.rb
more_math-1.1.0 tests/newton_bisection_test.rb
more_math-1.0.2 tests/newton_bisection_test.rb
more_math-1.0.1 tests/newton_bisection_test.rb
more_math-1.0.0 tests/newton_bisection_test.rb
more_math-0.4.0 tests/newton_bisection_test.rb
more_math-0.3.3 tests/newton_bisection_test.rb
more_math-0.3.2 tests/newton_bisection_test.rb
more_math-0.3.1 tests/newton_bisection_test.rb
more_math-0.3.0 tests/newton_bisection_test.rb
more_math-0.2.1 tests/newton_bisection_test.rb
more_math-0.1.0 tests/newton_bisection_test.rb
more_math-0.0.4 tests/newton_bisection_test.rb