コード例 #1
0
def testConversionToFullScalar() -> None:
    y = _LightweightScalar(value=1.0, unit="kg/m3", category="density")
    x = Scalar(value=y.GetValue(), unit=y.GetUnit(), category=y.GetCategory())

    assert x.GetValue() == 1.0

    assert x.GetUnit() == "kg/m3"
    assert x.GetCategory() == "density"
    assert x.GetQuantityType() == "density"

    assert x.GetQuantity().GetUnit() == "kg/m3"
    assert x.GetQuantity().GetCategory() == "density"
    assert x.GetQuantity().GetQuantityType() == "density"

    # Full Scalar supports conversion
    assert x.GetValue(unit="g/cm3") == 0.001
コード例 #2
0
def testScalarCopyAndRepresentation(unit_database_empty):
    unit_database = unit_database_empty

    unit_database.AddUnitBase("length", "meters", "m")
    unit_database.AddUnit("length", "milimeters", "mm", "x * 1000.0", "x / 1000.0")
    unit_database.AddUnit("length", "centimeters", "cm", "x * 100.0", "x / 100.0")
    unit_database.AddCategory("well-diameter", "length")
    s = Scalar("well-diameter", 10, "m")

    assert "Scalar(10.0, 'm', 'well-diameter')" == repr(s)
    assert "10.0" == six.text_type(s.value)
    assert "m" == s.unit
    assert "well-diameter" == s.GetCategory()
    assert "length" == s.GetQuantityType()

    s = s.CreateCopy(unit="cm")
    assert "Scalar(1000.0, 'cm', 'well-diameter')" == repr(s)
    assert "1000 [cm]" == six.text_type(s)