test/test_all.rb in interpolate-0.2.3 vs test/test_all.rb in interpolate-0.2.4
- old
+ new
@@ -1,17 +1,17 @@
-#!/usr/bin/env ruby1.8 -w
+#!/usr/bin/env ruby
require 'test/unit'
-require 'lib/interpolate'
+require 'interpolate'
class InterpolationTest < Test::Unit::TestCase
-
+ # acceptable delta; floating point values won't be exact
DELTA = 1e-7
def setup
- @decimal_points = {
+ decimal_points = {
0 => 0,
1 => 0.1,
2 => 0.2,
3 => 0.3,
4 => 0.4,
@@ -21,32 +21,33 @@
8 => 0.8,
9 => 0.9,
10 => 1
}.freeze
- @array_points = {
+ array_points = {
100 => [1, 10, 100],
200 => [5, 50, 500],
500 => [10, 100, 1000]
}.freeze
- @dec_gradient = Interpolation.new(@decimal_points).freeze
- @array_gradient = Interpolation.new(@array_points).freeze
+ @dec_gradient = Interpolation.new(decimal_points).freeze
+ @array_gradient = Interpolation.new(array_points).freeze
end
- def test_bad_point
+
+ def test_bad_points
bad_points = {
0 => 4.2,
1 => "hello", # not allowed by default
2 => 3.4,
3 => 4.8
}
- gradient = Interpolation.new(bad_points)
assert_raise ArgumentError do
- gradient.at(1.5)
+ gradient = Interpolation.new(bad_points)
end
+
end
def test_lower_bounds
assert_equal(@dec_gradient.at(0), 0)
assert_equal(@dec_gradient.at(-1), 0)
@@ -129,33 +130,9 @@
def test_array_values
assert_equal(@array_gradient.at(150), [3, 30, 300])
assert_equal(@array_gradient.at(200), [5, 50, 500])
assert_equal(@array_gradient.at(350), [7.5, 75, 750])
- end
-
- def test_given_block_left
- gradient = Interpolation.new(@decimal_points) {|l, r, bal| l}
- assert_in_delta(gradient.at(1.5), 0.1, DELTA)
- assert_in_delta(gradient.at(2.5), 0.2, DELTA)
- assert_in_delta(gradient.at(3.5), 0.3, DELTA)
- end
-
- def test_given_block_right
- gradient = Interpolation.new(@decimal_points) {|l, r, bal| r}
- assert_in_delta(gradient.at(1.5), 0.2, DELTA)
- assert_in_delta(gradient.at(2.5), 0.3, DELTA)
- assert_in_delta(gradient.at(3.5), 0.4, DELTA)
- end
-
- def test_given_block_mean_squared
- # squared balance, not linear
- gradient = Interpolation.new(@decimal_points) do |l, r, bal|
- l + ((r - l).to_f * bal * bal)
- end
- assert_in_delta(gradient.at(1.5), 0.12500, DELTA)
- assert_in_delta(gradient.at(2.75), 0.25625, DELTA)
- assert_in_delta(gradient.at(3.99), 0.39801, DELTA)
end
def test_frozen_points
a = @array_gradient.at(200)
assert_nothing_raised RuntimeError do