Class: TestDists

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

Instance Method Summary collapse

Instance Method Details

#setupObject



109
110
111
112
113
114
# File 'lib/tests.rb', line 109

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

#test_add_distObject



130
131
132
133
134
135
136
# File 'lib/tests.rb', line 130

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



145
146
147
148
149
# File 'lib/tests.rb', line 145

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

#test_childrenObject



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/tests.rb', line 177

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



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

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



213
214
215
216
217
# File 'lib/tests.rb', line 213

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

#test_del_distObject



138
139
140
141
142
143
# File 'lib/tests.rb', line 138

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

#test_del_dist_arrObject



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

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



116
117
118
119
120
121
122
123
124
# File 'lib/tests.rb', line 116

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



125
126
127
128
129
# File 'lib/tests.rb', line 125

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



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

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

#test_notesObject



240
241
242
243
244
245
246
# File 'lib/tests.rb', line 240

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/tests.rb', line 159

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



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/tests.rb', line 258

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



189
190
191
192
193
# File 'lib/tests.rb', line 189

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

#test_snd_f_defObject



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

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

#test_snd_len_defObject



235
236
237
238
239
# File 'lib/tests.rb', line 235

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



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/tests.rb', line 224

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



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

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

#test_toneseq_pushingObject



247
248
249
250
251
252
253
254
255
256
257
# File 'lib/tests.rb', line 247

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