public void DefaultRoundingIsApplied() { AdHocConfig.Use(c => c.SetMeasurePrecision(1)); var m = new Measure(1.15m, U.Inch); m.Value.IsEqualTo(1.2m); }
public void YetUnknownUnitUsedInConversionAssumesPhysicalUnit() { AdHocConfig.Use(c => c.Unit(U.Centimeter) .IsPhysicalUnit(U._LENGTH) .ConvertValueBased(U.Inch, v => v * 0.393700787m, v => v * 2.54m)); var data = U.Inch.GetUnitData(); data.PhysicalUnit.IsEqualTo(U._LENGTH); }
public ObtainingPhysicalUnits() { AdHocConfig.Use(c => { c.Unit(U.Joule).IsPhysicalUnit((U._MASS * U._LENGTH.Squared()) / U._TIME.Squared()); c.Unit(U.Meter).IsPhysicalUnit(U._LENGTH); c.Unit(U.Second).IsPhysicalUnit(U._TIME); }); }
public void CanAddGrannySmithToGoldenDelicious() { AdHocConfig.Use(c => c.Unit(Gram).IsPhysicalUnit(_MASS).StartScale().To(Kilogram, 1000)); var m1 = new Measure(1, Kilogram); var m2 = new Measure(1, Gram); var m3 = m1 + m2; m3.Unit.IsEqualTo(Kilogram); m3.Value.IsEqualTo(1.001m); }
public void ConversionDefinitionMustMatchWithPhysicalUnit3() { Assert.Throws <InvalidOperationException>(() => AdHocConfig.Use(c => { c.Unit(U.Inch).IsPhysicalUnit(U._TIME); c.Unit(U.Centimeter).IsPhysicalUnit(U._LENGTH) .ConvertValueBased(U.Inch, v => v * 0.393700787m, v => v * 2.54m); }) ); }
public void CannotAddApplesToOranges() { AdHocConfig.Use(c => { c.Unit(Foot).IsPhysicalUnit(_LENGTH); c.Unit(Gram).IsPhysicalUnit(_MASS); }); var m1 = new Measure(1, Foot); var m2 = new Measure(1, Gram); Assert.Throws <InvalidOperationException>(() => { var m3 = m1 + m2; }); }
public void AConversionCanBeSet() { AdHocConfig.Use(c => { c.Unit(U.Inch).IsPhysicalUnit(U._LENGTH); c.Unit(U.Centimeter).IsPhysicalUnit(U._LENGTH) .ConvertValueBased(U.Inch, v => v * 0.393700787m, v => v * 2.54m); }); var m = new Measure(1.0m, U.Inch); m.ConvertTo(U.Centimeter).Value.IsEqualTo(2.54m); }
public void UseOfScaleSystemCreatesConversions() { AdHocConfig.Use(c => c.Unit(U.Millimeter) .IsPhysicalUnit(U._LENGTH) .StartScale() .To(U.Centimeter, 10) .To(U.Meter, 100) .To(U.Kilometer, 1000)); var m = new Measure(1.0m, U.Kilometer); var m2 = m.ConvertTo(U.Millimeter); m2.Value.IsEqualTo(1000000); }
public void UnitsAreReducibleToTheirPhysicalUnits() { AdHocConfig.Use(c => { c.Unit(U.Meter).IsPhysicalUnit(U._LENGTH); c.Unit(U.Second).IsPhysicalUnit(U._TIME); }); var velocity = U.Meter / U.Second; var physicalVelocity = velocity.ToPhysicalUnit(); physicalVelocity.IsEqualTo(U._LENGTH / U._TIME); }
public void DefaultConfigIsOverridablePerUnit() { AdHocConfig.Use(c => { c.SetMeasurePrecision(1); c.Unit(U.Nanosecond).HasPrecision(0); }); var m = new Measure(1.15m, U.Second); m.Value.IsEqualTo(1.2m); var m2 = new Measure(1.15m, U.Nanosecond); m2.Value.IsEqualTo(1.0m); }
public UnitGraphTests() { AdHocConfig.Use(uc => { uc.SetMeasurePrecision(4); uc.Unit(U.Meter).IsPhysicalUnit(U._LENGTH); uc.Unit(U.Centimeter).IsPhysicalUnit(U._LENGTH); uc.Unit(U.Inch).IsPhysicalUnit(U._LENGTH); uc.Unit(U.Second).IsPhysicalUnit(U._TIME); }); ug = new UnitGraph(); var n1 = ug.AddUnit(U.Inch); var n2 = ug.AddUnit(U.Centimeter); var n3 = ug.AddUnit(U.Meter); ug.AddConversion(n1, n2, v => v * 2.54m, v => v * 0.393700787m); ug.AddConversion(n2, n3, v => v * 0.01m, v => v * 100); }
public ComplexUnitGraphTests() { AdHocConfig.Use(uc => { uc.SetMeasurePrecision(4); uc.Unit(U.Meter).IsPhysicalUnit(U._LENGTH); uc.Unit(U.Second).IsPhysicalUnit(U._TIME); uc.Unit(U.Kilogram) .IsPhysicalUnit(U._MASS) .EquivalentTo(U.Joule * U.Second.Squared() / U.Meter.Squared()); uc.Unit(U.Joule) .IsPhysicalUnit((U._MASS * U._LENGTH.Squared()) / U._TIME.Squared()) .EquivalentTo(U.Kilogram * U.Meter.Squared() / U.Second.Squared()); }); ug = new UnitGraph(); var n1 = ug.AddUnit(U.Kilogram); var n2 = ug.AddUnit(U.Joule); ug.AddMeasurementConversion(n1, n2, m => m * PhysicalConstants.EnergyMassFactor, m => m / PhysicalConstants.EnergyMassFactor); }
public void ConversionOfComplexUnits() { AdHocConfig.Use(c => { c.SetMeasurePrecision(2); c.Unit(Meter).IsPhysicalUnit(_LENGTH) .StartScale() .To(Kilometer, 1000); c.Unit(Second).IsPhysicalUnit(_TIME) .StartScale() .To(Hour, 3600); }); var kmPerH = Kilometer / Hour; var mPerSec = Meter / Second; var v1 = 100 * kmPerH; var v2 = v1.ConvertTo(mPerSec); v2.Unit.IsEqualTo(mPerSec); v2.Value.IsEqualTo(27.78m); }
public MeasureTests(ITestOutputHelper output) { _output = output; AdHocConfig.UseEmpty(); }
public void PhysicalUnitMustBeAvailableToDefineConversion() { Assert.Throws <InvalidOperationException>(() => AdHocConfig.Use(c => c.Unit(U.Centimeter).ConvertValueBased(U.Inch, v => v * 0.393700787m, v => v * 2.54m)) ); }
public void OnlyUnderscoreUnitsArePhysicalUnits() { Assert.Throws <InvalidOperationException>(() => AdHocConfig.Use(c => c.Unit(U.Second).IsPhysicalUnit(U.Meter))); }
public void AttemptToConvertWithoutinfoGivesInvalidOpException() { AdHocConfig.UseEmpty(); Assert.Throws <InvalidOperationException>(() => { var m1 = new Measure(1, Kilogram).ConvertTo(Gram); }); }