test/cases/banjo/channel_test.rb in banjo-0.0.4 vs test/cases/banjo/channel_test.rb in banjo-0.0.5
- old
+ new
@@ -1,37 +1,75 @@
require 'test_helper'
class ChannelTest < Test::Unit::TestCase
- def subject
- @subject ||= Banjo::Channel.new(0)
+ def channel
+ @channel ||= Banjo::Channel.new
end
- def test_channel
- assert_equal 0, subject.channel
+ def test_inherited
+ klass = Class.new(Banjo::Channel)
+ assert_includes Banjo::Channel.channels, klass
end
- def test_tick_note_plays
- mock(subject).play_note(15, 50, 0.5)
- subject.tick_note(0, 15)
+ def test_channel
+ assert_equal 0, channel.channel
end
- def test_tick_note_does_not_play
- mock(subject).play_note(15, 50, 0.5).never
- subject.tick_note(3, 15)
+ def test_play
+ note = channel.play(22)
+ assert_equal 22, note.note
+ assert_equal channel, note.channel
+ assert_kind_of Banjo::Note, note
end
- def test_mod_note_when_note_plays
- [0, 4, 8, 12].each do |tick|
- subject.tick = tick
- mock(subject).play_note(15, 50, 0.5)
- subject.mod_note(4, 15)
+ def test_within_plays
+ Banjo.tick = 1
+ called = false
+ channel.within(0, 2) do
+ called = true
end
+
+ assert called, "Given block should be called"
end
- def test_mod_note_when_note_does_not_play
- ((0..15).to_a - [0, 4, 8, 12]).each do |tick|
- subject.tick = tick
- mock(subject).play_note(15, 50, 0.5).never
- subject.mod_note(4, 15)
+ def test_within_does_not_play
+ Banjo.tick = 1
+ called = true
+ channel.within(10, 20) do
+ called = false
end
+
+ assert called, "Given block should not be called"
+ end
+
+ def test_midi_messages
+ assert_equal [0x90, 0x80], channel.midi_messages
+ end
+
+ def test_channels
+ assert_equal [], Banjo::Channel.channels
+ end
+
+ def test_modulation
+ channel.output = stub!
+ mock(channel.output).puts(0xB0, 0x01, 100)
+ channel.modulation(100)
+ end
+
+ def test_pitch
+ channel.output = stub!
+ mock(channel.output).puts(0xE0, 0, 100)
+ channel.pitch(100)
+ end
+
+ def test_sustain
+ channel.output = stub!
+ mock(channel.output).puts(0xB0, 0x40, 100)
+ channel.sustain(100)
+ end
+
+ def test_hush
+ channel.output = stub!
+ mock(channel.output).puts(0xB0, 0x7B, 0)
+ channel.hush
end
end