Skip to content
Permalink
Browse files

Issue #46: "1 == 1.001" yields True

  • Loading branch information
rogerdc committed Apr 24, 2019
1 parent 0b23e47 commit b65cb049aaa3f3b3de9ba42fe4589c316f04423d
@@ -72,3 +72,4 @@ Source/CSharp/Expressive/Expressive/obj/Release/TemporaryGeneratedFile_E7A71F73-
/Source/CSharp/Expressive/packages
/Source/CSharp/Expressive/nuget-package
/Source/CSharp/Expressive/.vs/config/applicationhost.config
.vs
@@ -63,5 +63,27 @@ public void TestRightNull()

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),
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),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}
}
}
@@ -74,5 +74,29 @@ public void TestRightNull()

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),
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),
ExpressiveOptions.None);

Assert.AreEqual(false, expression.Evaluate(null));
}


}
}
@@ -74,5 +74,38 @@ public void TestRightNull()

Assert.AreEqual(null, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatEqual()
{
var expression = new GreaterThanOrEqualExpression(
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.0),
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatTrue()
{
var expression = new GreaterThanOrEqualExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatFalse()
{
var expression = new GreaterThanOrEqualExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(false, expression.Evaluate(null));
}
}
}
@@ -74,5 +74,28 @@ public void TestRightNull()

Assert.AreEqual(null, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatTrue()
{
var expression = new LessThanExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatFalse()
{
var expression = new LessThanExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(false, expression.Evaluate(null));
}

}
}
@@ -74,5 +74,39 @@ public void TestRightNull()

Assert.AreEqual(null, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatEqual()
{
var expression = new LessThanOrEqualExpression(
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.0),
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatTrue()
{
var expression = new LessThanOrEqualExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatFalse()
{
var expression = new LessThanOrEqualExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(false, expression.Evaluate(null));
}

}
}
@@ -63,5 +63,27 @@ public void TestRightNull()

Assert.AreEqual(true, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatEqual()
{
var expression = new NotEqualExpression(
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1.0),
Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == (object)1),
ExpressiveOptions.None);

Assert.AreEqual(false, expression.Evaluate(null));
}

[TestMethod]
public void TestIntFloatNotEqual()
{
var expression = new NotEqualExpression(
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),
ExpressiveOptions.None);

Assert.AreEqual(true, expression.Evaluate(null));
}
}
}
@@ -5,7 +5,15 @@ namespace Expressive.Helpers
{
internal static class Comparison
{
private static readonly Type[] CommonTypes = { typeof(long), typeof(int), typeof(double), typeof(bool), typeof(DateTime), typeof(string), typeof(decimal) };
private static readonly Type[] CommonTypes = {
typeof(DateTime), // If it can be interpreted as a DateTime use that.
typeof(decimal), // Decimal is stored as 96 bits of value, plus a sign, plus an exponent
typeof(double), // Double is stored as a 64 bit floating point
typeof(long), // 64 bit signed integer
typeof(int), // 32 bit signed integer
typeof(bool), // Process booleans before strings
typeof(string), // If it's not anything else, it can be a string.
};

internal static int CompareUsingMostPreciseType(object a, object b, bool ignoreCase)
{
@@ -21,6 +29,10 @@ internal static int CompareUsingMostPreciseType(object a, object b, bool ignoreC

private static Type GetMostPreciseType(Type a, Type b)
{
if (a == b)
{
return a; // If they're the same type, just return one of them.
}
foreach (var t in Comparison.CommonTypes)
{
if (a == t || b == t)

0 comments on commit b65cb04

Please sign in to comment.
You can’t perform that action at this time.