Exemplo n.º 1
0
        public void CompareToThrowsOnTypeMismatch()
        {
            Luminosity watt = Luminosity.FromWatts(1);

            Assert.Throws <ArgumentException>(() => watt.CompareTo(new object()));
        }
 public static Luminosity Watts <T>(this T value) =>
 Luminosity.FromWatts(Convert.ToDouble(value));
Exemplo n.º 3
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            Luminosity watt = Luminosity.FromWatts(1);

            Assert.False(watt.Equals(new object()));
        }
Exemplo n.º 4
0
        public void FromWatts_WithNanValue_CreateQuantityAndAffectNaNValue()
        {
            var nanQuantity = Luminosity.FromWatts(double.NaN);

            Assert.True(double.IsNaN(nanQuantity.Value));
        }
Exemplo n.º 5
0
        public void GetHashCode_Equals()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(new { Luminosity.Info.Name, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
Exemplo n.º 6
0
 public void FromWatts_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Luminosity.FromWatts(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => Luminosity.FromWatts(double.NegativeInfinity));
 }
Exemplo n.º 7
0
        public void Convert_ToDecimal_EqualsValueAsSameType()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity));
        }
Exemplo n.º 8
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(Luminosity.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
Exemplo n.º 9
0
        public void ToString_NullProvider_EqualsCurrentUICulture()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g"));
        }
Exemplo n.º 10
0
        public void Convert_ToDateTime_ThrowsInvalidCastException()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(quantity));
        }
Exemplo n.º 11
0
        public void ToString_NullArgs_ThrowsArgumentNullException()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Throws <ArgumentNullException>(() => quantity.ToString(null, "g", null));
        }
Exemplo n.º 12
0
        public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException()
        {
            var v = Luminosity.FromWatts(1);

            Assert.Throws <ArgumentOutOfRangeException>(() => v.Equals(Luminosity.FromWatts(1), -1, ComparisonType.Relative));
        }
Exemplo n.º 13
0
        public void ToBaseUnit_ReturnsQuantityWithBaseUnit()
        {
            var quantityInBaseUnit = Luminosity.FromWatts(1).ToBaseUnit();

            Assert.Equal(Luminosity.BaseUnit, quantityInBaseUnit.Unit);
        }
Exemplo n.º 14
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(QuantityType.Luminosity, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
Exemplo n.º 15
0
        public void Convert_ToInt32_EqualsValueAsSameType()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity));
        }
Exemplo n.º 16
0
        public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(Luminosity.Info, Convert.ChangeType(quantity, typeof(QuantityInfo)));
        }
Exemplo n.º 17
0
        public void Convert_ToSByte_EqualsValueAsSameType()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity));
        }
Exemplo n.º 18
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
Exemplo n.º 19
0
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
Exemplo n.º 20
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = Luminosity.FromWatts(value);

            Assert.Equal(Luminosity.FromWatts(-value), -quantity);
        }
Exemplo n.º 21
0
        public void Convert_ToString_EqualsToString()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
Exemplo n.º 22
0
 public void FromWatts_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Luminosity.FromWatts(double.NaN));
 }
Exemplo n.º 23
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
Exemplo n.º 24
0
        public void EqualsReturnsFalseOnNull()
        {
            Luminosity watt = Luminosity.FromWatts(1);

            Assert.False(watt.Equals(null));
        }
Exemplo n.º 25
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Luminosity)));
        }
