public void ShouldAllowCastingAsDouble() { // when NumericExpression <double> cast = _castCall.AsDouble(); // then Assert.IsTrue(cast.Expression is DoubleCast); Assert.AreSame(_variable.Expression, cast.Expression.Arguments.ElementAt(0)); }
public void ShouldAllowCastingAsDecimal() { // when NumericExpression <decimal> cast = _castCall.AsDecimal(); // then Assert.True(cast.Expression is DecimalCast); Assert.Same(_variable.Expression, cast.Expression.Arguments.ElementAt(0)); }
public void ShouldAllowCreatingCallToStrlenFunctionWithVariableParameter() { // given VariableExpression var = new VariableExpression("mail"); // when NumericExpression <int> strlen = Builder.StrLen(var); // then Assert.True(strlen.Expression is StrLenFunction); Assert.Same(var.Expression, strlen.Expression.Arguments.ElementAt(0)); }
public void ShouldAllowArithmeticOperatorsWithGenericAndNongenericNumericExpressionsReversed() { NumericExpression left = new NumericExpression(Left); NumericExpression right = new NumericExpression <int>(15); Right = right.Expression; AssertExpressionTypeAndCorrectArguments <MultiplicationExpression>(left * right); AssertExpressionTypeAndCorrectArguments <DivisionExpression>(left / right); AssertExpressionTypeAndCorrectArguments <AdditionExpression>(left + right); AssertExpressionTypeAndCorrectArguments <SubtractionExpression>(left - right); }
public void ShouldAllowCreatingCallToStrlenFunctionWithStringLiteralParameter() { // given var literal = new TypedLiteralExpression <string>("mail"); // when NumericExpression <int> strlen = Builder.StrLen(literal); // then Assert.True(strlen.Expression is StrLenFunction); Assert.Same(literal.Expression, strlen.Expression.Arguments.ElementAt(0)); }
public void CanSubtractTypedNumericFromSimpleValue() { // given var right = new NumericExpression <decimal>(10); // when var multiplication = (10m - right).Expression; // then Assert.True(multiplication is SubtractionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanSubtractSimpleValueFromTypedNumeric() { // given var left = new NumericExpression <decimal>(10); // when var multiplication = (left - 10m).Expression; // then Assert.IsTrue(multiplication is SubtractionExpression); Assert.IsTrue(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.IsTrue(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanAddTypedNumericToSimpleValue() { // given var right = new NumericExpression <decimal>(10); // when var multiplication = (10m + right).Expression; // then Assert.IsTrue(multiplication is AdditionExpression); Assert.IsTrue(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.IsTrue(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanMultiplySimpleValueByNumeric() { // given var right = new NumericExpression(new VariableTerm("x")); // when var multiplication = (10 * right).Expression; // then Assert.True(multiplication is MultiplicationExpression); Assert.Same(right.Expression, multiplication.Arguments.ElementAt(1)); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); }
public void CanMultiplyNumericBySimpleValue() { // given var left = new NumericExpression(new VariableTerm("x")); // when var multiplication = (left * 10).Expression; // then Assert.True(multiplication is MultiplicationExpression); Assert.Same(left.Expression, multiplication.Arguments.ElementAt(0)); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanDivideTypedNumericBySimpleValue() { // given var left = new NumericExpression <decimal>(10); // when var multiplication = (left / 10m).Expression; // then Assert.IsTrue(multiplication is DivisionExpression); Assert.IsTrue(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.IsTrue(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanDivideSimpleValueByTypedNumeric() { // given var right = new NumericExpression <decimal>(10); // when var multiplication = (10m / right).Expression; // then Assert.True(multiplication is DivisionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanAddSimpleValueToTypedNumeric() { // given var left = new NumericExpression <decimal>(10); // when var multiplication = (left + 10m).Expression; // then Assert.True(multiplication is AdditionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanCreateSameTermFunctionUsingVariableNameForSecondParameter() { // given SparqlExpression right = new VariableExpression("x"); SparqlExpression left = new NumericExpression <int>(10); // when BooleanExpression sameTerm = Builder.SameTerm(left, "x"); // then Assert.IsTrue(sameTerm.Expression is SameTermFunction); Assert.AreSame(left.Expression, sameTerm.Expression.Arguments.ElementAt(0)); Assert.AreEqual(right.Expression.ToString(), sameTerm.Expression.Arguments.ElementAt(1).ToString()); }
public void CanCreateGreaterThanOperatorBetweenVariableAndLiteral() { // given VariableExpression v1 = new VariableExpression("v1"); LiteralExpression literal = new NumericExpression <int>(10); // when var areEqual = (v1 > literal).Expression; // then Assert.IsTrue(areEqual is GreaterThanExpression); Assert.IsTrue(areEqual.Arguments.ElementAt(0) is VariableTerm); Assert.IsTrue(areEqual.Arguments.ElementAt(1) is ConstantTerm); }
public void ShouldAllowComparingGenericAndNongenericNumericExpressionsReversed() { var right = new NumericExpression(Right); var left = new NumericExpression <int>(15); Left = left.Expression; AssertExpressionTypeAndCorrectArguments <EqualsExpression>(left == right); AssertExpressionTypeAndCorrectArguments <GreaterThanExpression>(left > right); AssertExpressionTypeAndCorrectArguments <GreaterThanOrEqualToExpression>(left >= right); AssertExpressionTypeAndCorrectArguments <LessThanExpression>(left < right); AssertExpressionTypeAndCorrectArguments <LessThanOrEqualToExpression>(left <= right); AssertExpressionTypeAndCorrectArguments <NotEqualsExpression>(left != right); }
public void ShouldAllowUsingArithmeticOperatorsWithVariableExpressionAndNumericExpression() { // given NumericExpression right = new NumericExpression(Right); VariableExpression left = new VariableExpression("number"); Left = left.Expression; // then AssertExpressionTypeAndCorrectArguments <MultiplicationExpression>(left * right); AssertExpressionTypeAndCorrectArguments <DivisionExpression>(left / right); AssertExpressionTypeAndCorrectArguments <AdditionExpression>(left + right); AssertExpressionTypeAndCorrectArguments <SubtractionExpression>(left - right); }
public void ShouldAllowCreatingCallToSubstrFunctionWithVariableAndIntegerParameter() { // given var literal = new VariableExpression("mail"); var startLocation = new NumericExpression <int>(5); // when TypedLiteralExpression <string> strlen = Builder.Substr(literal, 5); // then Assert.True(strlen.Expression is SubStrFunction); Assert.Same(literal.Expression, strlen.Expression.Arguments.ElementAt(0)); Assert.Equal(startLocation.Expression.ToString(), strlen.Expression.Arguments.ElementAt(1).ToString()); }
public void ShouldAllowCreatingCallToSubstrFunctionWithStringLiteralAndNumericExpressionParameter() { // given var literal = new TypedLiteralExpression <string>("mail"); var startLocation = new NumericExpression <int>(5); // when TypedLiteralExpression <string> strlen = Builder.Substr(literal, startLocation); // then Assert.True(strlen.Expression is SubStrFunction); Assert.Same(literal.Expression, strlen.Expression.Arguments.ElementAt(0)); Assert.Same(startLocation.Expression, strlen.Expression.Arguments.ElementAt(1)); }
public void CanDivideTypedNumericByUntypedNumeric() { // given NumericExpression <int> right = new NumericExpression <int>(10); NumericExpression left = new NumericExpression <decimal>(10); // when var multiplication = (right / left).Expression; // then Assert.IsTrue(multiplication is DivisionExpression); Assert.IsTrue(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.IsTrue(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanMultiplyTypedNumericAndUntypedNumeric2() { // given NumericExpression <int> right = new NumericExpression <int>(10); NumericExpression left = new NumericExpression <decimal>(10); // when var multiplication = (left * right).Expression; // then Assert.True(multiplication is MultiplicationExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanCreateSameTermFunction() { // given SparqlExpression left = new VariableExpression("x"); SparqlExpression right = new NumericExpression <int>(10); // when BooleanExpression sameTerm = Builder.SameTerm(left, right); // then Assert.IsTrue(sameTerm.Expression is SameTermFunction); Assert.AreSame(left.Expression, sameTerm.Expression.Arguments.ElementAt(0)); Assert.AreSame(right.Expression, sameTerm.Expression.Arguments.ElementAt(1)); }
public void CanSubtractTypedNumericToUntypedNumeric() { // given NumericExpression <int> right = new NumericExpression <int>(10); NumericExpression left = new NumericExpression <decimal>(10); // when var multiplication = (right - left).Expression; // then Assert.True(multiplication is SubtractionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanSubtractTypedNumericsOfMatchingTypes() { // given NumericExpression <int> right = new NumericExpression <int>(10); NumericExpression <int> left = new NumericExpression <int>(10); // when var multiplication = (left - right).Expression; // then Assert.True(multiplication is SubtractionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanAddTypedNumericsOfdifferentTypes() { // given NumericExpression <int> right = new NumericExpression <int>(10); NumericExpression <decimal> left = new NumericExpression <decimal>(10); // when var multiplication = (left + right).Expression; // then Assert.True(multiplication is AdditionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is ConstantTerm); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void CanChainSubtractionsOfNumerics() { // given NumericExpression <int> op2 = new NumericExpression <int>(10); NumericExpression <decimal> op1 = new NumericExpression <decimal>(10); NumericExpression <int> op3 = new NumericExpression <int>(5); // when var multiplication = (op1 - op2 - op3).Expression; // then Assert.True(multiplication is SubtractionExpression); Assert.True(multiplication.Arguments.ElementAt(0) is SubtractionExpression); Assert.True(multiplication.Arguments.ElementAt(1) is ConstantTerm); }
public void ShouldAllowUsingArithmeticOperatorsWithSignedByteAndNumericExpression() { // given const sbyte operandValue = 10; NumericExpression left = new NumericExpression(Left); // then AssertExpressionTypeAndCorrectArguments <MultiplicationExpression>(left * operandValue, assertRightOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); AssertExpressionTypeAndCorrectArguments <DivisionExpression>(left / operandValue, assertRightOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); AssertExpressionTypeAndCorrectArguments <AdditionExpression>(left + operandValue, assertRightOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); AssertExpressionTypeAndCorrectArguments <SubtractionExpression>(left - operandValue, assertRightOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); }
public void ShouldAllowCreatingCallToSubstrFunctionWithStringLiteralAndIntegerAndIntegerExpressionParameter() { // given var literal = new TypedLiteralExpression <string>("mail"); var startLocation = new NumericExpression <int>(5); var length = new NumericExpression <int>(5); // when TypedLiteralExpression <string> strlen = Builder.Substr(literal, 5, length); // then Assert.IsTrue(strlen.Expression is SubStrFunction); Assert.AreSame(literal.Expression, strlen.Expression.Arguments.ElementAt(0)); Assert.AreEqual(startLocation.Expression.ToString(), strlen.Expression.Arguments.ElementAt(1).ToString()); Assert.AreSame(length.Expression, strlen.Expression.Arguments.ElementAt(2)); }
public void ShouldAllowCreatingCallToSubstrFunctionWithLiteralExpressionAndVariableAndIntegerExpressionParameters() { // given var literal = new TypedLiteralExpression <string>("mail"); var startLocation = new VariableExpression("startFrom"); var length = new NumericExpression <int>(5); // when TypedLiteralExpression <string> strlen = Builder.Substr(literal, startLocation, length); // then Assert.True(strlen.Expression is SubStrFunction); Assert.Same(literal.Expression, strlen.Expression.Arguments.ElementAt(0)); Assert.Same(startLocation.Expression, strlen.Expression.Arguments.ElementAt(1)); Assert.Same(length.Expression, strlen.Expression.Arguments.ElementAt(2)); }
public void ShouldAllowUsingArithmeticOperatorsWithNumericExpressionAndSignedByte() { // given const sbyte operandValue = 10; NumericExpression right = new NumericExpression(Right); // then AssertExpressionTypeAndCorrectArguments <MultiplicationExpression>(operandValue * right, assertLeftOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); AssertExpressionTypeAndCorrectArguments <DivisionExpression>(operandValue / right, assertLeftOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); AssertExpressionTypeAndCorrectArguments <AdditionExpression>(operandValue + right, assertLeftOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); AssertExpressionTypeAndCorrectArguments <SubtractionExpression>(operandValue - right, assertLeftOperand: ex => AssertCorrectConstantTerm(ex, operandValue)); }