Exemplo n.º 1
0
    def test_convert_sequence(self):
        m = Unit('m')
        ft = Unit('ft')

        m2ft = m.get_converter(ft)
        assert '3.28084*x' == m2ft.get_expression()

        ft2m = Converter('ft',m)
        assert '0.3048*a' == ft2m.get_expression('a')

        sqm2sqft = (m*m).get_converter((ft*ft))
        assert '10.7639*x' == sqm2sqft.get_expression()

        inarr = np.array([2.8, 3.5, 19.2, 312])

        # Verify output of m2ft is what we expect
        outarr = m2ft(inarr)
        np.testing.assert_array_almost_equal(outarr, np.array([9.186352, 11.48294, 62.992128, 1023.62208]), decimal=6)

        # Verify output of ft2m is what we expect
        outarr = ft2m(inarr)
        np.testing.assert_array_almost_equal(outarr, np.array([0.85344, 1.0668 , 5.85216, 95.0976]), decimal=5)

        outarr = sqm2sqft(inarr)
        np.testing.assert_array_almost_equal(outarr, np.array([30.13892, 37.67365, 206.66688, 3358.3368]), decimal=5)

        with pytest.raises(TypeError):
            m.get_converter(None)
Exemplo n.º 2
0
    def test_convert_sequence(self):
        m = Unit('m')
        ft = Unit('ft')

        m2ft = m.get_converter(ft)
        assert '3.28084*x' == m2ft.get_expression()

        ft2m = Converter('ft', m)
        assert '0.3048*a' == ft2m.get_expression('a')

        sqm2sqft = (m * m).get_converter((ft * ft))
        assert '10.7639*x' == sqm2sqft.get_expression()

        inarr = np.array([2.8, 3.5, 19.2, 312])

        # Verify output of m2ft is what we expect
        outarr = m2ft(inarr)
        np.testing.assert_array_almost_equal(
            outarr,
            np.array([9.186352, 11.48294, 62.992128, 1023.62208]),
            decimal=6)

        # Verify output of ft2m is what we expect
        outarr = ft2m(inarr)
        np.testing.assert_array_almost_equal(
            outarr, np.array([0.85344, 1.0668, 5.85216, 95.0976]), decimal=5)

        outarr = sqm2sqft(inarr)
        np.testing.assert_array_almost_equal(
            outarr,
            np.array([30.13892, 37.67365, 206.66688, 3358.3368]),
            decimal=5)

        with pytest.raises(TypeError):
            m.get_converter(None)
Exemplo n.º 3
0
    def test_combine_converters(self):
        s = Unit('s')
        min = Unit('min')
        hr = Unit('hr')

        s2min = s.get_converter(min)
        min2hr = min.get_converter(hr)

        s2hr = s.get_converter(hr)

        s2min2hr = s2min.combine(min2hr)

        assert s2hr.get_expression('x') == s2min2hr.get_expression('x')

        np.testing.assert_almost_equal(min2hr(s2min.evaluate(10)), s2min2hr(10), decimal=7)

        with pytest.raises(TypeError):
            s2min.combine('10')
Exemplo n.º 4
0
    def test_convert_single(self):
        k = Unit('K')
        c = Unit('deg_c')

        k2c = k.get_converter(c)

        np.testing.assert_almost_equal(k2c(23.5), -249.65, decimal=2)
        np.testing.assert_almost_equal(k2c(288.2), 15.05, decimal=2)
        np.testing.assert_almost_equal(k2c(273.15), 0.0, decimal=1)
Exemplo n.º 5
0
    def test_convert_single(self):
        k = Unit('K')
        c = Unit('deg_c')

        k2c = k.get_converter(c)

        np.testing.assert_almost_equal(k2c(23.5), -249.65, decimal=2)
        np.testing.assert_almost_equal(k2c(288.2), 15.05, decimal=2)
        np.testing.assert_almost_equal(k2c(273.15), 0.0, decimal=1)
Exemplo n.º 6
0
    def test_combine_converters(self):
        s = Unit('s')
        min = Unit('min')
        hr = Unit('hr')

        s2min = s.get_converter(min)
        min2hr = min.get_converter(hr)

        s2hr = s.get_converter(hr)

        s2min2hr = s2min.combine(min2hr)

        assert s2hr.get_expression('x') == s2min2hr.get_expression('x')

        np.testing.assert_almost_equal(min2hr(s2min.evaluate(10)),
                                       s2min2hr(10),
                                       decimal=7)

        with pytest.raises(TypeError):
            s2min.combine('10')
Exemplo n.º 7
0
    def test_errors(self):
        s = Unit('s')
        min = Unit('min')

        s2min = s.get_converter(min)

        with pytest.raises(TypeError):
            s2min.combine('10')

        with pytest.raises(TypeError):
            Converter(s, None)

        with pytest.raises(TypeError):
            fake = object
            fake.this = None
            Converter(s, fake)
Exemplo n.º 8
0
    def test_errors(self):
        s = Unit('s')
        min = Unit('min')

        s2min = s.get_converter(min)

        with pytest.raises(TypeError):
            s2min.combine('10')

        with pytest.raises(TypeError):
            Converter(s, None)

        with pytest.raises(TypeError):
            fake = object
            fake.this = None
            Converter(s, fake)