コード例 #1
0
        private static void DoAssosciativeQuantityMultiply <TLeft, TRight, TExpectedResult>()
        {
            IUnit             unit      = new Mock <IUnit>().Object;
            Quantity <TLeft>  left      = new Quantity <TLeft>(default(TLeft), unit);
            Quantity <TRight> right     = new Quantity <TRight>(default(TRight), unit);
            QuantityBase      lxrResult = left * right;
            QuantityBase      rxlResult = right * left;

            if (lxrResult == null)
            {
                throw new NullReferenceException("Result of left*right was null.");
            }
            if (rxlResult == null)
            {
                throw new NullReferenceException("Result of right*left was null.");
            }

            if (!(rxlResult is Quantity <TExpectedResult>))
            {
                throw new NotSupportedException(string.Format("Expected result type {0}, but got {1}.",
                                                              typeof(Quantity <TExpectedResult>), lxrResult.GetType()));
            }
            if (!(rxlResult is Quantity <TExpectedResult>))
            {
                throw new NotSupportedException(string.Format("Expected result type {0}, but got {1}.",
                                                              typeof(Quantity <TExpectedResult>), rxlResult.GetType()));
            }
        }
コード例 #2
0
        private static void DoAssosciativeQuantityDivide <TDividend, TDivisor, TExpectedResult>(TDividend nonZeroDividend, TDivisor nonZeroDivisor)
        {
            IUnit unit = new Mock <IUnit>().Object;
            Quantity <TDividend> dividend  = new Quantity <TDividend>(nonZeroDividend, unit);
            Quantity <TDivisor>  divisor   = new Quantity <TDivisor>(nonZeroDivisor, unit);
            QuantityBase         ldrResult = dividend / divisor;
            QuantityBase         rdlResult = divisor / dividend;

            if (ldrResult == null)
            {
                throw new NullReferenceException("Result of left / right was null.");
            }
            if (rdlResult == null)
            {
                throw new NullReferenceException("Result of right / left was null.");
            }

            if (!(ldrResult is Quantity <TExpectedResult>))
            {
                throw new NotSupportedException(string.Format("Expected result type {0}, but got {1}.",
                                                              typeof(Quantity <TExpectedResult>), ldrResult.GetType()));
            }
            if (!(rdlResult is Quantity <TExpectedResult>))
            {
                throw new NotSupportedException(string.Format("Expected result type {0}, but got {1}.",
                                                              typeof(Quantity <TExpectedResult>), rdlResult.GetType()));
            }
        }
コード例 #3
0
        private static void DoQuantitySubtract <TDividend, TDivisor, TExpectedResult>()
        {
            IUnit unit = new Mock <IUnit>().Object;
            Quantity <TDividend> dividend  = new Quantity <TDividend>(default(TDividend), unit);
            Quantity <TDivisor>  divisor   = new Quantity <TDivisor>(default(TDivisor), unit);
            QuantityBase         ldrResult = dividend - divisor;
            QuantityBase         rdlResult = divisor - dividend;

            if (ldrResult == null)
            {
                throw new NullReferenceException("Result of left - right was null.");
            }
            if (rdlResult == null)
            {
                throw new NullReferenceException("Result of right - left was null.");
            }

            if (!(ldrResult is Quantity <TExpectedResult>))
            {
                throw new NotSupportedException(string.Format("Expected result type {0}, but got {1}.",
                                                              typeof(Quantity <TExpectedResult>), ldrResult.GetType()));
            }
            if (!(rdlResult is Quantity <TExpectedResult>))
            {
                throw new NotSupportedException(string.Format("Expected result type {0}, but got {1}.",
                                                              typeof(Quantity <TExpectedResult>), rdlResult.GetType()));
            }
        }
コード例 #4
0
        private static QuantityBase MultiplyDoubleMatrix(QuantityBase left, QuantityBase right)
        {
            Quantity <double> leftQ = (Quantity <double>)left;
            Quantity <MathNet.Numerics.LinearAlgebra.Matrix <double> > rightQ = (Quantity <MathNet.Numerics.LinearAlgebra.Matrix <double> >)right;

            IUnit unit = MultiplyUnits(left, right);

            MathNet.Numerics.LinearAlgebra.Matrix <double> matrix = leftQ.Value * rightQ.Value;
            return(new Quantity <MathNet.Numerics.LinearAlgebra.Matrix <double> >(matrix, unit));
        }
コード例 #5
0
        private static QuantityBase MultiplyMatrixVector(QuantityBase left, QuantityBase right)
        {
            Quantity <MathNet.Numerics.LinearAlgebra.Matrix <double> > leftQ  = (Quantity <MathNet.Numerics.LinearAlgebra.Matrix <double> >)left;
            Quantity <MathNet.Numerics.LinearAlgebra.Vector <double> > rightQ = (Quantity <MathNet.Numerics.LinearAlgebra.Vector <double> >)right;

            IUnit unit = MultiplyUnits(left, right);

            MathNet.Numerics.LinearAlgebra.Vector <double> vector = leftQ.Value * rightQ.Value;
            return(new Quantity <MathNet.Numerics.LinearAlgebra.Vector <double> >(vector, unit));
        }
コード例 #6
0
ファイル: QuantityBaseTests.cs プロジェクト: larsmoa/Quants
        public void ValueCastDouble_ValueIsInt_DoesNotThrow()
        {
            // Arrange
            var mock = new Mock <QuantityBase>();

            mock.Setup(x => x.QuantityValueType).Returns(typeof(int));
            mock.Setup(x => x.QuantityValue).Returns(1);
            QuantityBase quantity = mock.Object;

            // Act/assert
            Assert.DoesNotThrow(() => quantity.ValueCast <double>());
        }
