예제 #1
0
        public void CompareToThrowsOnNull()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            internationalunit.CompareTo(null);
        }
예제 #2
0
        public void EqualsIsImplemented()
        {
            VitaminA v = VitaminA.FromInternationalUnits(1);

            Assert.IsTrue(v.Equals(VitaminA.FromInternationalUnits(1)));
            Assert.IsFalse(v.Equals(VitaminA.Zero));
        }
예제 #3
0
        public void EqualsIsImplemented()
        {
            VitaminA v = VitaminA.FromInternationalUnits(1);

            Assert.True(v.Equals(VitaminA.FromInternationalUnits(1), VitaminA.FromInternationalUnits(InternationalUnitsTolerance)));
            Assert.False(v.Equals(VitaminA.Zero, VitaminA.FromInternationalUnits(InternationalUnitsTolerance)));
        }
예제 #4
0
        public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = VitaminA.FromInternationalUnits(1);

            Assert.True(v.Equals(VitaminA.FromInternationalUnits(1), InternationalUnitsTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(VitaminA.Zero, InternationalUnitsTolerance, ComparisonType.Relative));
        }
예제 #5
0
        public void CompareToThrowsOnTypeMismatch()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            internationalunit.CompareTo(new object());
        }
예제 #6
0
        public void Equals_SameType_IsImplemented()
        {
            var a = VitaminA.FromInternationalUnits(1);
            var b = VitaminA.FromInternationalUnits(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
예제 #7
0
        public void CompareToIsImplemented()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.Equal(0, internationalunit.CompareTo(internationalunit));
            Assert.True(internationalunit.CompareTo(VitaminA.Zero) > 0);
            Assert.True(VitaminA.Zero.CompareTo(internationalunit) < 0);
        }
        public void FromInternationalUnits_WithInfinityValue_CreateQuantityAndAffectInfinityValue()
        {
            var positiveInfinityQuantity = VitaminA.FromInternationalUnits(double.PositiveInfinity);
            var negativeInfinityQuantity = VitaminA.FromInternationalUnits(double.NegativeInfinity);

            Assert.True(double.IsPositiveInfinity(positiveInfinityQuantity.Value));
            Assert.True(double.IsNegativeInfinity(negativeInfinityQuantity.Value));
        }
예제 #9
0
        public void CompareToIsImplemented()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.AreEqual(0, internationalunit.CompareTo(internationalunit));
            Assert.Greater(internationalunit.CompareTo(VitaminA.Zero), 0);
            Assert.Less(VitaminA.Zero.CompareTo(internationalunit), 0);
        }
예제 #10
0
        public void ToUnit()
        {
            var internationalunit = VitaminA.FromInternationalUnits(1);

            var internationalunitQuantity = internationalunit.ToUnit(VitaminAUnit.InternationalUnit);

            AssertEx.EqualTolerance(InternationalUnitsInOneInternationalUnit, (double)internationalunitQuantity.Value, InternationalUnitsTolerance);
            Assert.Equal(VitaminAUnit.InternationalUnit, internationalunitQuantity.Unit);
        }
예제 #11
0
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = VitaminA.FromInternationalUnits(1);
            object b = VitaminA.FromInternationalUnits(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
예제 #12
0
        public void ArithmeticOperators()
        {
            VitaminA v = VitaminA.FromInternationalUnits(1);

            Assert.AreEqual(-1, -v.InternationalUnits, InternationalUnitsTolerance);
            Assert.AreEqual(2, (VitaminA.FromInternationalUnits(3) - v).InternationalUnits, InternationalUnitsTolerance);
            Assert.AreEqual(2, (v + v).InternationalUnits, InternationalUnitsTolerance);
            Assert.AreEqual(10, (v * 10).InternationalUnits, InternationalUnitsTolerance);
            Assert.AreEqual(10, (10 * v).InternationalUnits, InternationalUnitsTolerance);
            Assert.AreEqual(2, (VitaminA.FromInternationalUnits(10) / 5).InternationalUnits, InternationalUnitsTolerance);
            Assert.AreEqual(2, VitaminA.FromInternationalUnits(10) / VitaminA.FromInternationalUnits(5), InternationalUnitsTolerance);
        }
예제 #13
0
        public void To_UnitSystem_ThrowsArgumentExceptionIfNotSupported()
        {
            var internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.SI));
            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.CGS));
            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.BI));
            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.EE));
            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.USC));
            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.FPS));
            Assert.Throws <ArgumentException>(() => internationalunit.ToUnit(UnitSystem.Astronomical));
        }
