Skip to content

Commit

Permalink
Push faulty test for review
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmacphersonmusic committed May 21, 2015
1 parent 745f8c7 commit 2ad3cd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 16 additions & 3 deletions lib/music_theory/note.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# coding: utf-8
require 'music_theory/output'
require 'music_theory/pitch'

module MusicTheory
class Note
include MusicTheory::Output
attr_accessor :frequency, :duration, :output_file_name, :distort

def initialize(options = {})
@frequency = options[:frequency] || 440.0 # Note frequency in Hz
@frequency = @frequency.to_f
@frequency = interpret_frequency_or_pitch_object(options[:frequency])

This comment has been minimized.

Copy link
@scottmacphersonmusic

scottmacphersonmusic May 21, 2015

Author Owner

What confuses me here is that even before I substituted the above line, MusicTheory::Note.new(frequency: 493.883, duration: 1.0, distort: false) from implement_pitch_test.rb was evaluating to Nil.

@duration = options[:duration] || 1.0 # Number of seconds per note
@distort = options[:distort] || false
@output_file_name = options[:output_file_name] || 'note' # File name to write (without extension)
Expand Down Expand Up @@ -53,6 +53,19 @@ def distort!(samples)
end
end

end
private

def interpret_frequency_or_pitch_object(frequency_option)
if frequency_option.class == Pitch
puts "its a Pitch object!!"
return frequency_option.frequency
elsif frequency_option == Float
return frequency_option
elsif frequency_option == Integer
return frequency_option.to_f
else
return 440.0
end
end
end
end
5 changes: 4 additions & 1 deletion test/implement_pitch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

class TestNote < MiniTest::Test
def setup
# @pitch_object_note = MusicTheory::Note.new(frequency: (:B, 4), duration: 1.0, distort: false)
@pitch_object_note = MusicTheory::Note.new(frequency: Pitch.new(:B, 4), duration: 1.0, distort: false)
@frequency_note = MusicTheory::Note.new(frequency: 493.883, duration: 1.0, distort: false)
end

def test_note_accepts_pitch_object_input
# assert_equal @pitch_object_note.sine_wave_cycle, @frequency_note.sine_wave_cycle
puts @pitch_object_note.class

This comment has been minimized.

Copy link
@scottmacphersonmusic

scottmacphersonmusic May 21, 2015

Author Owner

At first I wrote assert_equal @pitch_object_note, @frequency_note, and was confused as to why that test was passing. By putsing the class of @pitch_object_note and @frequency_note I learned that they were both Nil objects.

puts @frequency_note.class

This comment has been minimized.

Copy link
@scottmacphersonmusic

scottmacphersonmusic May 21, 2015

Author Owner

@bion such confuse - how are these both Nil? Even before I replaced MusicTheory::Note @frequency's "options[:frequency || 440.0" with interpret_frequency_or_pitch_object I was getting Nil for @pitch_object_note and @frequency note.

end
end

0 comments on commit 2ad3cd3

Please sign in to comment.