Sha256: efb49baefa95f322ce6f6df23f92ae48d730bee65430931c61d677bc39bec4b2

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe SPCore::Interpolation do
  context '.linear' do
    it 'should interpolate floating-point values' do
      result = SPCore::Interpolation.linear 2.0, 4.0, 0.5
      result.should eq(3.0)
    end

    it 'should interpolate integer values' do
      result = SPCore::Interpolation.linear 20, 40, 0.5
      result.should eq(30)
    end
  end

  context '.cubic_hermite' do
    it 'should look like...' do
      y0, y1, y2, y3 = 1.75, 1, 0.75, -1.5

      x_ary = []
      y_ary = []

      (0.0..1.0).step(0.05) do |x|
        y = SPCore::Interpolation.cubic_hermite y0, y1, y2, y3, x
        x_ary << x
        y_ary << y
      end

      #Gnuplot.open do |gp|
      #  Gnuplot::Plot.new(gp) do |plot|
      #    plot.title  "interpolated values"
      #    plot.xlabel "x"
      #    plot.ylabel "f(x)"
      #  
      #    plot.data = [            
      #      Gnuplot::DataSet.new( [ x_ary, y_ary ] ) { |ds|
      #        ds.with = "linespoints"
      #        ds.title = "cubic hermite"
      #        ds.linewidth = 1
      #      }
      #    ]
      #  end
      #end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spcore-0.2.1 spec/interpolation/interpolation_spec.rb