Skip to content

Commit

Permalink
Add test for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmacphersonmusic committed May 18, 2015
1 parent 3e315b4 commit a4caae5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,31 @@ def setup
@frequency = 220.to_f
@duration = 2.0
@sample_rate = 22050
@total_frames = (@duration * @sample_rate).to_i
@cycles_per_frame = @frequency / @sample_rate
@sine_wave_cycle = 2 * Math::PI * @cycles_per_frame
@note = MusicTheory::Note.new(frequency: @frequency, duration: @duration)
end

def test_total_frames
frames = (@duration * @sample_rate).to_i
assert_equal frames, @note.total_frames
assert_equal @total_frames, @note.total_frames
end

def test_cycles_per_frame
assert_equal @cycles_per_frame, @note.cycles_per_frame
end

def test_sine_wave_cycle
sine_wave_cycle = 2 * Math::PI * @cycles_per_frame
assert_equal sine_wave_cycle, @note.sine_wave_cycle
assert_equal @sine_wave_cycle, @note.sine_wave_cycle
end

def test_samples
phase = 0
samples = @total_frames.times.map do
sample = (Math.sin phase).to_f
phase += @sine_wave_cycle
sample
end
assert_equal samples, @note.samples
end
end

0 comments on commit a4caae5

Please sign in to comment.