public void Equals_RelativeTolerance_IsImplemented() { var v = FuelEfficiency.FromLitersPer100Kilometers(1); Assert.True(v.Equals(FuelEfficiency.FromLitersPer100Kilometers(1), LitersPer100KilometersTolerance, ComparisonType.Relative)); Assert.False(v.Equals(FuelEfficiency.Zero, LitersPer100KilometersTolerance, ComparisonType.Relative)); }
public void CompareToIsImplemented() { FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); Assert.Equal(0, literper100kilometers.CompareTo(literper100kilometers)); Assert.True(literper100kilometers.CompareTo(FuelEfficiency.Zero) > 0); Assert.True(FuelEfficiency.Zero.CompareTo(literper100kilometers) < 0); }
public void FromLitersPer100Kilometers_WithInfinityValue_CreateQuantityAndAffectInfinityValue() { var positiveInfinityQuantity = FuelEfficiency.FromLitersPer100Kilometers(double.PositiveInfinity); var negativeInfinityQuantity = FuelEfficiency.FromLitersPer100Kilometers(double.NegativeInfinity); Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value)); Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value)); }
public void Equals_SameType_IsImplemented() { var a = FuelEfficiency.FromLitersPer100Kilometers(1); var b = FuelEfficiency.FromLitersPer100Kilometers(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); }
public void Equals_QuantityAsObject_IsImplemented() { object a = FuelEfficiency.FromLitersPer100Kilometers(1); object b = FuelEfficiency.FromLitersPer100Kilometers(2); Assert.True(a.Equals(a)); Assert.False(a.Equals(b)); Assert.False(a.Equals((object)null)); }
public void ConversionRoundTrip() { FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); AssertEx.EqualTolerance(1, FuelEfficiency.FromKilometersPerLiters(literper100kilometers.KilometersPerLiters).LitersPer100Kilometers, KilometersPerLitersTolerance); AssertEx.EqualTolerance(1, FuelEfficiency.FromLitersPer100Kilometers(literper100kilometers.LitersPer100Kilometers).LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(1, FuelEfficiency.FromMilesPerUkGallon(literper100kilometers.MilesPerUkGallon).LitersPer100Kilometers, MilesPerUkGallonTolerance); AssertEx.EqualTolerance(1, FuelEfficiency.FromMilesPerUsGallon(literper100kilometers.MilesPerUsGallon).LitersPer100Kilometers, MilesPerUsGallonTolerance); }
public void LiterPer100KilometersToFuelEfficiencyUnits() { FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); AssertEx.EqualTolerance(KilometersPerLitersInOneLiterPer100Kilometers, literper100kilometers.KilometersPerLiters, KilometersPerLitersTolerance); AssertEx.EqualTolerance(LitersPer100KilometersInOneLiterPer100Kilometers, literper100kilometers.LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(MilesPerUkGallonInOneLiterPer100Kilometers, literper100kilometers.MilesPerUkGallon, MilesPerUkGallonTolerance); AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, literper100kilometers.MilesPerUsGallon, MilesPerUsGallonTolerance); }
public void As() { var literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); AssertEx.EqualTolerance(KilometersPerLitersInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.KilometerPerLiter), KilometersPerLitersTolerance); AssertEx.EqualTolerance(LitersPer100KilometersInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.LiterPer100Kilometers), LitersPer100KilometersTolerance); AssertEx.EqualTolerance(MilesPerUkGallonInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.MilePerUkGallon), MilesPerUkGallonTolerance); AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, literper100kilometers.As(FuelEfficiencyUnit.MilePerUsGallon), MilesPerUsGallonTolerance); }
public void ArithmeticOperators() { FuelEfficiency v = FuelEfficiency.FromLitersPer100Kilometers(1); AssertEx.EqualTolerance(-1, -v.LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(2, (FuelEfficiency.FromLitersPer100Kilometers(3) - v).LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(2, (v + v).LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(10, (v * 10).LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(10, (10 * v).LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(2, (FuelEfficiency.FromLitersPer100Kilometers(10) / 5).LitersPer100Kilometers, LitersPer100KilometersTolerance); AssertEx.EqualTolerance(2, FuelEfficiency.FromLitersPer100Kilometers(10) / FuelEfficiency.FromLitersPer100Kilometers(5), LitersPer100KilometersTolerance); }
public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported() { var literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.SI)); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.CGS)); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.BI)); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.EE)); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.USC)); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.FPS)); Assert.Throws <ArgumentException>(() => literper100kilometers.ToUnit(UnitSystem.Astronomical)); }
public void ComparisonOperators() { FuelEfficiency oneLiterPer100Kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); FuelEfficiency twoLitersPer100Kilometers = FuelEfficiency.FromLitersPer100Kilometers(2); Assert.True(oneLiterPer100Kilometers < twoLitersPer100Kilometers); Assert.True(oneLiterPer100Kilometers <= twoLitersPer100Kilometers); Assert.True(twoLitersPer100Kilometers > oneLiterPer100Kilometers); Assert.True(twoLitersPer100Kilometers >= oneLiterPer100Kilometers); Assert.False(oneLiterPer100Kilometers > twoLitersPer100Kilometers); Assert.False(oneLiterPer100Kilometers >= twoLitersPer100Kilometers); Assert.False(twoLitersPer100Kilometers < oneLiterPer100Kilometers); Assert.False(twoLitersPer100Kilometers <= oneLiterPer100Kilometers); }
public void EqualityOperators() { var a = FuelEfficiency.FromLitersPer100Kilometers(1); var b = FuelEfficiency.FromLitersPer100Kilometers(2); // ReSharper disable EqualExpressionComparison Assert.True(a == a); Assert.False(a != a); Assert.True(a != b); Assert.False(a == b); Assert.False(a == null); Assert.False(null == a); // ReSharper restore EqualExpressionComparison }
public void ToUnit() { var literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); var kilometerperliterQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.KilometerPerLiter); AssertEx.EqualTolerance(KilometersPerLitersInOneLiterPer100Kilometers, (double)kilometerperliterQuantity.Value, KilometersPerLitersTolerance); Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, kilometerperliterQuantity.Unit); var literper100kilometersQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.LiterPer100Kilometers); AssertEx.EqualTolerance(LitersPer100KilometersInOneLiterPer100Kilometers, (double)literper100kilometersQuantity.Value, LitersPer100KilometersTolerance); Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, literper100kilometersQuantity.Unit); var mileperukgallonQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.MilePerUkGallon); AssertEx.EqualTolerance(MilesPerUkGallonInOneLiterPer100Kilometers, (double)mileperukgallonQuantity.Value, MilesPerUkGallonTolerance); Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, mileperukgallonQuantity.Unit); var mileperusgallonQuantity = literper100kilometers.ToUnit(FuelEfficiencyUnit.MilePerUsGallon); AssertEx.EqualTolerance(MilesPerUsGallonInOneLiterPer100Kilometers, (double)mileperusgallonQuantity.Value, MilesPerUsGallonTolerance); Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, mileperusgallonQuantity.Unit); }
public void Convert_ChangeType_UnitType_EqualsUnit() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(FuelEfficiencyUnit))); }
public void Convert_ChangeType_SelfType_EqualsSelf() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(FuelEfficiency))); }
public void Convert_ToUInt64_EqualsValueAsSameType() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); }
public void Convert_ToString_EqualsToString() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); }
public void Convert_ToSingle_EqualsValueAsSameType() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); }
public void Convert_ToInt16_EqualsValueAsSameType() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); }
public void Convert_ToDecimal_EqualsValueAsSameType() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); }
public void Convert_ToDateTime_ThrowsInvalidCastException() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity)); }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = FuelEfficiency.FromLitersPer100Kilometers(value); Assert.Equal(FuelEfficiency.FromLitersPer100Kilometers(-value), -quantity); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }
public void Convert_ChangeType_QuantityType_EqualsQuantityType() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(QuantityType.FuelEfficiency, Convert.ChangeType(quantity, typeof(QuantityType))); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(FuelEfficiency.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void EqualsReturnsFalseOnNull() { FuelEfficiency literper100kilometers = FuelEfficiency.FromLitersPer100Kilometers(1); Assert.False(literper100kilometers.Equals(null)); }
public void GetHashCode_Equals() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(new { FuelEfficiency.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }
public void ToString_NullArgs_ThrowsArgumentNullException() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null)); }
public static FuelEfficiency LitersPer100Kilometers <T>(this T value) => FuelEfficiency.FromLitersPer100Kilometers(Convert.ToDecimal(value));
public void ToString_NullProvider_EqualsCurrentUICulture() { var quantity = FuelEfficiency.FromLitersPer100Kilometers(1.0); Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); }