- self.assertEqual (alpha_norm(a, 1), 0)
- a[0] = 1
- self.assertEqual (alpha_norm(a, 1), 0.5)
- a[1] = 1
- self.assertEqual (alpha_norm(a, 1), 1)
- a = array([0, 1], dtype=float_type)
- assert_almost_equal (alpha_norm(a, 2), .5*2.**.5)
-
- def test_alpha_norm_of_none(self):
- self.assertRaises (ValueError, alpha_norm, None, 1)
-
- def test_alpha_norm_of_array_of_float32(self):
- # check scalar fails
- a = array(1, dtype = float_type)
- self.assertRaises (ValueError, alpha_norm, a, 1)
- # check 2d array fails
- a = array([[2],[4]], dtype = float_type)
- self.assertRaises (ValueError, alpha_norm, a, 1)
- # check 1d array
- a = array(range(10), dtype = float_type)
- self.assertEqual (alpha_norm(a, 1), 4.5)
-
- def test_alpha_norm_of_array_of_int(self):
- a = array(1, dtype = 'int')
- self.assertRaises (ValueError, alpha_norm, a, 1)
- a = array([[[1,2],[3,4]]], dtype = 'int')
- self.assertRaises (ValueError, alpha_norm, a, 1)
- a = array(range(10), dtype = 'int')
- self.assertRaises (ValueError, alpha_norm, a, 1)
-
- def test_alpha_norm_of_array_of_string (self):
- a = "hello"
- self.assertRaises (ValueError, alpha_norm, a, 1)
+ self.assertRaises(IndexError, a.__getitem__, 3)
+ self.assertRaises(IndexError, a.__getitem__, 2)
+
+class aubio_wrong_fvec_input(TestCase):
+ """ uses min_removal to test PyAubio_IsValidVector """
+
+ def test_no_input(self):
+ self.assertRaises(TypeError, min_removal)
+
+ def test_none(self):
+ self.assertRaises(ValueError, min_removal, None)
+
+ def test_wrong_scalar(self):
+ a = np.array(10, dtype=float_type)
+ self.assertRaises(ValueError, min_removal, a)
+
+ def test_wrong_dimensions(self):
+ a = np.array([[[1, 2], [3, 4]]], dtype=float_type)
+ self.assertRaises(ValueError, min_removal, a)
+
+ def test_wrong_array_size(self):
+ x = np.array([], dtype=float_type)
+ self.assertRaises(ValueError, min_removal, x)
+
+ def test_wrong_type(self):
+ a = np.zeros(10, dtype=wrong_type)
+ self.assertRaises(ValueError, min_removal, a)
+
+ def test_wrong_list_input(self):
+ self.assertRaises(ValueError, min_removal, [0., 1.])
+
+ def test_good_input(self):
+ a = np.zeros(10, dtype=float_type)
+ assert_equal(np.zeros(10, dtype=float_type), min_removal(a))
+
+class aubio_alpha_norm(TestCase):
+
+ def test_alpha_norm_of_random(self):
+ x = np.random.rand(1024).astype(float_type)
+ alpha = np.random.rand() * 5.
+ x_alpha_norm = (np.sum(np.abs(x)**alpha)/len(x))**(1/alpha)
+ assert_almost_equal(alpha_norm(x, alpha), x_alpha_norm)
+
+class aubio_zero_crossing_rate_test(TestCase):