Beispiel #1
0
 def test_one_array(self):
     """ Does it pass a an array through correctly?
     """
     units = [None]
     a = array((1, 2, 3))
     result = convert_units(units, a)
     self.assertTrue(all(a == result))
 def test_one_array(self):
     """ Does it pass a an array through correctly?
     """
     units = [None]
     a = array((1, 2, 3))
     result = convert_units(units, a)
     self.assertTrue(all(a == result))
Beispiel #3
0
 def test_convert_unit_scalar(self):
     """ Does it convert a scalar correctly?
     """
     units = [feet]
     a = UnitScalar(3., units=meters)
     aa = convert_units(units, a)
     self.assertTrue(allclose(a, aa.as_units(meters)))
     self.assertEqual(aa.units, feet)
 def test_convert_unit_scalar(self):
     """ Does it convert a scalar correctly?
     """
     units = [feet]
     a = UnitScalar(3., units=meters)
     aa = convert_units(units, a)
     self.assertTrue(allclose(a, aa.as_units(meters)))
     self.assertEqual(aa.units, feet)
Beispiel #5
0
 def test_two_arrays(self):
     """ Does it pass a two arrays through correctly?
     """
     units = [None, None]
     a = array((1, 2, 3))
     b = array((3, 4, 5))
     aa, bb = convert_units(units, a, b)
     self.assertTrue(all(a == aa))
     self.assertTrue(all(b == bb))
 def test_two_arrays(self):
     """ Does it pass a two arrays through correctly?
     """
     units = [None, None]
     a = array((1, 2, 3))
     b = array((3, 4, 5))
     aa, bb = convert_units(units, a, b)
     self.assertTrue(all(a == aa))
     self.assertTrue(all(b == bb))
Beispiel #7
0
 def test_convert_unit_array(self):
     """ Does it convert an array correctly?
     """
     units = [feet]
     a = UnitArray((1, 2, 3), units=meters)
     aa = convert_units(units, a)
     self.assertTrue(allclose(a, aa.as_units(meters)))
     # fixme: This actually may be something we don't want.  For speed,
     #        if this were just a standard array, we would be better off.
     self.assertEqual(aa.units, feet)
Beispiel #8
0
    def test_convert_array_with_units(self):
        """ Does it add units to an array correctly?

            fixme: This may be exactly what we don't want to happen!
        """
        units = [feet]
        a = array((1, 2, 3))
        aa = convert_units(units, a)
        self.assertTrue(all(a == aa))
        self.assertTrue(type(aa) is ndarray)
    def test_dont_convert_unit_scalar(self):
        """ Does it return the same object if units are the same?

            Note: This isn't required for accuracy, but it is a good
                  optimization.
        """
        units = [feet]
        a = UnitScalar(3., units=feet)
        aa = convert_units(units, a)
        self.assertTrue(id(a), id(aa))
 def test_convert_unit_array(self):
     """ Does it convert an array correctly?
     """
     units = [feet]
     a = UnitArray((1, 2, 3), units=meters)
     aa = convert_units(units, a)
     self.assertTrue(allclose(a, aa.as_units(meters)))
     # fixme: This actually may be something we don't want.  For speed,
     #        if this were just a standard array, we would be better off.
     self.assertEqual(aa.units, feet)
Beispiel #11
0
    def test_dont_convert_unit_scalar(self):
        """ Does it return the same object if units are the same?

            Note: This isn't required for accuracy, but it is a good
                  optimization.
        """
        units = [feet]
        a = UnitScalar(3., units=feet)
        aa = convert_units(units, a)
        self.assertTrue(id(a), id(aa))
    def test_convert_array_with_units(self):
        """ Does it add units to an array correctly?

            fixme: This may be exactly what we don't want to happen!
        """
        units = [feet]
        a = array((1, 2, 3))
        aa = convert_units(units, a)
        self.assertTrue(all(a == aa))
        self.assertTrue(isinstance(aa, ndarray))
 def test_convert_different_args(self):
     """ Does it handle multiple different args correctly?
     """
     units = [feet, meters, None, feet]
     a = UnitArray((1, 2, 3), units=meters)
     b = array((2, 3, 4))
     c = 1
     d = UnitScalar(3., units=meters)
     aa, bb, cc, dd = convert_units(units, a, b, c, d)
     self.assertTrue(allclose(a, aa.as_units(meters)))
     self.assertTrue(allclose(b, bb))
     self.assertEqual(c, cc)
     self.assertTrue(allclose(d, dd.as_units(meters)))
Beispiel #14
0
 def test_convert_different_args(self):
     """ Does it handle multiple different args correctly?
     """
     units = [feet, meters, None, feet]
     a = UnitArray((1, 2, 3), units=meters)
     b = array((2, 3, 4))
     c = 1
     d = UnitScalar(3., units=meters)
     aa, bb, cc, dd = convert_units(units, a, b, c, d)
     self.assertTrue(allclose(a, aa.as_units(meters)))
     self.assertTrue(allclose(b, bb))
     self.assertEqual(c, cc)
     self.assertTrue(allclose(d, dd.as_units(meters)))
Beispiel #15
0
 def test_single_float(self):
     """ Does it pass a single value through correctly?
     """
     units = [None]
     result = convert_units(units, 1.0)
     self.assertEqual(1.0, result)
Beispiel #16
0
 def test_two_float(self):
     """ Does it pass a two values through correctly?
     """
     units = [None, None]
     result = convert_units(units, 1.0, 2.0)
     self.assertEqual([1.0, 2.0], result)
 def test_two_float(self):
     """ Does it pass a two values through correctly?
     """
     units = [None, None]
     result = convert_units(units, 1.0, 2.0)
     self.assertEqual([1.0, 2.0], result)
 def test_single_float(self):
     """ Does it pass a single value through correctly?
     """
     units = [None]
     result = convert_units(units, 1.0)
     self.assertEqual(1.0, result)