Class: TestDists

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

Instance Method Summary collapse

Instance Method Details

#setupObject



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

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

#test_add_distObject



134
135
136
137
138
139
140
# File 'lib/tests.rb', line 134

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



149
150
151
152
153
# File 'lib/tests.rb', line 149

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

#test_childrenObject



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/tests.rb', line 181

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



211
212
213
214
215
# File 'lib/tests.rb', line 211

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



217
218
219
220
221
# File 'lib/tests.rb', line 217

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

#test_del_distObject



142
143
144
145
146
147
# File 'lib/tests.rb', line 142

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

#test_del_dist_arrObject



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

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



120
121
122
123
124
125
126
127
128
# File 'lib/tests.rb', line 120

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



129
130
131
132
133
# File 'lib/tests.rb', line 129

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



199
200
201
202
203
204
# File 'lib/tests.rb', line 199

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

#test_notesObject



244
245
246
247
248
249
250
# File 'lib/tests.rb', line 244

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



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/tests.rb', line 163

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



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/tests.rb', line 262

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



193
194
195
196
197
# File 'lib/tests.rb', line 193

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

#test_snd_f_defObject



223
224
225
226
# File 'lib/tests.rb', line 223

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

#test_snd_len_defObject



239
240
241
242
243
# File 'lib/tests.rb', line 239

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



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/tests.rb', line 228

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



206
207
208
209
# File 'lib/tests.rb', line 206

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

#test_toneseq_pushingObject



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/tests.rb', line 251

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