-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from bijington/issue-64-null-used-in-compariso…
…n-is-inconsistent Comparisons now correctly handle nulls and are consistent with .NET. …
- Loading branch information
Showing
12 changed files
with
177 additions
and
615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 24 additions & 74 deletions
98
.../CSharp/Expressive/Expressive.Tests/Expressions/Binary/Relational/EqualExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,39 @@ | ||
using System.Collections.Generic; | ||
using Expressive.Expressions; | ||
using Expressive.Expressions.Binary.Relational; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Expressive.Tests.Expressions.Binary.Relational | ||
{ | ||
[TestClass] | ||
public class EqualExpressionTests | ||
public static class EqualExpressionTests | ||
{ | ||
[TestMethod] | ||
public void TestBothNull() | ||
[TestCase(null, null, true)] | ||
[TestCase(5, 5, true)] | ||
[TestCase(5, 2, false)] | ||
[TestCase(2, 5, false)] | ||
[TestCase(null, "abc", false)] | ||
[TestCase("abc", null, false)] | ||
[TestCase("abc", "abc", true)] | ||
[TestCase(null, false, false)] | ||
[TestCase(false, null, false)] | ||
[TestCase(true, false, false)] | ||
[TestCase(true, true, true)] | ||
[TestCase(false, false, true)] | ||
[TestCase(false, true, false)] | ||
[TestCase(1.001, 1, false)] | ||
[TestCase(1, 1.001, false)] | ||
[TestCase(1.001, 1.001, true)] | ||
[TestCase(1, 1.00, true)] | ||
[TestCase(1.00, 1, true)] | ||
public static void TestEvaluate(object lhs, object rhs, object expectedValue) | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == lhs), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == rhs), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(true, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEqual() | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(true, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestLeftNull() | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)"abc"), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestNotEqual() | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)2), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRightNull() | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)false), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestIntFloatUnequal() | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.001), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestIntFloatEqual() | ||
{ | ||
var expression = new EqualExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.00), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(true, expression.Evaluate(null)); | ||
Assert.That(expression.Evaluate(null), Is.EqualTo(expectedValue)); | ||
} | ||
} | ||
} |
119 changes: 28 additions & 91 deletions
119
...p/Expressive/Expressive.Tests/Expressions/Binary/Relational/GreaterThanExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,39 @@ | ||
using System.Collections.Generic; | ||
using Expressive.Expressions; | ||
using Expressive.Expressions.Binary.Relational; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Expressive.Tests.Expressions.Binary.Relational | ||
{ | ||
[TestClass] | ||
public class GreaterThanExpressionTests | ||
public static class GreaterThanExpressionTests | ||
{ | ||
[TestMethod] | ||
public void TestBothNull() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(null, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEqual() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGreaterThan() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)2), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(true, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestLeftNull() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)"abc"), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(null, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestLessThan() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)2), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)5), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRightNull() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)false), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)null), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(null, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestIntFloatTrue() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.001), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(true, expression.Evaluate(null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestIntFloatFalse() | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.001), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.AreEqual(false, expression.Evaluate(null)); | ||
[TestCase(null, null, false)] | ||
[TestCase(5, 5, false)] | ||
[TestCase(5, 2, true)] | ||
[TestCase(2, 5, false)] | ||
[TestCase(null, "abc", false)] | ||
[TestCase("abc", null, true)] | ||
[TestCase("abc", "abc", false)] | ||
[TestCase(null, false, false)] | ||
[TestCase(false, null, true)] | ||
[TestCase(true, false, true)] | ||
[TestCase(true, true, false)] | ||
[TestCase(false, false, false)] | ||
[TestCase(false, true, false)] | ||
[TestCase(1.001, 1, true)] | ||
[TestCase(1, 1.001, false)] | ||
[TestCase(1.001, 1.001, false)] | ||
[TestCase(1, 1.00, false)] | ||
[TestCase(1.00, 1, false)] | ||
public static void TestEvaluate(object lhs, object rhs, object expectedValue) | ||
{ | ||
var expression = new GreaterThanExpression( | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == lhs), | ||
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == rhs), | ||
new Context(ExpressiveOptions.None)); | ||
|
||
Assert.That(expression.Evaluate(null), Is.EqualTo(expectedValue)); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.