Sha256: 0d15b09dc345fecebde752b1d17f591d2e6b7db2622e2fe0887bf1af344f89d7

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

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

describe SPCore::Calculus do
  before :all do
    sample_rate = 200
    @sample_period = 1.0 / sample_rate
    sample_count = sample_rate
    
    range = -Math::PI..Math::PI
    delta = (range.max - range.min) / sample_count
    
    @sin = []
    @cos = []
    
    range.step(delta) do |x|
      @sin << Math::sin(x)
      @cos << (Math::PI * 2 * Math::cos(x))
    end
  end
  
  describe '.derivative' do
    before :all do
      @expected = @cos
      @actual = Calculus.derivative @sin, @sample_period
    end
    
    it 'should produce a signal of same size' do
      @actual.size.should eq @expected.size
    end
    
    it 'should produce a signal matching the 1st derivative' do
      @actual.each_index do |i|
        @actual[i].should be_within(0.1).of(@expected[i])
      end
    end
  end

  describe '.integral' do
    before :all do
      @expected = @sin
      @actual = Calculus.integral @cos, @sample_period
    end
    
    it 'should produce a signal of same size' do
      @actual.size.should eq @expected.size
    end
    
    it 'should produce a signal matching the 1st derivative' do
      @actual.each_index do |i|
        @actual[i].should be_within(0.1).of(@expected[i])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spcore-0.2.1 spec/analysis/calculus_spec.rb