Sha256: c091d9886d8052bce773bf6f8414a8b807ed50929ae2388cb6ea9a2839dc35aa

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

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

describe Program do
  
  it "should assign the segments given during initialization" do
    segments = [ 0.0...5.0, 0.0...4.0, 5.0...10.0 ]
    program = Program.new segments
    program.segments.should eq(segments.clone)
  end
  
  describe "#include?" do
    it "should return true for any offset which would be encountered" do
      segments = [ 0.0...5.0, 0.0...4.0, 5.0...10.0 ]
      program = Program.new segments
      
      [0.0, 4.0, 5.0, 9.999].each do |offset|
        program.include?(offset).should be_true
      end
    end

    it "should return false for any offset which would not be encountered" do
      segments = [ 0.0...5.0, 0.0...4.0, 5.0...10.0 ]
      program = Program.new segments
      
      [-0.000001, 10.000001].each do |offset|
        program.include?(offset).should be_false
      end
    end
  end
  
  describe "#note_elapsed_at" do
    before :each do
      segments = [ 0.0...5.0, 0.0...4.0, 5.0..10.0 ]
      @program = Program.new segments
    end

    it "should return 0.0 at program start" do
      @program.note_elapsed_at(@program.segments.first.first).should eq(0.0)
    end

    it "should return program length at program stop" do
      @program.note_elapsed_at(@program.segments.last.last).should eq(@program.length)
    end

    it "should return correct note elapsed for any included offset" do
      @program.note_elapsed_at(2.5).should eq(2.5)
      @program.note_elapsed_at(5.5).should eq(9.5)
    end

    it "should raise error if offset is not included" do
      lambda { @program.note_elapsed_at(-0.000001) }.should raise_error
      lambda { @program.note_elapsed_at(10.000001) }.should raise_error
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
music-transcription-0.4.3 spec/program_spec.rb
music-transcription-0.4.2 spec/program_spec.rb
music-transcription-0.4.1 spec/program_spec.rb
music-transcription-0.4.0 spec/program_spec.rb