Sha256: 00ec931fb3d1a4ae751e37d83d701fc188a490255063aec1744fa6d069742001

Contents?: true

Size: 588 Bytes

Versions: 3

Compression:

Stored size: 588 Bytes

Contents

require File.join(File.dirname(__FILE__), 'test_helper.rb')
require File.join(File.dirname(__FILE__), 'extensions.rb')

require 'cartesian/grid_search'

class TestCartesian < Test::Unit::TestCase
  def test_argmin
    assert_equal 0, *[-1,0,1].argmin {|x| x**2 }
    assert_equal [0,0], ((-3..3)**2).argmin {|x,y| x**2+y**2 }
  end

  def test_argmax
    assert_equal 0, *[-2,-1,0].argmax {|x| x**3 }
    values = []
    -3.step(3, 0.25) {|val| values << val }
    x, y = (values**2).argmax {|x,y| x**2+y**2 }
    assert x.among?([-3,3])
    assert y.among?([-3,3])
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cartesian-0.5.3 test/test_grid_search.rb
cartesian-0.5.2 test/test_grid_search.rb
cartesian-0.5.0 test/test_grid_search.rb