Skip to content

Commit da1ddd4

Browse files
committed
more unit tests to implement ITest
1 parent 706bb04 commit da1ddd4

File tree

16 files changed

+56
-89
lines changed

16 files changed

+56
-89
lines changed

.vscode/launch.json

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,6 @@
44
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
55
"version": "0.2.0",
66
"configurations": [
7-
8-
{
9-
"name": ".NET Core Launch (Benchmarks)",
10-
"type": "coreclr",
11-
"request": "launch",
12-
"preLaunchTask": "build_benchmarks",
13-
// If you have changed target frameworks, make sure to update the program path.
14-
"program": "${workspaceFolder}/test/FastExpressionCompiler.Benchmarks/bin/Debug/netcoreapp3.1/FastExpressionCompiler.Benchmarks.exe",
15-
"args": [],
16-
"cwd": "${workspaceFolder}/test/FastExpressionCompiler.Benchmarks",
17-
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
18-
"console": "internalConsole",
19-
"stopAtEntry": false,
20-
"internalConsoleOptions": "openOnSessionStart",
21-
"requireExactSource": false // allows to for moderate code editing while debugging
22-
},
23-
{
24-
"name": ".NET Core Launch (UnitTests)",
25-
"type": "coreclr",
26-
"request": "launch",
27-
"preLaunchTask": "build_testsrunner",
28-
// If you have changed target frameworks, make sure to update the program path.
29-
"program": "${workspaceFolder}/test/FastExpressionCompiler.UnitTests/bin/Debug/netcoreapp3.1/FastExpressionCompiler.UnitTests.dll",
30-
"args": [],
31-
"cwd": "${workspaceFolder}/test/FastExpressionCompiler.TestsRunner",
32-
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
33-
"console": "internalConsole",
34-
"stopAtEntry": false,
35-
"internalConsoleOptions": "openOnSessionStart",
36-
"requireExactSource": false // allows to for moderate code editing while debugging
37-
},
387
{
398
"name": ".NET Core Launch (TestsRunner)",
409
"type": "coreclr",

.vscode/tasks.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
"kind": "build",
1515
"isDefault": true
1616
}
17-
},
18-
{
19-
"label": "build_benchmarks",
20-
"command": "dotnet",
21-
"type": "process",
22-
"args": [
23-
"build",
24-
"${workspaceFolder}/test/FastExpressionCompiler.Benchmarks/FastExpressionCompiler.Benchmarks.csproj"
25-
],
26-
"problemMatcher": "$msCompile"
2717
}
2818
]
2919
}
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NUnit.Framework;
2-
using System;
3-
using System.Linq.Expressions;
2+
using System;
3+
using System.Linq.Expressions;
44
#if LIGHT_EXPRESSION
55
using System.Text;
66
using static FastExpressionCompiler.LightExpression.Expression;
@@ -29,45 +29,49 @@ public void Test_Recursive_Expression()
2929
fs.PrintIL();
3030
var res = fs(4);
3131

32-
var f = expr.CompileFast(true);
32+
var f = expr.CompileFast(true, CompilerFlags.NoInvocationLambdaInlining);
3333
f.PrintIL();
3434
var res2 = f(4);
3535

36+
// f = expr.CompileFast(true);
37+
// f.PrintIL();
38+
// res2 = f(4);
39+
3640
Assert.AreEqual(res, res2);
3741
}
3842

