def test_init_duration_to_affect_per_sample(self): # one sample m = basic_wave.Modifier(frequency=440) self.assertEqual(440, m.frequency) # all samples m = basic_wave.Modifier(frequency=440, duration=-1) self.assertEqual(440 / basic_wave.FRAMERATE, m.frequency) # a few samples m = basic_wave.Modifier(frequency=440, phi=3.4, magnitude=0.56, offset=0.78, duration=1.3) self.assertEqual(440 / (basic_wave.FRAMERATE * 1.3), m.frequency) self.assertEqual(3.4 / (basic_wave.FRAMERATE * 1.3), m.phi) self.assertEqual(0.56 / (basic_wave.FRAMERATE * 1.3), m.magnitude) self.assertEqual(0.78 / (basic_wave.FRAMERATE * 1.3), m.offset) m = basic_wave.Modifier(frequency=440, phi=3.4, magnitude=0.56, offset=0.78, duration=0.75) self.assertEqual(440 / (basic_wave.FRAMERATE * 0.75), m.frequency) self.assertEqual(3.4 / (basic_wave.FRAMERATE * 0.75), m.phi) self.assertEqual(0.56 / (basic_wave.FRAMERATE * 0.75), m.magnitude) self.assertEqual(0.78 / (basic_wave.FRAMERATE * 0.75), m.offset)
def test_modify_no_swap(self): a = basic_wave.BasicWave(440, 42, 0.63, 0.87) m = basic_wave.Modifier(frequency=100, phi=10, magnitude=1, offset=0.1) a.add_modifier(m) a.play() self.assertEqual(540, a.frequency) self.assertEqual(52, a.phi) self.assertEqual(1.63, a.magnitude) self.assertEqual(0.97, a.offset)
def test_init_swap_value(self): m = basic_wave.Modifier(frequency=12, phi=3.4, magnitude=0.56, offset=0.78, swap=True) self.assertEqual(12, m.frequency) self.assertEqual(3.4, m.phi) self.assertEqual(0.56, m.magnitude) self.assertEqual(0.78, m.offset)
def test_modify_incremental_change(self): a = basic_wave.BasicWave(440, 42, 0.63, 0.87) m = basic_wave.Modifier(frequency=100, phi=10, magnitude=1, offset=0.1, duration=0.2) a.add_modifier(m) a.play() self.assertEqual(440 + 100 / (basic_wave.FRAMERATE * 0.2), a.frequency) self.assertEqual(42 + 10 / (basic_wave.FRAMERATE * 0.2), a.phi) self.assertEqual(0.63 + 1 / (basic_wave.FRAMERATE * 0.2), a.magnitude) self.assertEqual(0.87 + 0.1 / (basic_wave.FRAMERATE * 0.2), a.offset)
def test_init_modifier_value(self): # continues mod = basic_wave.Modifier(frequency=4.81, phi=5.16, magnitude=2.3, offset=4, start=0, duration=-1) self.assertEqual(4.81 / basic_wave.FRAMERATE, mod.frequency) self.assertEqual(5.16 / basic_wave.FRAMERATE, mod.phi) self.assertEqual(2.3 / basic_wave.FRAMERATE, mod.magnitude) self.assertEqual(4 / basic_wave.FRAMERATE, mod.offset) self.assertEqual(0, mod.affected_sample) # single mod = basic_wave.Modifier(frequency=4.81, phi=5.16, magnitude=2.3, offset=4, start=2) self.assertEqual(4.81, mod.frequency) self.assertEqual(5.16, mod.phi) self.assertEqual(2.3, mod.magnitude) self.assertEqual(4, mod.offset) self.assertEqual(2 * basic_wave.FRAMERATE, mod.affected_sample)
def test_init_swap_state(self): m = basic_wave.Modifier(swap=True) self.assertEqual(True, m.swap)
def test_init_duration_and_swap(self): with self.assertRaises(NotImplementedError): basic_wave.Modifier(duration=1, swap=True)
def test_init_start_at_second_x(self): m = basic_wave.Modifier(start=5) self.assertEqual(5 * basic_wave.FRAMERATE, m.affected_sample)
def test_init_start_immediate(self): m = basic_wave.Modifier() self.assertEqual(0, m.affected_sample)
def test_init_duration_a_few_seconds(self): m = basic_wave.Modifier(duration=5) self.assertEqual(5 * basic_wave.FRAMERATE, m.duration_left)
def test_add_modifier(self): a = basic_wave.BasicWave(440, pi / 2, 0.63, 0.87) self.assertEqual(0, len(a.modifiers)) m = basic_wave.Modifier() a.add_modifier(m) self.assertEqual(1, len(a.modifiers))
def test_init_duration_one_time(self): m = basic_wave.Modifier() self.assertEqual(1, m.duration_left)
def test_init_duration_endless(self): m = basic_wave.Modifier(duration=-1) self.assertEqual(-1, m.duration_left)