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())); } }
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())); } }
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())); } }
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)); }
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)); }
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>()); }
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>()); }
private static QuantityBase MultiplyVectorFloat(QuantityBase left, QuantityBase right) { return(MultiplyFloatVector(right, left)); }
private static QuantityBase MultiplyMatrixDouble(QuantityBase left, QuantityBase right) { return(MultiplyDoubleMatrix(right, left)); }
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)); }
private static IUnit DivideUnits(QuantityBase left, QuantityBase right) { return(new UnitCreator(left.Unit).Divide(right.Unit).Create()); }
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)); }
private static Quantity <float> MultiplyFloatLong(QuantityBase left, QuantityBase right) { return(MultiplyLongFloat(right, left)); }
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)); }
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)); }
private static Quantity <float> DivideFloatLong(QuantityBase left, QuantityBase right) { return(DivideLongFloat(right, left)); }
private static Quantity <float> DivideFloatInt(QuantityBase left, QuantityBase right) { return(DivideIntFloat(right, left)); }
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)); }
private static Quantity <double> DivideDoubleLong(QuantityBase left, QuantityBase right) { return(DivideLongDouble(right, left)); }
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)); }
private static Quantity <double> DivideDoubleFloat(QuantityBase left, QuantityBase right) { return(DivideFloatDouble(right, left)); }
private static QuantityBase MultiplyVectorDouble(QuantityBase left, QuantityBase right) { return(MultiplyDoubleVector(right, left)); }
private static IUnit MultiplyUnits(QuantityBase left, QuantityBase right) { return(new UnitCreator().Multiply(left.Unit, right.Unit).Create()); }
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)); }
private static QuantityBase MultiplyMatrixFloat(QuantityBase left, QuantityBase right) { return(MultiplyFloatMatrix(right, left)); }
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)); }
private static Quantity <float> MultiplyFloatInt(QuantityBase left, QuantityBase right) { return(MultiplyIntFloat(right, left)); }
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)); }
private static Quantity <long> DivideIntLong(QuantityBase left, QuantityBase right) { return(DivideLongInt(right, left)); }
private static Quantity <long> MultiplyIntLong(QuantityBase left, QuantityBase right) { return(MultiplyLongInt(right, left)); }