-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from jaidevd/jd-add-tests
Add tests for utility functions.
- Loading branch information
Showing
16 changed files
with
185 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
# Cube26 product code | ||
# | ||
# (C) Copyright 2015 Cube26 Software Pvt Ltd | ||
# All right reserved. | ||
# | ||
# This file is confidential and NOT open source. Do not distribute. | ||
# | ||
|
||
""" | ||
Tests for the generatos module. | ||
""" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
# Cube26 product code | ||
# | ||
# (C) Copyright 2015 Cube26 Software Pvt Ltd | ||
# All right reserved. | ||
# | ||
# This file is confidential and NOT open source. Do not distribute. | ||
# | ||
|
||
""" | ||
Tests for tftb.generators.utils | ||
""" | ||
|
||
import unittest | ||
import numpy as np | ||
|
||
from tftb.generators import utils, fmlin | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
|
||
def test_sigmerge(self): | ||
"""Test merging of signals with a given SNR.""" | ||
signal = fmlin(128)[0] | ||
noise = np.random.randn(128,) | ||
noisy_signal = utils.sigmerge(signal, noise) | ||
gamma_estimate = np.sqrt(signal.var() / noise.var()) | ||
np.testing.assert_allclose(noisy_signal, | ||
signal + gamma_estimate * noise, rtol=1e-2, | ||
atol=1e-2) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
# Cube26 product code | ||
# | ||
# (C) Copyright 2015 Cube26 Software Pvt Ltd | ||
# All right reserved. | ||
# | ||
# This file is confidential and NOT open source. Do not distribute. | ||
# | ||
|
||
""" | ||
Tests for tftb.processing.utils | ||
""" | ||
|
||
import unittest | ||
import numpy as np | ||
from tftb.processing import utils | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
|
||
def test_derive_window(self): | ||
"""Test derivative of window function.""" | ||
from scipy.signal import gaussian | ||
g = gaussian(129, 10) | ||
dwindow = utils.derive_window(g) | ||
self.assertEqual(dwindow[64], 0) | ||
self.assertTrue(np.all(dwindow[:64] >= 0)) | ||
self.assertTrue(np.all(dwindow[64:] <= 0)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# vim:fenc=utf-8 | ||
# | ||
# Cube26 product code | ||
# | ||
# (C) Copyright 2015 Cube26 Software Pvt Ltd | ||
# All right reserved. | ||
# | ||
# This file is confidential and NOT open source. Do not distribute. | ||
# | ||
|
||
""" | ||
Tests for tftb.utils | ||
""" | ||
|
||
import unittest | ||
import numpy as np | ||
from tftb import utils | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
|
||
def test_is_linear(self): | ||
"""Test the is_linear function.""" | ||
x = np.arange(10) | ||
self.assertTrue(utils.is_linear(x)) | ||
x = np.sin(x) | ||
self.assertFalse(utils.is_linear(x)) | ||
|
||
def test_nextpow2(self): | ||
"""Test the nextpow2 function.""" | ||
self.assertEqual(utils.nextpow2(2), 1) | ||
self.assertEqual(utils.nextpow2(17), 5) | ||
import warnings | ||
with warnings.catch_warnings(record=True) as catcher: | ||
utils.nextpow2(-3) | ||
self.assertEqual(len(catcher), 1) | ||
self.assertTrue(catcher[-1].category, RuntimeWarning) | ||
|
||
def test_divider(self): | ||
"""Test the divider function.""" | ||
self.assertItemsEqual(utils.divider(4), (2, 2)) | ||
self.assertItemsEqual(utils.divider(17), (1, 17)) | ||
self.assertItemsEqual(utils.divider(60), (10, 6)) | ||
x = np.arange(1, 101) | ||
lowers = np.zeros(x.shape) | ||
uppers = np.zeros(x.shape) | ||
for i, num in enumerate(x): | ||
a, b = utils.divider(num) | ||
lowers[i] = a | ||
uppers[i] = b | ||
perfect_squares = np.arange(1, 11) ** 2 | ||
np.testing.assert_allclose(perfect_squares, x[lowers == uppers]) | ||
|
||
def test_nearest_odd(self): | ||
"""Test the nearest_odd function.""" | ||
self.assertEqual(utils.nearest_odd(0), 1) | ||
self.assertEqual(utils.nearest_odd(2), 3) | ||
self.assertEqual(utils.nearest_odd(-0.00001), -1) | ||
|
||
def test_modulo(self): | ||
"""Test the modulo function.""" | ||
x = np.arange(1, 11) | ||
np.testing.assert_allclose(utils.modulo(x, 1), np.ones(x.shape)) | ||
np.testing.assert_allclose(utils.modulo(x, 2), | ||
np.array([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])) | ||
np.testing.assert_allclose(utils.modulo(x, 3), | ||
np.array([1, 2, 3, 1, 2, 3, 1, 2, 3, 1])) | ||
np.testing.assert_allclose(utils.modulo(x, 4), | ||
np.array([1, 2, 3, 4, 1, 2, 3, 4, 1, 2])) | ||
np.testing.assert_allclose(utils.modulo(x, 5), | ||
np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5])) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.