Skip to content
Snippets Groups Projects
Select Git revision
  • 02f5be355a453122c193d01398f959d7429b9e84
  • master default
  • v0.1.11.1
  • v0.1.11
  • v0.1.10.1
  • v0.1.10
  • v0.1.9.8
  • v0.1.9.7
  • v0.1.9.6
  • v0.1.2
  • v0.1.1
  • v0.1
12 results

test_from_lin.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_from_lin.py 1.07 KiB
    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)