Class: TestDists

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/tests.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



71
72
73
74
75
76
# File 'lib/tests.rb', line 71

def setup
  @d=Dist.new
  @d2=Dist.new
  @d3=Dist.new
  @d3.length = bar
end

#test_add_distObject



92
93
94
95
96
97
98
# File 'lib/tests.rb', line 92

def test_add_dist
  assert_equal(0, @d.branches)
  @d<<@d2
  assert_equal(1, @d.branches)
  d=0.0.Dist
  assert_equal([0.0], d.hits.hits)
end

#test_add_dist_arrObject



107
108
109
110
111
# File 'lib/tests.rb', line 107

def test_add_dist_arr
  assert_equal(0, @d.branches)
  @d<<[@d3,@d2]
  assert_equal(2, @d.branches)
end

#test_childrenObject



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/tests.rb', line 139

def test_children
  @d2<<1
  @d<<[@d2]
  assert_equal(1, @d.branches)
  assert_equal(1, @d[0].hits.count)
  # can't have a snd
  assert_raise(RuntimeError) {@d<<Snd.new}
  assert_raise(RuntimeError) {@d.snd}
  @d>>[@d2]
  assert_raise(RuntimeError) {@d[0].hits.count}
end

#test_def_hitsObject



169
170
171
172
173
# File 'lib/tests.rb', line 169

def test_def_hits
  d=Dist.new
  assert_equal(0, d.hits.count)
  assert_equal([0.0], d.dist.hits) #default
end

#test_def_tone_lenObject



175
176
177
178
179
# File 'lib/tests.rb', line 175

def test_def_tone_len
  d=10.Dist
  d<< Snd.new
  assert_equal(10, d.snd.tonepart.max_frames)
end

#test_del_distObject



100
101
102
103
104
105
# File 'lib/tests.rb', line 100

def test_del_dist
  assert_equal(0, @d.branches)
  @d<<@d2
  @d>>@d2
  assert_equal(0, @d.branches)
end

#test_del_dist_arrObject



113
114
115
116
117
118
119
# File 'lib/tests.rb', line 113

def test_del_dist_arr
  assert_equal(0, @d.branches)
  @d<<[@d3,@d2]
  assert_equal(2, @d.branches)
  @d>>[@d3,@d2]
  assert_equal(0, @d.branches)
end

#test_dist_child_gettersObject



78
79
80
81
82
83
84
85
86
# File 'lib/tests.rb', line 78

def test_dist_child_getters
   @d << (8.Dist << 0.5 << 300.Snd)
   @d.last_born.snd.length= 10
   assert_equal([0.5], @d.last_born.hits.hits)
   assert_equal(1, @d.last_born.snd.count)
   # persist?
   @d.last_born << 0.6
   assert_equal([0.5,0.6], @d.last_born.hits.hits)
end

#test_dist_default_hit_0Object



87
88
89
90
91
# File 'lib/tests.rb', line 87

def test_dist_default_hit_0
  dist = 50_000.Dist
  assert_equal(1, dist.dist.hits.count)
  assert_equal(0, dist.hits.count)
end

#test_lenObject



157
158
159
160
161
162
# File 'lib/tests.rb', line 157

def test_len
  d=10.Dist
  assert_equal(10, d.length)
  d.length = 100
  assert_equal(100, d.length)
end

#test_notesObject



202
203
204
205
206
207
208
# File 'lib/tests.rb', line 202

def test_notes
  snd = Note.new(0,5).Snd
  assert_equal(440, snd.tonepart.freq)
  assert_equal(Note.new(0,5).freq, snd.tonepart.note.freq)
  snd = Note.new("c#",5)
  assert_equal(4, snd.note)
end

#test_persistenceObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/tests.rb', line 121

def test_persistence
  assert_equal(0, @d2.hits.count)
  @d2<<1
  assert_equal(1, @d2.hits.count)
  @d2<<[0.7,0.8]
  assert_equal(3, @d2.hits.count)
  h=@d2.hits
  h<<0.1
  assert_equal(4, @d2.hits.count)
  h<<0.2
  assert_equal(5, @d2.hits.count)
  h>>0.2
  assert_equal(4, @d2.hits.count)
  @d2>>[0.1,0.8]
  # still persists
  assert_equal(2, @d2.hits.count)
end

#test_scaleObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/tests.rb', line 220

def test_scale
  Composer.scale = "mixolydian"
  notes = scale_notes
  assert_equal(7, notes.count)
  assert_equal([0,2,4,5,7,9,10], notes)
  
  snd = Snd.new
  snd.length= beat
  @d3<< snd
  @d3.make(6)
  7.times do |i|
    newn = Note.new(notes[i], 4)
    @d3.snd.tonepart(i).note= newn
  end
  assert_equal(392, @d3.snd.tonepart(6).freq.round)
  assert_equal(277, @d3.snd.tonepart(2).freq.round)
end

#test_sndObject



151
152
153
154
155
# File 'lib/tests.rb', line 151

def test_snd
  assert_equal(0, @d.sounds)
  @d<<Snd.new
  assert_equal(1, @d.sounds)
end

#test_snd_f_defObject



181
182
183
184
# File 'lib/tests.rb', line 181

def test_snd_f_def
  s=20.0.Snd
  assert_equal(20, s.tonepart.freq)
end

#test_snd_len_defObject



197
198
199
200
201
# File 'lib/tests.rb', line 197

def test_snd_len_def
  snd = 155.Snd
  @d3<<snd
  assert_equal(bar, snd.tone.frames) # if 0 uses full
end

#test_snd_len_distObject



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/tests.rb', line 186

def test_snd_len_dist
  snd = 155.Snd
  snd.length= beat
  assert_equal(beat, snd.tone.frames)
  assert_equal(0, snd.tonepart.max_frames)
  snd.length= 0
  snd.length= beat
  @d3<<snd
  assert_equal(bar, snd.tonepart.max_frames)
  assert_equal(beat, snd.tone.frames) # kept, not 0
end

#test_snddefsObject



164
165
166
167
# File 'lib/tests.rb', line 164

def test_snddefs
  s=20.Snd
  assert_equal(20, s.tone.freq.start)
end

#test_toneseq_pushingObject



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/tests.rb', line 209

def test_toneseq_pushing
  @d3 << Note.new(0,5).Snd
  @d3.snd.length= beat
  assert_equal(beat, @d3.snd.tone.frames)
  @d3.make(1)
  assert_equal(2, @d3.snd.toneseq.toneparts.count)
  assert_equal(beat/2, @d3.snd.tone.frames) # made 2, frames should be half
  @d3.make(2)
  assert_equal(4, @d3.snd.toneseq.toneparts.count)
  assert_equal(beat/4, @d3.snd.tone.frames) # made 4, frames should be 1/4
end