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)
    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)
    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)
    def test_convert_ndarray(self):
        lb2g = Converter('lb', 'g')

        inarr = np.arange(10).reshape(2, 5)
        valarr = np.array([[0.0, 453.592, 907.184, 1360.776, 1814.368],
                           [2267.96, 2721.552, 3175.144, 3628.736, 4082.328]])

        outarr = lb2g(inarr)
        assert outarr.shape == (2, 5)
        np.testing.assert_array_almost_equal(outarr, valarr, decimal=3)

        # Add an 'empty' outer dimension - this will get squeezed out!!
        inarr2 = inarr.copy().reshape(1, 2, 5)
        outarr2 = lb2g(inarr2)
        assert outarr2.shape == (2, 5)
        np.testing.assert_array_almost_equal(outarr2, valarr, decimal=3)

        # Slice the array down to 1 value, it will come out as a single value
        np.testing.assert_almost_equal(lb2g(inarr2[:, 1, 2]),
                                       3175.144,
                                       decimal=3)
    def test_create(self):
        day = Unit('day')
        yr = Unit('yr')
        day2yr = Converter(day,yr)

        assert day2yr.get_expression() == '0.00273791*x'
    def test_create(self):
        day = Unit('day')
        yr = Unit('yr')
        day2yr = Converter(day, yr)

        assert day2yr.get_expression() == '0.00273791*x'