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())
def check_values(self, values, expected, position): x = Audio(fs=10, initialdata=values) peak, idx = x.peak() self.assertTrue(len(peak)==1) self.assertTrue(len(idx)==1) print("index: %3i peak: %f" %(idx, peak)) print(x) self.assertAlmostEqual(peak, expected, places=3) self.assertEqual(idx, position)
def check_values(self, values, expected, position): x = Audio(fs=10, initialdata=values) peak, idx = x.peak() self.assertTrue(len(peak)==2) self.assertTrue(len(idx)==2) print("index: %s peak: %s" %(idx, peak)) print(x) self.assertAlmostEqual(peak[0], expected[0], places=3) self.assertAlmostEqual(peak[1], expected[1], places=3) self.assertEqual(idx[0], position[0]) self.assertEqual(idx[1], position[1])