Add tests on new behaviours

This commit is contained in:
Pieter Vander Vennet 2020-09-07 18:47:37 +02:00
parent b1e4aa29a3
commit 666c78ff59

View file

@ -49,18 +49,16 @@ namespace AspectedRouting.Tests
AspectMetadata functionToApply, AspectMetadata functionToApply,
IEnumerable<(string expected, Dictionary<string, string> tags)> tests) IEnumerable<(string expected, Dictionary<string, string> tags)> tests)
{ {
if (functionToApply == null) if (functionToApply == null)
{ {
throw new NullReferenceException("functionToApply is null"); throw new NullReferenceException("functionToApply is null");
} }
FunctionToApply = functionToApply; FunctionToApply = functionToApply;
Tests = tests; Tests = tests;
} }
public bool Run() public bool Run()
{ {
var failed = false; var failed = false;
@ -77,14 +75,28 @@ namespace AspectedRouting.Tests
} }
} }
try
{
var actual = FunctionToApply.Evaluate(context, new Constant(test.tags)); var actual = FunctionToApply.Evaluate(context, new Constant(test.tags));
if (!actual.ToString().Equals(test.expected) && if (test.expected == "null" && actual == null)
{
// Test ok
}
else if (!actual.ToString().Equals(test.expected) &&
!(actual is double actualD && Math.Abs(double.Parse(test.expected) - actualD) < 0.0001) !(actual is double actualD && Math.Abs(double.Parse(test.expected) - actualD) < 0.0001)
) )
{ {
failed = true; failed = true;
Console.WriteLine( Console.WriteLine(
$"[{FunctionToApply.Name}] Line {testCase+1} failed:\n Expected: {test.expected}\n actual: {actual}\n tags: {test.tags.Pretty()}\n"); $"[{FunctionToApply.Name}] Line {testCase + 1} failed:\n Expected: {test.expected}\n actual: {actual}\n tags: {test.tags.Pretty()}\n");
}
}
catch (Exception e)
{
Console.WriteLine(
$"[{FunctionToApply.Name}] Line {testCase + 1} ERROR:\n Expected: {test.expected}\n error message: {e.Message}\n tags: {test.tags.Pretty()}\n");
failed = true;
} }
} }