Skip to content
Snippets Groups Projects
Commit 02f5be35 authored by Jan Petermann's avatar Jan Petermann
Browse files

Merge branch '71-tests-for-conversion-db' into develop

parents a75c6244 84dcc253
Branches
No related tags found
No related merge requests found
import numpy
import numpy as np
def to_lin(data):
......@@ -6,11 +6,11 @@ def to_lin(data):
def from_lin(data):
return 10 * numpy.log10(data)
return 10 * np.log10(data)
def mean(data):
return from_lin(numpy.mean(to_lin(data)))
return from_lin(np.mean(to_lin(data)))
def subtract(signal, noise):
......@@ -19,9 +19,9 @@ def subtract(signal, noise):
def average(datasets):
lin = to_lin(datasets)
average = numpy.sum(lin, 0) / len(lin)
average = np.sum(lin, 0) / len(lin)
return from_lin(average)
def dBm2Vrms(dbm, R=50.0):
return numpy.sqrt(0.001 * R) * 10 ** (dbm / 20)
return np.sqrt(0.001 * R) * 10 ** (dbm / 20)
import unittest
import numpy as np
import pandas as pd
from openqlab.conversion.db import from_lin
class TestFromLin(unittest.TestCase):
def test_positive_integer(self):
self.assertEqual(from_lin(10), 10)
self.assertEqual(from_lin(100000), 50)
self.assertAlmostEqual(from_lin(1.9952623), 3)
def test_negative_integer(self):
self.assertEqual(from_lin(0.1), -10)
self.assertEqual(from_lin(1e-5), -50)
self.assertAlmostEqual(from_lin(0.5011872336272722), -3)
def test_positive_float(self):
self.assertAlmostEqual(from_lin(2.23872113), 3.5)
def test_negative_float(self):
self.assertAlmostEqual(from_lin(0.446683592), -3.5)
def test_dataframe(self):
df = pd.DataFrame([10, 0.1, 1e5])
expected_df = pd.DataFrame([10, -10, 50], dtype="float64")
pd.testing.assert_frame_equal(from_lin(df), expected_df)
def test_numpy_array(self):
a = np.array([10, 0.1, 1e5])
expected_array = np.array([10, -10, 50])
np.testing.assert_array_equal(from_lin(a), expected_array)
import unittest
import numpy as np
import pandas as pd
from openqlab.conversion.db import to_lin
class TestToLin(unittest.TestCase):
def test_positive_integer(self):
self.assertEqual(to_lin(10), 10)
self.assertEqual(to_lin(50), 100000)
self.assertAlmostEqual(to_lin(3), 1.9952623)
def test_negative_integer(self):
self.assertEqual(to_lin(-10), 0.1)
self.assertEqual(to_lin(-50), 1e-5)
self.assertAlmostEqual(to_lin(-3), 0.5011872336272722)
def test_positive_float(self):
self.assertAlmostEqual(to_lin(3.5), 2.23872113)
def test_negative_float(self):
self.assertAlmostEqual(to_lin(-3.5), 0.446683592)
def test_dataframe(self):
df = pd.DataFrame([10, -10, 50])
expected_df = pd.DataFrame([10, 0.1, 1e5])
pd.testing.assert_frame_equal(to_lin(df), expected_df)
def test_numpy_array(self):
a = np.array([10, -10, 50])
expected_array = np.array([10, 0.1, 1e5])
np.testing.assert_array_equal(to_lin(a), expected_array)
import unittest
from pathlib import Path
from openqlab.conversion.db import to_lin
class TestGwinstek(unittest.TestCase):
def test_to_lin(self):
pass
def test_from_lin(self):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment