21 using NUnit.Framework;
23 namespace Deveel.Data.Sql.Expressions {
33 Assert.DoesNotThrow(() => resultExp = addExp.
Evaluate());
34 Assert.IsNotNull(resultExp);
38 Assert.IsNotNull(constExp.Value.Value);
39 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
40 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
43 var expected =
new SqlNumber(13557.67, 2);
45 Assert.AreEqual(expected, actual);
55 Assert.DoesNotThrow(() => s = addExp.ToString());
58 Assert.AreEqual(
"4566 + 8991.670000", s);
68 Assert.DoesNotThrow(() => resultExp = addExp.
Evaluate());
69 Assert.IsNotNull(resultExp);
73 Assert.IsNotNull(constExp.Value.Value);
74 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
75 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
79 Assert.AreEqual(expected, actual);
89 Assert.DoesNotThrow(() => resultExp = addExp.
Evaluate());
90 Assert.IsNotNull(resultExp);
94 Assert.IsNotNull(constExp.Value.Value);
95 Assert.IsInstanceOf<
StringType>(constExp.Value.Type);
96 Assert.IsInstanceOf<
SqlString>(constExp.Value.Value);
97 Assert.AreEqual(
new SqlString(
"The quick brown fox jumps over the lazy dog"), (
SqlString) constExp.
Value.Value);
107 Assert.DoesNotThrow(() => resultExp = subtractExp.
Evaluate());
108 Assert.IsNotNull(resultExp);
112 Assert.IsNotNull(constExp.Value.Value);
113 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
114 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
117 var expected =
new SqlNumber(877410.33, 2);
119 Assert.AreEqual(expected, actual);
129 Assert.DoesNotThrow(() => resultExp = subtractExp.
Evaluate());
130 Assert.IsNotNull(resultExp);
134 Assert.IsNotNull(constExp.Value.Value);
135 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
136 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
147 Assert.DoesNotThrow(() => resultExp = mulExp.
Evaluate());
148 Assert.IsNotNull(resultExp);
152 Assert.IsNotNull(constExp.Value.Value);
153 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
154 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
157 var expected =
new SqlNumber(25943705.04, 2);
158 Assert.AreEqual(expected, actual);
168 Assert.DoesNotThrow(() => resultExp = divExp.
Evaluate());
169 Assert.IsNotNull(resultExp);
173 Assert.IsNotNull(constExp.Value.Value);
174 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
175 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
178 var expected =
new SqlNumber(625.74702, 5);
179 Assert.AreEqual(expected, actual);
189 Assert.DoesNotThrow(() => resultExp = modExp.
Evaluate());
190 Assert.IsNotNull(resultExp);
194 Assert.IsNotNull(constExp.Value.Value);
195 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
196 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
199 var expected =
new SqlNumber(583.0623, 4);
200 Assert.AreEqual(expected, actual);
203 [TestCase(9862711.650091, 9862711.650091,
true)]
204 [TestCase(12345, 2345,
false)]
205 [TestCase(123456.789, 123456.7,
false)]
212 Assert.DoesNotThrow(() => resultExp = eqExp.
Evaluate());
213 Assert.IsNotNull(resultExp);
217 Assert.IsNotNull(constExp.Value.Value);
218 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
219 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
221 var actual = ((
SqlBoolean)constExp.Value.Value);
223 Assert.AreEqual(expectedResult, actual);
226 [TestCase(763525.22e11, 763525.22e11,
false)]
227 [TestCase(12345, 123456,
true)]
228 [TestCase(564255.23899, 564255.23,
true)]
235 Assert.DoesNotThrow(() => resultExp = eqExp.
Evaluate());
236 Assert.IsNotNull(resultExp);
240 Assert.IsNotNull(constExp.Value.Value);
241 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
242 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
244 var actual = ((
SqlBoolean)constExp.Value.Value);
246 Assert.AreEqual(expectedResult, actual);
249 [TestCase(123998, 123999,
false)]
250 [TestCase(8764556.9011, 8764556.901145,
false)]
251 [TestCase(244591, 24620,
true)]
258 Assert.DoesNotThrow(() => resultExp = grExp.
Evaluate());
259 Assert.IsNotNull(resultExp);
263 Assert.IsNotNull(constExp.Value.Value);
264 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
265 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
267 var actual = ((
SqlBoolean)constExp.Value.Value);
269 Assert.AreEqual(expectedResult, actual);
272 [TestCase(988271, 988271,
false)]
273 [TestCase(625.99e23, 12,
false)]
274 [TestCase(19283.9991e68, 19283.9991e69,
true)]
281 Assert.DoesNotThrow(() => resultExp = ltExp.
Evaluate());
282 Assert.IsNotNull(resultExp);
286 Assert.IsNotNull(constExp.Value.Value);
287 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
288 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
290 var actual = ((
SqlBoolean)constExp.Value.Value);
292 Assert.AreEqual(expectedResult, actual);
295 [TestCase(458849, 5526, 464375)]
302 Assert.DoesNotThrow(() => resultExp = orExp.
Evaluate());
303 Assert.IsNotNull(resultExp);
307 Assert.IsNotNull(constExp.Value.Value);
308 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
309 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
311 var actual = ((
SqlNumber)constExp.Value.Value);
312 var expectedResult =
new SqlNumber(expected);
313 Assert.AreEqual(expectedResult, actual);
316 [TestCase(
true,
true,
true)]
317 [TestCase(
true,
false,
true)]
318 [TestCase(
false,
false,
false)]
325 Assert.DoesNotThrow(() => resultExp = orExp.
Evaluate());
326 Assert.IsNotNull(resultExp);
330 Assert.IsNotNull(constExp.Value.Value);
331 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
332 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
334 var actual = ((
SqlBoolean)constExp.Value.Value);
335 var expectedResult =
new SqlBoolean(expected);
336 Assert.AreEqual(expectedResult, actual);
340 [TestCase(
true,
true,
true)]
341 [TestCase(
true,
false,
false)]
342 [TestCase(
false,
false,
false)]
349 Assert.DoesNotThrow(() => resultExp = andExp.
Evaluate());
350 Assert.IsNotNull(resultExp);
354 Assert.IsNotNull(constExp.Value.Value);
355 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
356 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
358 var actual = ((
SqlBoolean)constExp.Value.Value);
359 var expectedResult =
new SqlBoolean(expected);
360 Assert.AreEqual(expectedResult, actual);
364 [TestCase(567488, 90021, 653157)]
365 public void NumericXOr(
double a,
double b,
double expected) {
371 Assert.DoesNotThrow(() => resultExp = xorExp.
Evaluate());
372 Assert.IsNotNull(resultExp);
376 Assert.IsNotNull(constExp.Value.Value);
377 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
378 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
380 var actual = ((
SqlNumber)constExp.Value.Value);
381 var expectedResult =
new SqlNumber(expected);
382 Assert.AreEqual(expectedResult, actual);
385 [TestCase(6574493, 13324, 4108)]
392 Assert.DoesNotThrow(() => resultExp = orExp.
Evaluate());
393 Assert.IsNotNull(resultExp);
397 Assert.IsNotNull(constExp.Value.Value);
398 Assert.IsInstanceOf<
NumericType>(constExp.Value.Type);
399 Assert.IsInstanceOf<
SqlNumber>(constExp.Value.Value);
401 var actual = ((
SqlNumber)constExp.Value.Value);
402 var expectedResult =
new SqlNumber(expected);
403 Assert.AreEqual(expectedResult, actual);
413 Assert.DoesNotThrow(() => resultExp = orExp.
Evaluate());
414 Assert.IsNotNull(resultExp);
418 Assert.IsNotNull(constExp.Value.Value);
419 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
420 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
422 var actual = ((
SqlBoolean)constExp.Value.Value);
424 Assert.AreEqual(expectedResult, actual);
434 Assert.DoesNotThrow(() => resultExp = orExp.
Evaluate());
435 Assert.IsNotNull(resultExp);
439 Assert.IsNotNull(constExp.Value.Value);
440 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
441 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
443 var actual = ((
SqlBoolean)constExp.Value.Value);
445 Assert.AreEqual(expectedResult, actual);
448 [TestCase(
"Antonello",
"Anto%",
true)]
449 [TestCase(
"Antonello",
"Anto",
false)]
450 [TestCase(
"Antonello",
"%nello",
true)]
451 [TestCase(
"Antonello",
"Anto_ello",
true)]
452 [TestCase(
"Antonello",
"Anton__ello",
false)]
453 [TestCase(
"Antonello",
"%Antonello%",
true)]
454 [TestCase(
"Antonello",
"Antonello_",
false)]
455 [TestCase(
"Antonello Provenzano",
"Antonello%",
true)]
462 Assert.DoesNotThrow(() => resultExp = likeExp.
Evaluate());
463 Assert.IsNotNull(resultExp);
467 Assert.IsNotNull(constExp.Value.Value);
468 Assert.IsInstanceOf<
BooleanType>(constExp.Value.Type);
469 Assert.IsInstanceOf<
SqlBoolean>(constExp.Value.Value);
471 var actual = ((
SqlBoolean)constExp.Value.Value);
472 var expectedResult =
new SqlBoolean(expected);
473 Assert.AreEqual(expectedResult, actual);
void NumericEqualTo(double a, double b, bool expected)
static SqlBinaryExpression Divide(SqlExpression left, SqlExpression right)
static SqlBinaryExpression And(SqlExpression left, SqlExpression right)
void NumericOr(long a, long b, long expected)
static SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right)
void NumericXOr(double a, double b, double expected)
static DataObject Double(double value)
static DataObject Number(SqlNumber value)
static DataObject Null(SqlType type)
static SqlBinaryExpression Equal(SqlExpression left, SqlExpression right)
static SqlBinaryExpression SmallerThan(SqlExpression left, SqlExpression right)
static DataObject String(string s)
static DataObject Boolean(SqlBoolean value)
void BooleanOr(bool a, bool b, bool expected)
void StringAndStringAdd()
void NumericIsNullFalse()
void StringLikesPattern(string input, string patern, bool expected)
virtual SqlExpression Evaluate(EvaluateContext context)
When overridden by a derived class, this method evaluates the expression within the provided context...
void NumericAnd(long a, long b, long expected)
void NumericAddToString()
static SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right)
static SqlBinaryExpression Add(SqlExpression left, SqlExpression right)
static SqlBinaryExpression Or(SqlExpression left, SqlExpression right)
static SqlBinaryExpression NotEqual(SqlExpression left, SqlExpression right)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
static SqlBinaryExpression XOr(SqlExpression left, SqlExpression right)
static SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right)
void NumericGreaterThan(double a, double b, bool expected)
static SqlBinaryExpression Like(SqlExpression left, SqlExpression right)
static readonly SqlNumber Null
An expression that holds a constant value.
static DataObject VarChar(string s)
void NumericAndBooleanAdd()
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
void BooleanAnd(bool a, bool b, bool expected)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
void NumericNotEqualTo(double a, double b, bool expected)
void NumericAndNumericSubtract()
Deveel.Data.Sql.Objects.SqlString SqlString
void NumericAndBooleanSubtract()
static SqlBinaryExpression GreaterThan(SqlExpression left, SqlExpression right)
void NumericAndNumericAdd()
static SqlBinaryExpression Is(SqlExpression left, SqlExpression right)
void NumericSmallerThan(double a, double b, bool expected)