Esempio n. 1
0
        public void EqualsRelativeToleranceIsImplemented()
        {
            var v = MassFraction.FromDecimalFractions(1);

            Assert.True(v.Equals(MassFraction.FromDecimalFractions(1), DecimalFractionsTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(MassFraction.Zero, DecimalFractionsTolerance, ComparisonType.Relative));
        }
Esempio n. 2
0
        public void ConversionRoundTrip()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            AssertEx.EqualTolerance(1, MassFraction.FromCentigramsPerGram(decimalfraction.CentigramsPerGram).DecimalFractions, CentigramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromCentigramsPerKilogram(decimalfraction.CentigramsPerKilogram).DecimalFractions, CentigramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromDecagramsPerGram(decimalfraction.DecagramsPerGram).DecimalFractions, DecagramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromDecagramsPerKilogram(decimalfraction.DecagramsPerKilogram).DecimalFractions, DecagramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromDecigramsPerGram(decimalfraction.DecigramsPerGram).DecimalFractions, DecigramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromDecigramsPerKilogram(decimalfraction.DecigramsPerKilogram).DecimalFractions, DecigramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromDecimalFractions(decimalfraction.DecimalFractions).DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromGramsPerGram(decimalfraction.GramsPerGram).DecimalFractions, GramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromGramsPerKilogram(decimalfraction.GramsPerKilogram).DecimalFractions, GramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromHectogramsPerGram(decimalfraction.HectogramsPerGram).DecimalFractions, HectogramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromHectogramsPerKilogram(decimalfraction.HectogramsPerKilogram).DecimalFractions, HectogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromKilogramsPerGram(decimalfraction.KilogramsPerGram).DecimalFractions, KilogramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromKilogramsPerKilogram(decimalfraction.KilogramsPerKilogram).DecimalFractions, KilogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromMicrogramsPerGram(decimalfraction.MicrogramsPerGram).DecimalFractions, MicrogramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromMicrogramsPerKilogram(decimalfraction.MicrogramsPerKilogram).DecimalFractions, MicrogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromMilligramsPerGram(decimalfraction.MilligramsPerGram).DecimalFractions, MilligramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromMilligramsPerKilogram(decimalfraction.MilligramsPerKilogram).DecimalFractions, MilligramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromNanogramsPerGram(decimalfraction.NanogramsPerGram).DecimalFractions, NanogramsPerGramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromNanogramsPerKilogram(decimalfraction.NanogramsPerKilogram).DecimalFractions, NanogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromPartsPerBillion(decimalfraction.PartsPerBillion).DecimalFractions, PartsPerBillionTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromPartsPerMillion(decimalfraction.PartsPerMillion).DecimalFractions, PartsPerMillionTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromPartsPerThousand(decimalfraction.PartsPerThousand).DecimalFractions, PartsPerThousandTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromPartsPerTrillion(decimalfraction.PartsPerTrillion).DecimalFractions, PartsPerTrillionTolerance);
            AssertEx.EqualTolerance(1, MassFraction.FromPercent(decimalfraction.Percent).DecimalFractions, PercentTolerance);
        }
