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

update tests

parent 3beaf654
Branches
No related tags found
1 merge request!23.7 to 3.10 compatibility
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 = "
...@@ -96,7 +95,7 @@ class TestAssertSigReshapePost(unittest.TestCase): ...@@ -96,7 +95,7 @@ class TestAssertSigReshapePost(unittest.TestCase):
"""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)
...@@ -113,7 +113,7 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -113,7 +113,7 @@ 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)
...@@ -122,7 +122,7 @@ class TestAssertSigReshapePre(unittest.TestCase): ...@@ -122,7 +122,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
"""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)
...@@ -87,7 +87,7 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -87,7 +87,7 @@ class TestCompSigReshape(unittest.TestCase):
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)
...@@ -110,7 +110,7 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -110,7 +110,7 @@ class TestCompSigReshape(unittest.TestCase):
"""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)
...@@ -124,7 +124,7 @@ class TestCompSigReshape(unittest.TestCase): ...@@ -124,7 +124,7 @@ class TestCompSigReshape(unittest.TestCase):
"""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.
Please register or to comment