def testZeroDimensionalNumpyArray() -> None: import numpy values = numpy.array(1000.0) # type:ignore[call-overload] array = units.Array(values, "m") assert array.GetValues("m") == numpy.array(1000.0) # type:ignore[call-overload] assert array.GetValues("km") == numpy.array(1.0) # type:ignore[call-overload]
def testZeroDimensionalNumpyArray(): import numpy values = numpy.array(1000.0) array = units.Array(values, "m") assert array.GetValues("m") == numpy.array(1000.0) assert array.GetValues("km") == numpy.array(1.0)
def testGetValues() -> None: """ Tests GetValues method return type when passing a 'unit' """ array = units.Array("temperature", values=[0, 100], unit="degC") assert isinstance(array.GetValues(), list) assert isinstance(array.GetValues("degC"), list) array2 = units.Array("temperature", values=(0, 100), unit="degC") assert isinstance(array2.GetValues(), tuple) assert isinstance(array2.GetValues("degC"), tuple) assert array2[1] == 100 array3 = units.Array[List[float]]("temperature", values=[], unit="degC") assert isinstance(array3.GetValues("degC"), list)
def testReadOnlyQuantity() -> None: quantity = ObtainQuantity("m", "length") array = units.Array(quantity, values=[1, 2, 3]) array = array.CreateCopy(unit="km") assert array.unit == "km" assert approx(array.GetValues()) == [0.001, 0.002, 0.003]
def testNumpyConversion() -> None: import numpy values = numpy.array([100, 200, 300]) array = units.Array("length", values=values, unit="m") converted_values = array.GetValues("km") assert isinstance(converted_values, numpy.ndarray) assert list(numpy.array([0.1, 0.2, 0.3])) == list(converted_values)
def testNoConversionWhenUsingSameUnit() -> None: import numpy values = numpy.array([100, 150, 200]) array = units.Array(values, "m") assert array.GetValues("m") is values
def testNoConversion() -> None: values = [100, 150, 200] array = units.Array("length", values=values, unit="m") assert array.GetValues() is values