Beispiel #1
0
        public void CanParse_All_Units()
        {
            foreach (var unit in UnitDataCache.GetSymbolAttributes <TUnit>())
            {
                var unitString = $"12.34{unit.Symbol}";

                var parsed = Units.Parse <T>(unitString);
                AssertMagnitudeAndUnits(parsed, 12.34, unit.GetUnitType <TUnit>());
            }
        }
Beispiel #2
0
        public void CanConvert_BaseUnit_ToAllOtherUnits()
        {
            var allOtherUnits = UnitDataCache.GetSymbolAttributes <TUnit>()
                                .Where(x => (int)(object)x.GetUnitType <TUnit>() != (int)(object)BaseUnit.Units);

            allOtherUnits.Should().NotBeEmpty();

            foreach (var unit in allOtherUnits)
            {
                var converted = BaseUnit.ConvertTo(unit.GetUnitType <TUnit>());
                converted.Magnitude.Should().BeApproximately(1.0 / unit.ScaleFactor + unit.Offset, 1e-10);

                converted = BaseUnit.ConvertTo(unit.Symbol);
                converted.Magnitude.Should().BeApproximately(1.0 / unit.ScaleFactor + unit.Offset, 1e-10);
            }
        }