コード例 #7
0
ファイル: QuantityBaseTests.cs プロジェクト: larsmoa/Quants
        public void ValueCastNotRelated_ValueIsInt_ThrowsInvalidCast()
        {
            // Arrange
            var mock = new Mock <QuantityBase>();

            mock.Setup(x => x.QuantityValueType).Returns(typeof(int));
            mock.Setup(x => x.QuantityValue).Returns(1);
            QuantityBase quantity = mock.Object;


            // Act/assert
            Assert.Throws <InvalidCastException>(() => quantity.ValueCast <Array>());
        }
コード例 #8
0
 private static QuantityBase MultiplyVectorFloat(QuantityBase left, QuantityBase right)
 {
     return(MultiplyFloatVector(right, left));
 }
コード例 #9
0
 private static QuantityBase MultiplyMatrixDouble(QuantityBase left, QuantityBase right)
 {
     return(MultiplyDoubleMatrix(right, left));
 }
コード例 #10
0
        public static Quantity <long> SubtractLong(QuantityBase left, QuantityBase right)
        {
            long value = ((Quantity <long>)left).Value - ((Quantity <long>)right).Value;

            return(new Quantity <long>(value, left.Unit));
        }
コード例 #11
0
 private static IUnit DivideUnits(QuantityBase left, QuantityBase right)
 {
     return(new UnitCreator(left.Unit).Divide(right.Unit).Create());
 }
コード例 #12
0
        private static Quantity <float> MultiplyIntFloat(QuantityBase left, QuantityBase right)
        {
            IUnit unit = MultiplyUnits(left, right);

            return(new Quantity <float>(((Quantity <int>)left).Value * ((Quantity <float>)right).Value, unit));
        }
コード例 #13
0
 private static Quantity <float> MultiplyFloatLong(QuantityBase left, QuantityBase right)
 {
     return(MultiplyLongFloat(right, left));
 }
コード例 #14
0
        private static Quantity <long> MultiplyLongInt(QuantityBase left, QuantityBase right)
        {
            IUnit unit = MultiplyUnits(left, right);

            return(new Quantity <long>(((Quantity <long>)left).Value * ((Quantity <int>)right).Value, unit));
        }
コード例 #15
0
        private static Quantity <long> DivideLongInt(QuantityBase left, QuantityBase right)
        {
            IUnit unit = DivideUnits(left, right);

            return(new Quantity <long>(((Quantity <long>)left).Value / ((Quantity <int>)right).Value, unit));
        }
コード例 #16
0
 private static Quantity <float> DivideFloatLong(QuantityBase left, QuantityBase right)
 {
     return(DivideLongFloat(right, left));
 }
コード例 #17
0
 private static Quantity <float> DivideFloatInt(QuantityBase left, QuantityBase right)
 {
     return(DivideIntFloat(right, left));
 }
コード例 #18
0
        private static Quantity <float> DivideIntFloat(QuantityBase left, QuantityBase right)
        {
            IUnit unit = DivideUnits(left, right);

            return(new Quantity <float>(((Quantity <int>)left).Value / ((Quantity <float>)right).Value, unit));
        }
コード例 #19
0
 private static Quantity <double> DivideDoubleLong(QuantityBase left, QuantityBase right)
 {
     return(DivideLongDouble(right, left));
 }
コード例 #20
0
        private static Quantity <double> DivideIntDouble(QuantityBase left, QuantityBase right)
        {
            IUnit unit = DivideUnits(left, right);

            return(new Quantity <double>(((Quantity <int>)left).Value / ((Quantity <double>)right).Value, unit));
        }
コード例 #21
0
 private static Quantity <double> DivideDoubleFloat(QuantityBase left, QuantityBase right)
 {
     return(DivideFloatDouble(right, left));
 }
コード例 #22
0
 private static QuantityBase MultiplyVectorDouble(QuantityBase left, QuantityBase right)
 {
     return(MultiplyDoubleVector(right, left));
 }
コード例 #23
0
 private static IUnit MultiplyUnits(QuantityBase left, QuantityBase right)
 {
     return(new UnitCreator().Multiply(left.Unit, right.Unit).Create());
 }
コード例 #24
0
        public static Quantity <float> AddFloat(QuantityBase left, QuantityBase right)
        {
            float value = ((Quantity <float>)left).Value + ((Quantity <float>)right).Value;

            return(new Quantity <float>(value, left.Unit));
        }
コード例 #25
0
 private static QuantityBase MultiplyMatrixFloat(QuantityBase left, QuantityBase right)
 {
     return(MultiplyFloatMatrix(right, left));
 }
コード例 #26
0
        public static Quantity <double> SubtractDouble(QuantityBase left, QuantityBase right)
        {
            double value = ((Quantity <double>)left).Value - ((Quantity <double>)right).Value;

            return(new Quantity <double>(value, left.Unit));
        }
コード例 #27
0
 private static Quantity <float> MultiplyFloatInt(QuantityBase left, QuantityBase right)
 {
     return(MultiplyIntFloat(right, left));
 }
コード例 #28
0
        public static Quantity <int> SubtractInt(QuantityBase left, QuantityBase right)
        {
            int value = ((Quantity <int>)left).Value - ((Quantity <int>)right).Value;

            return(new Quantity <int>(value, left.Unit));
        }
コード例 #29
0
 private static Quantity <long> DivideIntLong(QuantityBase left, QuantityBase right)
 {
     return(DivideLongInt(right, left));
 }
コード例 #30
0
 private static Quantity <long> MultiplyIntLong(QuantityBase left, QuantityBase right)
 {
     return(MultiplyLongInt(right, left));
 }