Exemplo n.º 26
0
        public void ToUnit()
        {
            var watt = Luminosity.FromWatts(1);

            var decawattQuantity = watt.ToUnit(LuminosityUnit.Decawatt);

            AssertEx.EqualTolerance(DecawattsInOneWatt, (double)decawattQuantity.Value, DecawattsTolerance);
            Assert.Equal(LuminosityUnit.Decawatt, decawattQuantity.Unit);

            var deciwattQuantity = watt.ToUnit(LuminosityUnit.Deciwatt);

            AssertEx.EqualTolerance(DeciwattsInOneWatt, (double)deciwattQuantity.Value, DeciwattsTolerance);
            Assert.Equal(LuminosityUnit.Deciwatt, deciwattQuantity.Unit);

            var femtowattQuantity = watt.ToUnit(LuminosityUnit.Femtowatt);

            AssertEx.EqualTolerance(FemtowattsInOneWatt, (double)femtowattQuantity.Value, FemtowattsTolerance);
            Assert.Equal(LuminosityUnit.Femtowatt, femtowattQuantity.Unit);

            var gigawattQuantity = watt.ToUnit(LuminosityUnit.Gigawatt);

            AssertEx.EqualTolerance(GigawattsInOneWatt, (double)gigawattQuantity.Value, GigawattsTolerance);
            Assert.Equal(LuminosityUnit.Gigawatt, gigawattQuantity.Unit);

            var kilowattQuantity = watt.ToUnit(LuminosityUnit.Kilowatt);

            AssertEx.EqualTolerance(KilowattsInOneWatt, (double)kilowattQuantity.Value, KilowattsTolerance);
            Assert.Equal(LuminosityUnit.Kilowatt, kilowattQuantity.Unit);

            var megawattQuantity = watt.ToUnit(LuminosityUnit.Megawatt);

            AssertEx.EqualTolerance(MegawattsInOneWatt, (double)megawattQuantity.Value, MegawattsTolerance);
            Assert.Equal(LuminosityUnit.Megawatt, megawattQuantity.Unit);

            var microwattQuantity = watt.ToUnit(LuminosityUnit.Microwatt);

            AssertEx.EqualTolerance(MicrowattsInOneWatt, (double)microwattQuantity.Value, MicrowattsTolerance);
            Assert.Equal(LuminosityUnit.Microwatt, microwattQuantity.Unit);

            var milliwattQuantity = watt.ToUnit(LuminosityUnit.Milliwatt);

            AssertEx.EqualTolerance(MilliwattsInOneWatt, (double)milliwattQuantity.Value, MilliwattsTolerance);
            Assert.Equal(LuminosityUnit.Milliwatt, milliwattQuantity.Unit);

            var nanowattQuantity = watt.ToUnit(LuminosityUnit.Nanowatt);

            AssertEx.EqualTolerance(NanowattsInOneWatt, (double)nanowattQuantity.Value, NanowattsTolerance);
            Assert.Equal(LuminosityUnit.Nanowatt, nanowattQuantity.Unit);

            var petawattQuantity = watt.ToUnit(LuminosityUnit.Petawatt);

            AssertEx.EqualTolerance(PetawattsInOneWatt, (double)petawattQuantity.Value, PetawattsTolerance);
            Assert.Equal(LuminosityUnit.Petawatt, petawattQuantity.Unit);

            var picowattQuantity = watt.ToUnit(LuminosityUnit.Picowatt);

            AssertEx.EqualTolerance(PicowattsInOneWatt, (double)picowattQuantity.Value, PicowattsTolerance);
            Assert.Equal(LuminosityUnit.Picowatt, picowattQuantity.Unit);

            var solarluminosityQuantity = watt.ToUnit(LuminosityUnit.SolarLuminosity);

            AssertEx.EqualTolerance(SolarLuminositiesInOneWatt, (double)solarluminosityQuantity.Value, SolarLuminositiesTolerance);
            Assert.Equal(LuminosityUnit.SolarLuminosity, solarluminosityQuantity.Unit);

            var terawattQuantity = watt.ToUnit(LuminosityUnit.Terawatt);

            AssertEx.EqualTolerance(TerawattsInOneWatt, (double)terawattQuantity.Value, TerawattsTolerance);
            Assert.Equal(LuminosityUnit.Terawatt, terawattQuantity.Unit);

            var wattQuantity = watt.ToUnit(LuminosityUnit.Watt);

            AssertEx.EqualTolerance(WattsInOneWatt, (double)wattQuantity.Value, WattsTolerance);
            Assert.Equal(LuminosityUnit.Watt, wattQuantity.Unit);
        }
Exemplo n.º 27
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = Luminosity.FromWatts(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(LuminosityUnit)));
        }
Exemplo n.º 28
0
        public void CompareToThrowsOnNull()
        {
            Luminosity watt = Luminosity.FromWatts(1);

            Assert.Throws <ArgumentNullException>(() => watt.CompareTo(null));
        }
 public void NumberToWattsTest() =>
 Assert.Equal(Luminosity.FromWatts(2), 2.Watts());