class Test_ConstructorChannels(unittest.TestCase): def setUp(self): self.x = Audio(channels=4) print(self.x) def test_str_method(self): self.assertIsInstance(self.x.__str__(), str) def test_channels(self): self.assertEqual(self.x.ch, 4) self.assertEqual(len(self.x), 0) def test_RMS_is_nan(self): print(self.x.rms()) self.assertTrue(np.isnan(self.x.rms()).all()) def test_peak_is_nan(self): peak, idx = self.x.peak() print(peak) print(idx) self.assertTrue(np.isnan(peak).all()) self.assertTrue((idx == 0).all()) def test_crestfactor_is_nan(self): print(self.x.crest_factor()) self.assertTrue(np.isnan(self.x.crest_factor()).all())
class Test_EmptyConstructor(unittest.TestCase): def setUp(self): self.x = Audio() print(self.x) def test_default_constructor(self): self.assertAlmostEqual(self.x.fs, 96000, places=7) self.assertEqual(self.x.ch, 0) self.assertEqual(self.x.nofsamples, 0) self.assertEqual(self.x.duration, 0) self.assertIsInstance(self.x.samples, np.ndarray) def test_str_method(self): self.assertIsInstance(self.x.__str__(), str) def test_empty_comment(self): self.assertSequenceEqual(self.x.comment(), '') def test_add_comment(self): self.assertSequenceEqual(self.x.comment(), '') s = 'This is a comment\nwith a line break' self.x.comment(comment=s) print(self.x) self.assertSequenceEqual(self.x.comment(), s)
def __str__(self): B, A = self._filter_emphasis.get_coefficients() mls_string = _MLS_base.__str__(self) mls_string = "\n".join(mls_string.splitlines()[2:-1]) s = Audio.__str__(self) s += '%s\n' % mls_string s += 'repeats : %i\n' % self.repeats s += 'len(impulse) : %.3f [s]\n' % self._length_impresp s += 'emphasis filt. B : %s\n' % str(B) s += 'emphasis filt. A : %s\n' % str(A) return s
def __str__(self): B, A = self._filter_emphasis.get_coefficients() mls_string = _MLS_base.__str__(self) mls_string = "\n".join(mls_string.splitlines()[2:-1]) s = Audio.__str__(self) s += '%s\n' %mls_string s += 'repeats : %i\n' %self.repeats s += 'len(impulse) : %.3f [s]\n' %self._length_impresp s += 'emphasis filt. B : %s\n' %str(B) s += 'emphasis filt. A : %s\n' %str(A) return s