예제 #14
0
        public void EqualityOperators()
        {
            VitaminA a = VitaminA.FromInternationalUnits(1);
            VitaminA b = VitaminA.FromInternationalUnits(2);

// ReSharper disable EqualExpressionComparison
            Assert.True(a == a);
            Assert.True(a != b);

            Assert.False(a == b);
            Assert.False(a != a);
// ReSharper restore EqualExpressionComparison
        }
예제 #15
0
        public void ComparisonOperators()
        {
            VitaminA oneInternationalUnit  = VitaminA.FromInternationalUnits(1);
            VitaminA twoInternationalUnits = VitaminA.FromInternationalUnits(2);

            Assert.True(oneInternationalUnit < twoInternationalUnits);
            Assert.True(oneInternationalUnit <= twoInternationalUnits);
            Assert.True(twoInternationalUnits > oneInternationalUnit);
            Assert.True(twoInternationalUnits >= oneInternationalUnit);

            Assert.False(oneInternationalUnit > twoInternationalUnits);
            Assert.False(oneInternationalUnit >= twoInternationalUnits);
            Assert.False(twoInternationalUnits < oneInternationalUnit);
            Assert.False(twoInternationalUnits <= oneInternationalUnit);
        }
예제 #16
0
        public void EqualityOperators()
        {
            var a = VitaminA.FromInternationalUnits(1);
            var b = VitaminA.FromInternationalUnits(2);

#pragma warning disable CS8073
// 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
#pragma warning restore CS8073
        }
예제 #17
0
        public void ConversionRoundTrip()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.AreEqual(1, VitaminA.FromInternationalUnits(internationalunit.InternationalUnits).InternationalUnits, InternationalUnitsTolerance);
        }
예제 #18
0
        public void As()
        {
            var internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.AreEqual(InternationalUnitsInOneInternationalUnit, internationalunit.As(VitaminAUnit.InternationalUnit), InternationalUnitsTolerance);
        }
예제 #19
0
        public void InternationalUnitToVitaminAUnits()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.AreEqual(InternationalUnitsInOneInternationalUnit, internationalunit.InternationalUnits, InternationalUnitsTolerance);
        }
예제 #20
0
        public void EqualsReturnsFalseOnNull()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.IsFalse(internationalunit.Equals(null));
        }
예제 #21
0
        public void GetHashCode_Equals()
        {
            var quantity = VitaminA.FromInternationalUnits(1.0);

            Assert.Equal(new { VitaminA.Info.Name, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
 /// <inheritdoc cref="VitaminA.FromInternationalUnits(UnitsNet.QuantityValue)" />
 public static VitaminA InternationalUnits(this decimal value) => VitaminA.FromInternationalUnits(Convert.ToDouble(value));
예제 #23
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = VitaminA.FromInternationalUnits(1.0);

            Assert.Equal(VitaminA.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
예제 #24
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = VitaminA.FromInternationalUnits(value);

            Assert.Equal(VitaminA.FromInternationalUnits(-value), -quantity);
        }
 /// <inheritdoc cref="VitaminA.FromInternationalUnits(UnitsNet.QuantityValue)" />
 public static VitaminA InternationalUnits(this double value) => VitaminA.FromInternationalUnits(value);
예제 #26
0
        public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo()
        {
            var quantity = VitaminA.FromInternationalUnits(1.0);

            Assert.Equal(VitaminA.Info, Convert.ChangeType(quantity, typeof(QuantityInfo)));
        }
 /// <inheritdoc cref="VitaminA.FromInternationalUnits(UnitsNet.QuantityValue)" />
 public static VitaminA?InternationalUnits(this float?value) => VitaminA.FromInternationalUnits(value);
예제 #28
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = VitaminA.FromInternationalUnits(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }
 /// <inheritdoc cref="VitaminA.FromInternationalUnits(UnitsNet.QuantityValue)" />
 public static VitaminA?InternationalUnits(this decimal?value) => VitaminA.FromInternationalUnits(value == null ? (double?)null : Convert.ToDouble(value.Value));
예제 #30
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            VitaminA internationalunit = VitaminA.FromInternationalUnits(1);

            Assert.IsFalse(internationalunit.Equals(new object()));
        }