Esempio n. 3
0
        public void As()
        {
            var decimalfraction = MassFraction.FromDecimalFractions(1);

            AssertEx.EqualTolerance(CentigramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.CentigramPerGram), CentigramsPerGramTolerance);
            AssertEx.EqualTolerance(CentigramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.CentigramPerKilogram), CentigramsPerKilogramTolerance);
            AssertEx.EqualTolerance(DecagramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.DecagramPerGram), DecagramsPerGramTolerance);
            AssertEx.EqualTolerance(DecagramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.DecagramPerKilogram), DecagramsPerKilogramTolerance);
            AssertEx.EqualTolerance(DecigramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.DecigramPerGram), DecigramsPerGramTolerance);
            AssertEx.EqualTolerance(DecigramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.DecigramPerKilogram), DecigramsPerKilogramTolerance);
            AssertEx.EqualTolerance(DecimalFractionsInOneDecimalFraction, decimalfraction.As(MassFractionUnit.DecimalFraction), DecimalFractionsTolerance);
            AssertEx.EqualTolerance(GramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.GramPerGram), GramsPerGramTolerance);
            AssertEx.EqualTolerance(GramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.GramPerKilogram), GramsPerKilogramTolerance);
            AssertEx.EqualTolerance(HectogramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.HectogramPerGram), HectogramsPerGramTolerance);
            AssertEx.EqualTolerance(HectogramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.HectogramPerKilogram), HectogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(KilogramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.KilogramPerGram), KilogramsPerGramTolerance);
            AssertEx.EqualTolerance(KilogramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.KilogramPerKilogram), KilogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(MicrogramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.MicrogramPerGram), MicrogramsPerGramTolerance);
            AssertEx.EqualTolerance(MicrogramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.MicrogramPerKilogram), MicrogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(MilligramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.MilligramPerGram), MilligramsPerGramTolerance);
            AssertEx.EqualTolerance(MilligramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.MilligramPerKilogram), MilligramsPerKilogramTolerance);
            AssertEx.EqualTolerance(NanogramsPerGramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.NanogramPerGram), NanogramsPerGramTolerance);
            AssertEx.EqualTolerance(NanogramsPerKilogramInOneDecimalFraction, decimalfraction.As(MassFractionUnit.NanogramPerKilogram), NanogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(PartsPerBillionInOneDecimalFraction, decimalfraction.As(MassFractionUnit.PartPerBillion), PartsPerBillionTolerance);
            AssertEx.EqualTolerance(PartsPerMillionInOneDecimalFraction, decimalfraction.As(MassFractionUnit.PartPerMillion), PartsPerMillionTolerance);
            AssertEx.EqualTolerance(PartsPerThousandInOneDecimalFraction, decimalfraction.As(MassFractionUnit.PartPerThousand), PartsPerThousandTolerance);
            AssertEx.EqualTolerance(PartsPerTrillionInOneDecimalFraction, decimalfraction.As(MassFractionUnit.PartPerTrillion), PartsPerTrillionTolerance);
            AssertEx.EqualTolerance(PercentInOneDecimalFraction, decimalfraction.As(MassFractionUnit.Percent), PercentTolerance);
        }
