Skip to content
Snippets Groups Projects
Commit f29599ab authored by Valentin Emiya's avatar Valentin Emiya
Browse files

update tests

parent 3beaf654
No related branches found
No related tags found
No related merge requests found
Pipeline #14338 passed
...@@ -65,8 +65,7 @@ import unittest ...@@ -65,8 +65,7 @@ import unittest
import random import random
import numpy as np import numpy as np
from ltfatpy.comp.assert_sigreshape_pre import assert_sigreshape_pre as aspre from ltfatpy.comp.assert_sigreshape_pre import assert_sigreshape_pre as aspre
from ltfatpy.comp.assert_sigreshape_post import assert_sigreshape_post\ from ltfatpy.comp.assert_sigreshape_post import assert_sigreshape_post as aspost
as aspost
import functools import functools
...@@ -74,16 +73,16 @@ class TestAssertSigReshapePost(unittest.TestCase): ...@@ -74,16 +73,16 @@ class TestAssertSigReshapePost(unittest.TestCase):
# Called before the tests. # Called before the tests.
def setUp(self): def setUp(self):
print('Start TestAssertSigReshapePost') print("Start TestAssertSigReshapePost")
# Called after the tests. # Called after the tests.
def tearDown(self): def tearDown(self):
print('Test done') print("Test done")
def test_default(self): def test_default(self):
""" Basic usual cases """ """Basic usual cases"""
L = random.randint(5, 200) L = random.randint(5, 200)
f = np.arange(0, L, dtype=np.float_) f = np.arange(0, L, dtype=np.float64)
(g, L, Ls, W, dim, permutedshape, order) = aspre(f) (g, L, Ls, W, dim, permutedshape, order) = aspre(f)
fres = aspost(f, dim, permutedshape, order) fres = aspost(f, dim, permutedshape, order)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = " mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
...@@ -93,10 +92,10 @@ class TestAssertSigReshapePost(unittest.TestCase): ...@@ -93,10 +92,10 @@ class TestAssertSigReshapePost(unittest.TestCase):
np.testing.assert_array_equal(f, fres, mess) np.testing.assert_array_equal(f, fres, mess)
def test_twodim(self): def test_twodim(self):
""" Many channels signals """ """Many channels signals"""
shapef = tuple([random.randint(5, 20) for _ in range(2)]) shapef = tuple([random.randint(5, 20) for _ in range(2)])
L = functools.reduce(lambda x, y: x*y, shapef) L = functools.reduce(lambda x, y: x * y, shapef)
f = np.arange(0, L, dtype=np.complex_) f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef) f = f.reshape(shapef)
(g, L, Ls, W, dim, permutedshape, order) = aspre(f) (g, L, Ls, W, dim, permutedshape, order) = aspre(f)
fres = aspost(f, dim, permutedshape, order) fres = aspost(f, dim, permutedshape, order)
...@@ -106,7 +105,7 @@ class TestAssertSigReshapePost(unittest.TestCase): ...@@ -106,7 +105,7 @@ class TestAssertSigReshapePost(unittest.TestCase):
mess = mess.format(L, Ls, W, dim) mess = mess.format(L, Ls, W, dim)
np.testing.assert_array_equal(f, fres, mess) np.testing.assert_array_equal(f, fres, mess)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase( if __name__ == "__main__":
TestAssertSigReshapePost) suite = unittest.TestLoader().loadTestsFromTestCase(TestAssertSigReshapePost)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -72,16 +72,16 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -72,16 +72,16 @@ class TestAssertSigReshapePre(unittest.TestCase):
# Called before the tests. # Called before the tests.
def setUp(self): def setUp(self):
print('Start TestAssertSigReshapePre') print("Start TestAssertSigReshapePre")
# Called after the tests. # Called after the tests.
def tearDown(self): def tearDown(self):
print('Test done') print("Test done")
def test_default(self): def test_default(self):
""" Basic usual cases """ """Basic usual cases"""
L = random.randint(5, 200) L = random.randint(5, 200)
f = np.arange(0, L, dtype=np.float_) f = np.arange(0, L, dtype=np.float64)
(g, L, Ls, W, dim, _permutedshape, _order) = asp(f) (g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = " mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
mess += str(g.shape) + ", f.shape = " + str(f.shape) mess += str(g.shape) + ", f.shape = " + str(f.shape)
...@@ -102,7 +102,7 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -102,7 +102,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(dim, 0, mess) self.assertEqual(dim, 0, mess)
def test_list(self): def test_list(self):
""" Basic signal in a list """ """Basic signal in a list"""
L = random.randint(5, 200) L = random.randint(5, 200)
f = [x for x in range(0, L)] f = [x for x in range(0, L)]
(g, L, Ls, W, dim, _permutedshape, _order) = asp(f) (g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
...@@ -113,16 +113,16 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -113,16 +113,16 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(L, L, mess) self.assertEqual(L, L, mess)
self.assertEqual(W, 1, mess) self.assertEqual(W, 1, mess)
self.assertEqual(dim, 0, mess) self.assertEqual(dim, 0, mess)
self.assertRaises(TypeError, asp, {'a': 1}) self.assertRaises(TypeError, asp, {"a": 1})
self.assertRaises(TypeError, asp, f, L, (1, 0)) self.assertRaises(TypeError, asp, f, L, (1, 0))
self.assertRaises(TypeError, asp, f, L, -4) self.assertRaises(TypeError, asp, f, L, -4)
self.assertRaises(TypeError, asp, f, 5.5) self.assertRaises(TypeError, asp, f, 5.5)
def test_twodim(self): def test_twodim(self):
""" Many channels signals """ """Many channels signals"""
shapef = tuple([random.randint(5, 20) for _ in range(2)]) shapef = tuple([random.randint(5, 20) for _ in range(2)])
L = functools.reduce(lambda x, y: x*y, shapef) L = functools.reduce(lambda x, y: x * y, shapef)
f = np.arange(0, L, dtype=np.complex_) f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef) f = f.reshape(shapef)
(g, L, Ls, W, dim, _permutedshape, _order) = asp(f) (g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = " mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
...@@ -133,7 +133,7 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -133,7 +133,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(W, shapef[1], mess) self.assertEqual(W, shapef[1], mess)
self.assertEqual(dim, 0, mess) self.assertEqual(dim, 0, mess)
L = random.randint(5, 200) L = random.randint(5, 200)
f = np.arange(0, L, dtype=np.float_) f = np.arange(0, L, dtype=np.float64)
fcol = f.reshape((1, L)) fcol = f.reshape((1, L))
(g, L, Ls, W, dim, _permutedshape, _order) = asp(fcol) (g, L, Ls, W, dim, _permutedshape, _order) = asp(fcol)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = " mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
...@@ -145,7 +145,6 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -145,7 +145,6 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(dim, 1, mess) self.assertEqual(dim, 1, mess)
if __name__ == '__main__': if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase( suite = unittest.TestLoader().loadTestsFromTestCase(TestAssertSigReshapePre)
TestAssertSigReshapePre)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -73,11 +73,11 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -73,11 +73,11 @@ class TestCompSigReshape(unittest.TestCase):
# Called before the tests. # Called before the tests.
def setUp(self): def setUp(self):
print('Start TestCompSigReshape') print("Start TestCompSigReshape")
# Called after the tests. # Called after the tests.
def tearDown(self): def tearDown(self):
print('Test done') print("Test done")
def test_default(self): def test_default(self):
self.assertRaises(ValueError, cpre, "toto", 10) self.assertRaises(ValueError, cpre, "toto", 10)
...@@ -85,9 +85,9 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -85,9 +85,9 @@ class TestCompSigReshape(unittest.TestCase):
self.assertRaises(ValueError, cpre, np.ones((10, 10, 2)), 1) self.assertRaises(ValueError, cpre, np.ones((10, 10, 2)), 1)
def test_onedim(self): def test_onedim(self):
""" One channel """ """One channel"""
L = random.randint(5, 200) L = random.randint(5, 200)
f = np.arange(0, L, dtype=np.float_) f = np.arange(0, L, dtype=np.float64)
(fin, fl, W, wasrow, remembershape) = cpre(f, 0) (fin, fl, W, wasrow, remembershape) = cpre(f, 0)
fres = cpost(fin, fl, wasrow, remembershape) fres = cpost(fin, fl, wasrow, remembershape)
mess = "\nfl = {:d}, W = {:d}, wasrow = {:d},remembershape.shape = " mess = "\nfl = {:d}, W = {:d}, wasrow = {:d},remembershape.shape = "
...@@ -96,7 +96,7 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -96,7 +96,7 @@ class TestCompSigReshape(unittest.TestCase):
mess = mess.format(fl, W, wasrow) mess = mess.format(fl, W, wasrow)
np.testing.assert_array_equal(f, fres, mess) np.testing.assert_array_equal(f, fres, mess)
L = random.randint(5, 200) L = random.randint(5, 200)
f = np.arange(0, L, dtype=np.float_) f = np.arange(0, L, dtype=np.float64)
f.resize((1, L)) f.resize((1, L))
(fin, fl, W, wasrow, remembershape) = cpre(f, 0) (fin, fl, W, wasrow, remembershape) = cpre(f, 0)
fres = cpost(fin, fl, wasrow, remembershape) fres = cpost(fin, fl, wasrow, remembershape)
...@@ -107,10 +107,10 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -107,10 +107,10 @@ class TestCompSigReshape(unittest.TestCase):
np.testing.assert_array_equal(f, fres, mess) np.testing.assert_array_equal(f, fres, mess)
def test_twodim(self): def test_twodim(self):
""" Many channels signals """ """Many channels signals"""
shapef = tuple([random.randint(5, 20) for _ in range(2)]) shapef = tuple([random.randint(5, 20) for _ in range(2)])
L = functools.reduce(lambda x, y: x*y, shapef) L = functools.reduce(lambda x, y: x * y, shapef)
f = np.arange(0, L, dtype=np.complex_) f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef) f = f.reshape(shapef)
(fin, fl, W, wasrow, remembershape) = cpre(f, 1) (fin, fl, W, wasrow, remembershape) = cpre(f, 1)
fres = cpost(fin, fl, wasrow, remembershape) fres = cpost(fin, fl, wasrow, remembershape)
...@@ -121,10 +121,10 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -121,10 +121,10 @@ class TestCompSigReshape(unittest.TestCase):
np.testing.assert_array_equal(f, fres, mess) np.testing.assert_array_equal(f, fres, mess)
def test_multidim(self): def test_multidim(self):
""" Multidimensionnal signals """ """Multidimensionnal signals"""
shapef = tuple([random.randint(5, 20) for _ in range(4)]) shapef = tuple([random.randint(5, 20) for _ in range(4)])
L = np.prod(shapef) L = np.prod(shapef)
f = np.arange(0, L, dtype=np.complex_) f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef) f = f.reshape(shapef)
(fin, fl, W, wasrow, remembershape) = cpre(f, 5) (fin, fl, W, wasrow, remembershape) = cpre(f, 5)
fres = cpost(fin, fl, wasrow, remembershape) fres = cpost(fin, fl, wasrow, remembershape)
...@@ -134,6 +134,7 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -134,6 +134,7 @@ class TestCompSigReshape(unittest.TestCase):
mess = mess.format(fl, W, wasrow) mess = mess.format(fl, W, wasrow)
np.testing.assert_array_equal(f, fres, mess) np.testing.assert_array_equal(f, fres, mess)
if __name__ == '__main__':
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestCompSigReshape) suite = unittest.TestLoader().loadTestsFromTestCase(TestCompSigReshape)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -115,13 +115,13 @@ def _adapt_type(val): ...@@ -115,13 +115,13 @@ def _adapt_type(val):
""" """
res = val res = val
if isinstance(val, np.ndarray): if isinstance(val, np.ndarray):
if np.issubdtype(val.dtype, np.unicode_): if np.issubdtype(val.dtype, np.str_):
# convert the unicode numpy arrays to standard unicode strings # convert the unicode numpy arrays to standard unicode strings
res = val.tolist() res = val.tolist()
# convert boolean values # convert boolean values
if val == u'_bool_True_': if val == "_bool_True_":
res = True res = True
elif val == u'_bool_False_': elif val == "_bool_False_":
res = False res = False
elif val.size == 1: elif val.size == 1:
# convert the single value in the array to the corresponding # convert the single value in the array to the corresponding
...@@ -199,15 +199,18 @@ def read_ref_mat(filename, squeeze_arrays=True, adapt_types=True): ...@@ -199,15 +199,18 @@ def read_ref_mat(filename, squeeze_arrays=True, adapt_types=True):
having an integer value, it is converted to int. having an integer value, it is converted to int.
""" """
data = scipy.io.loadmat(filename, chars_as_strings=True)['data'] data = scipy.io.loadmat(filename, chars_as_strings=True)["data"]
res = list() res = list()
for item in data[0, :]: for item in data[0, :]:
if item[0, 0].size > 0: if item[0, 0].size > 0:
# the tolist in the following is used to convert the unicode array # the tolist in the following is used to convert the unicode array
# to standard unicode string # to standard unicode string
inputs = dict(((key[0].tolist(), val) inputs = dict(
for key, val in zip(item[0, 0][0, :], (
item[0, 1][0, :]))) (key[0].tolist(), val)
for key, val in zip(item[0, 0][0, :], item[0, 1][0, :])
)
)
else: else:
inputs = dict() inputs = dict()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment