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

test_from_lin done

parent 8d584eee
Branches
Tags
No related merge requests found
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)
...@@ -15,7 +15,7 @@ class TestToLin(unittest.TestCase): ...@@ -15,7 +15,7 @@ class TestToLin(unittest.TestCase):
def test_negative_integer(self): def test_negative_integer(self):
self.assertEqual(to_lin(-10), 0.1) self.assertEqual(to_lin(-10), 0.1)
self.assertEqual(to_lin(-50), 1e-5) self.assertEqual(to_lin(-50), 1e-5)
self.assertAlmostEqual(to_lin(-3), 0.5011872) self.assertAlmostEqual(to_lin(-3), 0.5011872336272722)
def test_positive_float(self): def test_positive_float(self):
self.assertAlmostEqual(to_lin(3.5), 2.23872113) self.assertAlmostEqual(to_lin(3.5), 2.23872113)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment