Sha256: 30d479131860d4f9b72669a9467c6b61e5831bc80a5dc03239fa3e65ba29538c

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

#!/usr/bin/env ruby

require 'test/unit'
require 'bullshit'

class TestNewtonBisection < Test::Unit::TestCase
  include Bullshit

  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

3 entries across 3 versions & 2 rubygems

Version Path
flori-bullshit-0.1.0 tests/test_newton_bisection.rb
bullshit-0.1.1 tests/test_newton_bisection.rb
bullshit-0.1.0 tests/test_newton_bisection.rb