Esempio n. 4
0
        public void DecimalFractionToMassFractionUnits()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            AssertEx.EqualTolerance(CentigramsPerGramInOneDecimalFraction, decimalfraction.CentigramsPerGram, CentigramsPerGramTolerance);
            AssertEx.EqualTolerance(CentigramsPerKilogramInOneDecimalFraction, decimalfraction.CentigramsPerKilogram, CentigramsPerKilogramTolerance);
            AssertEx.EqualTolerance(DecagramsPerGramInOneDecimalFraction, decimalfraction.DecagramsPerGram, DecagramsPerGramTolerance);
            AssertEx.EqualTolerance(DecagramsPerKilogramInOneDecimalFraction, decimalfraction.DecagramsPerKilogram, DecagramsPerKilogramTolerance);
            AssertEx.EqualTolerance(DecigramsPerGramInOneDecimalFraction, decimalfraction.DecigramsPerGram, DecigramsPerGramTolerance);
            AssertEx.EqualTolerance(DecigramsPerKilogramInOneDecimalFraction, decimalfraction.DecigramsPerKilogram, DecigramsPerKilogramTolerance);
            AssertEx.EqualTolerance(DecimalFractionsInOneDecimalFraction, decimalfraction.DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(GramsPerGramInOneDecimalFraction, decimalfraction.GramsPerGram, GramsPerGramTolerance);
            AssertEx.EqualTolerance(GramsPerKilogramInOneDecimalFraction, decimalfraction.GramsPerKilogram, GramsPerKilogramTolerance);
            AssertEx.EqualTolerance(HectogramsPerGramInOneDecimalFraction, decimalfraction.HectogramsPerGram, HectogramsPerGramTolerance);
            AssertEx.EqualTolerance(HectogramsPerKilogramInOneDecimalFraction, decimalfraction.HectogramsPerKilogram, HectogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(KilogramsPerGramInOneDecimalFraction, decimalfraction.KilogramsPerGram, KilogramsPerGramTolerance);
            AssertEx.EqualTolerance(KilogramsPerKilogramInOneDecimalFraction, decimalfraction.KilogramsPerKilogram, KilogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(MicrogramsPerGramInOneDecimalFraction, decimalfraction.MicrogramsPerGram, MicrogramsPerGramTolerance);
            AssertEx.EqualTolerance(MicrogramsPerKilogramInOneDecimalFraction, decimalfraction.MicrogramsPerKilogram, MicrogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(MilligramsPerGramInOneDecimalFraction, decimalfraction.MilligramsPerGram, MilligramsPerGramTolerance);
            AssertEx.EqualTolerance(MilligramsPerKilogramInOneDecimalFraction, decimalfraction.MilligramsPerKilogram, MilligramsPerKilogramTolerance);
            AssertEx.EqualTolerance(NanogramsPerGramInOneDecimalFraction, decimalfraction.NanogramsPerGram, NanogramsPerGramTolerance);
            AssertEx.EqualTolerance(NanogramsPerKilogramInOneDecimalFraction, decimalfraction.NanogramsPerKilogram, NanogramsPerKilogramTolerance);
            AssertEx.EqualTolerance(PartsPerBillionInOneDecimalFraction, decimalfraction.PartsPerBillion, PartsPerBillionTolerance);
            AssertEx.EqualTolerance(PartsPerMillionInOneDecimalFraction, decimalfraction.PartsPerMillion, PartsPerMillionTolerance);
            AssertEx.EqualTolerance(PartsPerThousandInOneDecimalFraction, decimalfraction.PartsPerThousand, PartsPerThousandTolerance);
            AssertEx.EqualTolerance(PartsPerTrillionInOneDecimalFraction, decimalfraction.PartsPerTrillion, PartsPerTrillionTolerance);
            AssertEx.EqualTolerance(PercentInOneDecimalFraction, decimalfraction.Percent, PercentTolerance);
        }
Esempio n. 5
0
        public void CompareToIsImplemented()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            Assert.Equal(0, decimalfraction.CompareTo(decimalfraction));
            Assert.True(decimalfraction.CompareTo(MassFraction.Zero) > 0);
            Assert.True(MassFraction.Zero.CompareTo(decimalfraction) < 0);
        }
Esempio n. 6
0
        public void EqualsIsImplemented()
        {
            var a = MassFraction.FromDecimalFractions(1);
            var b = MassFraction.FromDecimalFractions(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals(null));
        }
Esempio n. 7
0
        public void ArithmeticOperators()
        {
            MassFraction v = MassFraction.FromDecimalFractions(1);

            AssertEx.EqualTolerance(-1, -v.DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(2, (MassFraction.FromDecimalFractions(3) - v).DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(2, (v + v).DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(10, (v * 10).DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(10, (10 * v).DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(2, (MassFraction.FromDecimalFractions(10) / 5).DecimalFractions, DecimalFractionsTolerance);
            AssertEx.EqualTolerance(2, MassFraction.FromDecimalFractions(10) / MassFraction.FromDecimalFractions(5), DecimalFractionsTolerance);
        }
Esempio n. 8
0
        public void ComparisonOperators()
        {
            MassFraction oneDecimalFraction  = MassFraction.FromDecimalFractions(1);
            MassFraction twoDecimalFractions = MassFraction.FromDecimalFractions(2);

            Assert.True(oneDecimalFraction < twoDecimalFractions);
            Assert.True(oneDecimalFraction <= twoDecimalFractions);
            Assert.True(twoDecimalFractions > oneDecimalFraction);
            Assert.True(twoDecimalFractions >= oneDecimalFraction);

            Assert.False(oneDecimalFraction > twoDecimalFractions);
            Assert.False(oneDecimalFraction >= twoDecimalFractions);
            Assert.False(twoDecimalFractions < oneDecimalFraction);
            Assert.False(twoDecimalFractions <= oneDecimalFraction);
        }
Esempio n. 9
0
        public void EqualityOperators()
        {
            var a = MassFraction.FromDecimalFractions(1);
            var b = MassFraction.FromDecimalFractions(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
        }
Esempio n. 10
0
        public void CompareToThrowsOnNull()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            Assert.Throws <ArgumentNullException>(() => decimalfraction.CompareTo(null));
        }
Esempio n. 11
0
        public void CompareToThrowsOnTypeMismatch()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            Assert.Throws <ArgumentException>(() => decimalfraction.CompareTo(new object()));
        }
 /// <inheritdoc cref="MassFraction.FromDecimalFractions(UnitsNet.QuantityValue)" />
 public static MassFraction DecimalFractions <T>(this T value) =>
 MassFraction.FromDecimalFractions(Convert.ToDouble(value));
Esempio n. 13
0
        public void ToUnit()
        {
            var decimalfraction = MassFraction.FromDecimalFractions(1);

            var centigrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.CentigramPerGram);

            AssertEx.EqualTolerance(CentigramsPerGramInOneDecimalFraction, (double)centigrampergramQuantity.Value, CentigramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.CentigramPerGram, centigrampergramQuantity.Unit);

            var centigramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.CentigramPerKilogram);

            AssertEx.EqualTolerance(CentigramsPerKilogramInOneDecimalFraction, (double)centigramperkilogramQuantity.Value, CentigramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.CentigramPerKilogram, centigramperkilogramQuantity.Unit);

            var decagrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.DecagramPerGram);

            AssertEx.EqualTolerance(DecagramsPerGramInOneDecimalFraction, (double)decagrampergramQuantity.Value, DecagramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.DecagramPerGram, decagrampergramQuantity.Unit);

            var decagramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.DecagramPerKilogram);

            AssertEx.EqualTolerance(DecagramsPerKilogramInOneDecimalFraction, (double)decagramperkilogramQuantity.Value, DecagramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.DecagramPerKilogram, decagramperkilogramQuantity.Unit);

            var decigrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.DecigramPerGram);

            AssertEx.EqualTolerance(DecigramsPerGramInOneDecimalFraction, (double)decigrampergramQuantity.Value, DecigramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.DecigramPerGram, decigrampergramQuantity.Unit);

            var decigramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.DecigramPerKilogram);

            AssertEx.EqualTolerance(DecigramsPerKilogramInOneDecimalFraction, (double)decigramperkilogramQuantity.Value, DecigramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.DecigramPerKilogram, decigramperkilogramQuantity.Unit);

            var decimalfractionQuantity = decimalfraction.ToUnit(MassFractionUnit.DecimalFraction);

            AssertEx.EqualTolerance(DecimalFractionsInOneDecimalFraction, (double)decimalfractionQuantity.Value, DecimalFractionsTolerance);
            Assert.Equal(MassFractionUnit.DecimalFraction, decimalfractionQuantity.Unit);

            var grampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.GramPerGram);

            AssertEx.EqualTolerance(GramsPerGramInOneDecimalFraction, (double)grampergramQuantity.Value, GramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.GramPerGram, grampergramQuantity.Unit);

            var gramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.GramPerKilogram);

            AssertEx.EqualTolerance(GramsPerKilogramInOneDecimalFraction, (double)gramperkilogramQuantity.Value, GramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.GramPerKilogram, gramperkilogramQuantity.Unit);

            var hectogrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.HectogramPerGram);

            AssertEx.EqualTolerance(HectogramsPerGramInOneDecimalFraction, (double)hectogrampergramQuantity.Value, HectogramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.HectogramPerGram, hectogrampergramQuantity.Unit);

            var hectogramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.HectogramPerKilogram);

            AssertEx.EqualTolerance(HectogramsPerKilogramInOneDecimalFraction, (double)hectogramperkilogramQuantity.Value, HectogramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.HectogramPerKilogram, hectogramperkilogramQuantity.Unit);

            var kilogrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.KilogramPerGram);

            AssertEx.EqualTolerance(KilogramsPerGramInOneDecimalFraction, (double)kilogrampergramQuantity.Value, KilogramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.KilogramPerGram, kilogrampergramQuantity.Unit);

            var kilogramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.KilogramPerKilogram);

            AssertEx.EqualTolerance(KilogramsPerKilogramInOneDecimalFraction, (double)kilogramperkilogramQuantity.Value, KilogramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.KilogramPerKilogram, kilogramperkilogramQuantity.Unit);

            var microgrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.MicrogramPerGram);

            AssertEx.EqualTolerance(MicrogramsPerGramInOneDecimalFraction, (double)microgrampergramQuantity.Value, MicrogramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.MicrogramPerGram, microgrampergramQuantity.Unit);

            var microgramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.MicrogramPerKilogram);

            AssertEx.EqualTolerance(MicrogramsPerKilogramInOneDecimalFraction, (double)microgramperkilogramQuantity.Value, MicrogramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.MicrogramPerKilogram, microgramperkilogramQuantity.Unit);

            var milligrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.MilligramPerGram);

            AssertEx.EqualTolerance(MilligramsPerGramInOneDecimalFraction, (double)milligrampergramQuantity.Value, MilligramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.MilligramPerGram, milligrampergramQuantity.Unit);

            var milligramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.MilligramPerKilogram);

            AssertEx.EqualTolerance(MilligramsPerKilogramInOneDecimalFraction, (double)milligramperkilogramQuantity.Value, MilligramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.MilligramPerKilogram, milligramperkilogramQuantity.Unit);

            var nanogrampergramQuantity = decimalfraction.ToUnit(MassFractionUnit.NanogramPerGram);

            AssertEx.EqualTolerance(NanogramsPerGramInOneDecimalFraction, (double)nanogrampergramQuantity.Value, NanogramsPerGramTolerance);
            Assert.Equal(MassFractionUnit.NanogramPerGram, nanogrampergramQuantity.Unit);

            var nanogramperkilogramQuantity = decimalfraction.ToUnit(MassFractionUnit.NanogramPerKilogram);

            AssertEx.EqualTolerance(NanogramsPerKilogramInOneDecimalFraction, (double)nanogramperkilogramQuantity.Value, NanogramsPerKilogramTolerance);
            Assert.Equal(MassFractionUnit.NanogramPerKilogram, nanogramperkilogramQuantity.Unit);

            var partperbillionQuantity = decimalfraction.ToUnit(MassFractionUnit.PartPerBillion);

            AssertEx.EqualTolerance(PartsPerBillionInOneDecimalFraction, (double)partperbillionQuantity.Value, PartsPerBillionTolerance);
            Assert.Equal(MassFractionUnit.PartPerBillion, partperbillionQuantity.Unit);

            var partpermillionQuantity = decimalfraction.ToUnit(MassFractionUnit.PartPerMillion);

            AssertEx.EqualTolerance(PartsPerMillionInOneDecimalFraction, (double)partpermillionQuantity.Value, PartsPerMillionTolerance);
            Assert.Equal(MassFractionUnit.PartPerMillion, partpermillionQuantity.Unit);

            var partperthousandQuantity = decimalfraction.ToUnit(MassFractionUnit.PartPerThousand);

            AssertEx.EqualTolerance(PartsPerThousandInOneDecimalFraction, (double)partperthousandQuantity.Value, PartsPerThousandTolerance);
            Assert.Equal(MassFractionUnit.PartPerThousand, partperthousandQuantity.Unit);

            var partpertrillionQuantity = decimalfraction.ToUnit(MassFractionUnit.PartPerTrillion);

            AssertEx.EqualTolerance(PartsPerTrillionInOneDecimalFraction, (double)partpertrillionQuantity.Value, PartsPerTrillionTolerance);
            Assert.Equal(MassFractionUnit.PartPerTrillion, partpertrillionQuantity.Unit);

            var percentQuantity = decimalfraction.ToUnit(MassFractionUnit.Percent);

            AssertEx.EqualTolerance(PercentInOneDecimalFraction, (double)percentQuantity.Value, PercentTolerance);
            Assert.Equal(MassFractionUnit.Percent, percentQuantity.Unit);
        }
Esempio n. 14
0
 public void FromDecimalFractions_WithNanValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => MassFraction.FromDecimalFractions(double.NaN));
 }
Esempio n. 15
0
 public void FromDecimalFractions_WithInfinityValue_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => MassFraction.FromDecimalFractions(double.PositiveInfinity));
     Assert.Throws <ArgumentException>(() => MassFraction.FromDecimalFractions(double.NegativeInfinity));
 }
Esempio n. 16
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            Assert.False(decimalfraction.Equals(new object()));
        }
Esempio n. 17
0
        public void EqualsReturnsFalseOnNull()
        {
            MassFraction decimalfraction = MassFraction.FromDecimalFractions(1);

            Assert.False(decimalfraction.Equals(null));
        }
 public void NumberToDecimalFractionsTest() =>
 Assert.Equal(MassFraction.FromDecimalFractions(2), 2.DecimalFractions());