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
import random
import numpy as np
from ltfatpy.comp.assert_sigreshape_pre import assert_sigreshape_pre as aspre
from ltfatpy.comp.assert_sigreshape_post import assert_sigreshape_post\
as aspost
from ltfatpy.comp.assert_sigreshape_post import assert_sigreshape_post as aspost
import functools
......@@ -74,16 +73,16 @@ class TestAssertSigReshapePost(unittest.TestCase):
# Called before the tests.
def setUp(self):
print('Start TestAssertSigReshapePost')
print("Start TestAssertSigReshapePost")
# Called after the tests.
def tearDown(self):
print('Test done')
print("Test done")
def test_default(self):
""" Basic usual cases """
"""Basic usual cases"""
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)
fres = aspost(f, dim, permutedshape, order)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
......@@ -93,10 +92,10 @@ class TestAssertSigReshapePost(unittest.TestCase):
np.testing.assert_array_equal(f, fres, mess)
def test_twodim(self):
""" Many channels signals """
"""Many channels signals"""
shapef = tuple([random.randint(5, 20) for _ in range(2)])
L = functools.reduce(lambda x, y: x*y, shapef)
f = np.arange(0, L, dtype=np.complex_)
L = functools.reduce(lambda x, y: x * y, shapef)
f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef)
(g, L, Ls, W, dim, permutedshape, order) = aspre(f)
fres = aspost(f, dim, permutedshape, order)
......@@ -106,7 +105,7 @@ class TestAssertSigReshapePost(unittest.TestCase):
mess = mess.format(L, Ls, W, dim)
np.testing.assert_array_equal(f, fres, mess)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(
TestAssertSigReshapePost)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestAssertSigReshapePost)
unittest.TextTestRunner(verbosity=2).run(suite)
......@@ -72,16 +72,16 @@ class TestAssertSigReshapePre(unittest.TestCase):
# Called before the tests.
def setUp(self):
print('Start TestAssertSigReshapePre')
print("Start TestAssertSigReshapePre")
# Called after the tests.
def tearDown(self):
print('Test done')
print("Test done")
def test_default(self):
""" Basic usual cases """
"""Basic usual cases"""
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)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
mess += str(g.shape) + ", f.shape = " + str(f.shape)
......@@ -102,7 +102,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(dim, 0, mess)
def test_list(self):
""" Basic signal in a list """
"""Basic signal in a list"""
L = random.randint(5, 200)
f = [x for x in range(0, L)]
(g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
......@@ -113,16 +113,16 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(L, L, mess)
self.assertEqual(W, 1, 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, -4)
self.assertRaises(TypeError, asp, f, 5.5)
def test_twodim(self):
""" Many channels signals """
"""Many channels signals"""
shapef = tuple([random.randint(5, 20) for _ in range(2)])
L = functools.reduce(lambda x, y: x*y, shapef)
f = np.arange(0, L, dtype=np.complex_)
L = functools.reduce(lambda x, y: x * y, shapef)
f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef)
(g, L, Ls, W, dim, _permutedshape, _order) = asp(f)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
......@@ -133,7 +133,7 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(W, shapef[1], mess)
self.assertEqual(dim, 0, mess)
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))
(g, L, Ls, W, dim, _permutedshape, _order) = asp(fcol)
mess = "\nL = {0:d}, Ls = {1:d}, W = {2:d}, dim = {3:d}, g.shape = "
......@@ -145,7 +145,6 @@ class TestAssertSigReshapePre(unittest.TestCase):
self.assertEqual(dim, 1, mess)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(
TestAssertSigReshapePre)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestAssertSigReshapePre)
unittest.TextTestRunner(verbosity=2).run(suite)
......@@ -73,11 +73,11 @@ class TestCompSigReshape(unittest.TestCase):
# Called before the tests.
def setUp(self):
print('Start TestCompSigReshape')
print("Start TestCompSigReshape")
# Called after the tests.
def tearDown(self):
print('Test done')
print("Test done")
def test_default(self):
self.assertRaises(ValueError, cpre, "toto", 10)
......@@ -85,9 +85,9 @@ class TestCompSigReshape(unittest.TestCase):
self.assertRaises(ValueError, cpre, np.ones((10, 10, 2)), 1)
def test_onedim(self):
""" One channel """
"""One channel"""
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)
fres = cpost(fin, fl, wasrow, remembershape)
mess = "\nfl = {:d}, W = {:d}, wasrow = {:d},remembershape.shape = "
......@@ -96,7 +96,7 @@ class TestCompSigReshape(unittest.TestCase):
mess = mess.format(fl, W, wasrow)
np.testing.assert_array_equal(f, fres, mess)
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))
(fin, fl, W, wasrow, remembershape) = cpre(f, 0)
fres = cpost(fin, fl, wasrow, remembershape)
......@@ -107,10 +107,10 @@ class TestCompSigReshape(unittest.TestCase):
np.testing.assert_array_equal(f, fres, mess)
def test_twodim(self):
""" Many channels signals """
"""Many channels signals"""
shapef = tuple([random.randint(5, 20) for _ in range(2)])
L = functools.reduce(lambda x, y: x*y, shapef)
f = np.arange(0, L, dtype=np.complex_)
L = functools.reduce(lambda x, y: x * y, shapef)
f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef)
(fin, fl, W, wasrow, remembershape) = cpre(f, 1)
fres = cpost(fin, fl, wasrow, remembershape)
......@@ -121,10 +121,10 @@ class TestCompSigReshape(unittest.TestCase):
np.testing.assert_array_equal(f, fres, mess)
def test_multidim(self):
""" Multidimensionnal signals """
"""Multidimensionnal signals"""
shapef = tuple([random.randint(5, 20) for _ in range(4)])
L = np.prod(shapef)
f = np.arange(0, L, dtype=np.complex_)
f = np.arange(0, L, dtype=np.complex128)
f = f.reshape(shapef)
(fin, fl, W, wasrow, remembershape) = cpre(f, 5)
fres = cpost(fin, fl, wasrow, remembershape)
......@@ -134,6 +134,7 @@ class TestCompSigReshape(unittest.TestCase):
mess = mess.format(fl, W, wasrow)
np.testing.assert_array_equal(f, fres, mess)
if __name__ == '__main__':
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestCompSigReshape)
unittest.TextTestRunner(verbosity=2).run(suite)
......@@ -115,13 +115,13 @@ def _adapt_type(val):
"""
res = val
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
res = val.tolist()
# convert boolean values
if val == u'_bool_True_':
if val == "_bool_True_":
res = True
elif val == u'_bool_False_':
elif val == "_bool_False_":
res = False
elif val.size == 1:
# 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):
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()
for item in data[0, :]:
if item[0, 0].size > 0:
# the tolist in the following is used to convert the unicode array
# to standard unicode string
inputs = dict(((key[0].tolist(), val)
for key, val in zip(item[0, 0][0, :],
item[0, 1][0, :])))
inputs = dict(
(
(key[0].tolist(), val)
for key, val in zip(item[0, 0][0, :], item[0, 1][0, :])
)
)
else:
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