3943
//from https://chriscavanagh.wordpress.com/2012/06/18/recursive-methods-in-expression-trees/
40-
public Expression<Func<T, T>> MakeFactorialExpression<T>()
41-
{
42-
var nParam = Expression.Parameter(typeof(T), "n");
43-
var methodVar = Expression.Variable(typeof(Func<T, T>), "factorial");
44-
var one = Expression.Convert(Expression.Constant(1), typeof(T));
45-
46-
return Expression.Lambda<Func<T, T>>(
47-
Expression.Block(
48-
// Func<uint, uint> method;
49-
new[] { methodVar },
50-
// method = n => ( n <= 1 ) ? 1 : n * method( n - 1 );
51-
Expression.Assign(
52-
methodVar,
53-
Expression.Lambda<Func<T, T>>(
54-
Expression.Condition(
55-
// ( n <= 1 )
56-
Expression.LessThanOrEqual(nParam, one),
57-
// 1
58-
one,
59-
// n * method( n - 1 )
60-
Expression.Multiply(
61-
// n
62-
nParam,
63-
// method( n - 1 )
64-
Expression.Invoke(
65-
methodVar,
66-
Expression.Subtract(nParam, one)))),
67-
nParam)),
68-
// return method( n );
69-
Expression.Invoke(methodVar, nParam)),
70-
nParam);
44+
public Expression<Func<T, T>> MakeFactorialExpression<T>()
45+
{
46+
var nParam = Expression.Parameter(typeof(T), "n");
47+
var methodVar = Expression.Variable(typeof(Func<T, T>), "factorial");
48+
var one = Expression.Constant(1, typeof(T));
49+
50+
return Expression.Lambda<Func<T, T>>(
51+
Expression.Block(
52+
// Func<uint, uint> method;
53+
new[] { methodVar },
54+
// method = n => ( n <= 1 ) ? 1 : n * method( n - 1 );
55+
Expression.Assign(
56+
methodVar,
57+
Expression.Lambda<Func<T, T>>(
58+
Expression.Condition(
59+
// ( n <= 1 )
60+
Expression.LessThanOrEqual(nParam, one),
61+
// 1
62+
one,
63+
// n * method( n - 1 )
64+
Expression.Multiply(
65+
// n
66+
nParam,
67+
// method( n - 1 )
68+
Expression.Invoke(
69+
methodVar,
70+
Expression.Subtract(nParam, one)))),
71+
nParam)),
72+
// return method( n );
73+
Expression.Invoke(methodVar, nParam)),
74+
nParam);
7175
}
7276
}
7377
}

test/FastExpressionCompiler.TestsRunner/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ public static void Main()
1111
{
1212
RunAllTests();
1313

14+
// new FastExpressionCompiler.LightExpression.IssueTests.Issue293_Recursive_Methods().Run();
15+
1416
//new FastExpressionCompiler.LightExpression.IssueTests.Issue274_Failing_Expressions_in_Linq2DB().Run();
15-
1617
// new FastExpressionCompiler.LightExpression.IssueTests.Issue159_NumericConversions().Run();
1718
// new FastExpressionCompiler.LightExpression.UnitTests.BinaryExpressionTests().Run();
1819
// new FastExpressionCompiler.LightExpression.IssueTests.Issue284_Invalid_Program_after_Coalesce().Run();
@@ -195,6 +196,9 @@ void Run(Func<int> run, string name = null)
195196
Run(new Issue284_Invalid_Program_after_Coalesce().Run);
196197
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue284_Invalid_Program_after_Coalesce().Run);
197198

199+
// Run(new Issue293_Recursive_Methods().Run);
200+
// Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue293_Recursive_Methods().Run);
201+
198202
Console.WriteLine($"============={Environment.NewLine}IssueTests are passing in {sw.ElapsedMilliseconds} ms.");
199203
});
200204

test/FastExpressionCompiler.UnitTests/BlockTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace FastExpressionCompiler.UnitTests
1414
#endif
1515
{
1616
[TestFixture]
17-
public class BlockTests
17+
public class BlockTests : ITest
1818
{
1919
public int Run()
2020
{

test/FastExpressionCompiler.UnitTests/ClosureConstantTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace FastExpressionCompiler.UnitTests
1212
#endif
1313
{
1414
[TestFixture]
15-
public class ClosureConstantTests
15+
public class ClosureConstantTests : ITest
1616
{
1717
public int Run()
1818
{

test/FastExpressionCompiler.UnitTests/CoalesceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace FastExpressionCompiler.UnitTests
1010
#endif
1111
{
1212
[TestFixture]
13-
public class CoalesceTests
13+
public class CoalesceTests : ITest
1414
{
1515
public int Run()
1616
{

test/FastExpressionCompiler.UnitTests/ConvertOperatorsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace FastExpressionCompiler.UnitTests
1111
#endif
1212
{
1313
[TestFixture]
14-
public class ConvertOperatorsTests
14+
public class ConvertOperatorsTests : ITest
1515
{
1616
public int Run()
1717
{

test/FastExpressionCompiler.UnitTests/DefaultTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace FastExpressionCompiler.LightExpression.UnitTests
99
namespace FastExpressionCompiler.UnitTests
1010
#endif
1111
{
12-
[TestFixture]
13-
public class DefaultTests
12+
[TestFixture]
13+
public class DefaultTests : ITest
1414
{
1515
public int Run()
1616
{

test/FastExpressionCompiler.UnitTests/EqualityOperatorsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace FastExpressionCompiler.UnitTests
1111
#endif
1212
{
1313
[TestFixture]
14-
public class EqualityOperatorsTests
14+
public class EqualityOperatorsTests : ITest
1515
{
1616
public int Run()
1717
{

0 commit comments

Comments
 (0)