Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f886716
add parser
bygu4 Apr 24, 2025
93efcdd
refactor
bygu4 Apr 24, 2025
279cfa0
add AST conversions
bygu4 Apr 25, 2025
0a96785
add lambda term to string transformation
bygu4 Apr 25, 2025
4362d34
add interpreter and program
bygu4 Apr 25, 2025
7e43c80
change naming
bygu4 Apr 25, 2025
46a9a2d
add parser tests
bygu4 Apr 25, 2025
ef7ee44
correct whitespace parsing
bygu4 Apr 26, 2025
ca4f7d7
refactor the interpreter, check for keywords and use regex during var…
bygu4 Apr 26, 2025
74d00b9
refactor, move exit codes to separate file, correct interpreter
bygu4 Apr 26, 2025
07526b5
update term to string transformation
bygu4 Apr 26, 2025
7078d15
add ColorScheme module, refactor
bygu4 Apr 26, 2025
ae199ba
add Console directory
bygu4 Apr 26, 2025
16fa87a
add special commands, refactor
bygu4 Apr 27, 2025
569718d
update parser tests
bygu4 Apr 27, 2025
f02b0ab
refactor main
bygu4 Apr 27, 2025
0b6d810
rename keywords, add clear buffer keyword
bygu4 Apr 27, 2025
6607308
add tests for the interpreter class
bygu4 Apr 27, 2025
3da4a82
add optional whitespace for abstraction
bygu4 Apr 27, 2025
49f9c03
refactor, skip empty interpreter output
bygu4 Apr 28, 2025
a741d1a
add Reducer logging
bygu4 Apr 28, 2025
d052882
add Options struct, add --verbose option
bygu4 Apr 28, 2025
60d4bf2
correct output formatting
bygu4 Apr 28, 2025
4f82792
use list instead of map to store definitions
bygu4 Apr 28, 2025
a736f1d
add --line-number option
bygu4 Apr 28, 2025
c9d66e9
update main
bygu4 Apr 28, 2025
f58a61f
update comments and exception handling
bygu4 Apr 28, 2025
2614394
handle stack overflow during reduction, update logging
bygu4 Apr 29, 2025
d4bfc42
adjust recursion limit
bygu4 Apr 29, 2025
e2c46e4
adjust recursion limit
bygu4 Apr 29, 2025
87a10a7
improve logging, change success output color
bygu4 Apr 29, 2025
49206ab
add Help modules for managing console printing, refactor
bygu4 Apr 29, 2025
04968b2
add display command
bygu4 Apr 29, 2025
b1acccc
add Logger class, refactor
bygu4 Apr 29, 2025
1e4965b
update tests
bygu4 Apr 29, 2025
4c0ca5d
correct application parsing with closing abstraction, update tests
bygu4 Apr 29, 2025
c6216ee
minor refactoring
bygu4 Apr 29, 2025
48a12da
update comments
bygu4 Apr 29, 2025
672f7a1
simplify code in reducer
bygu4 Apr 29, 2025
35a5d13
rewrite reduction in CPS, update naming
bygu4 Apr 30, 2025
9f3c1c7
rewrite substitution and free variable obtaining in CPS, refactor
bygu4 Apr 30, 2025
929bd85
correct term to string transformation, update tests
bygu4 Apr 30, 2025
54211a5
add more tests, use TailCall attribute
bygu4 May 1, 2025
beb6445
enable tail call optimization in props
bygu4 May 1, 2025
6fe9aba
add arithmetic test
bygu4 May 1, 2025
1ba8ab7
rewrite AST conversions in CPS
bygu4 May 1, 2025
cbf300d
correct parentheses in term to string conversion
bygu4 May 1, 2025
9e7731c
correct the reduction in normal strategy, add factorial test
bygu4 May 5, 2025
8abf51c
add fibonacci test
bygu4 May 5, 2025
fbaab84
update reducer tests
bygu4 May 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions Tasks/LambdaInterpreter/LambdaInterpreter.Tests/InterpreterTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
module Interpreter.Tests

open NUnit.Framework
open FsUnit
open System
open System.IO

open LambdaInterpreter

let testFilesDir = "TestFiles"
let successfulCasesPath = Path.Join [|testFilesDir; "Successful"|]
let unsuccessfulCasesPath = Path.Join [|testFilesDir; "Unsuccessful"|]

let successfulCasesSources = Directory.EnumerateFiles successfulCasesPath |> seq |> Seq.sort
let unsuccessfulCasesSources = Directory.EnumerateFiles unsuccessfulCasesPath |> seq |> Seq.sort

let e = String.Empty

let successfulCasesResults: Result<string, string> list list = [
[ // Test 1
Ok "\\z.z";
Ok "trololo";
];
[ // Test 2
Ok "ololo";
Ok "a";
Ok "\\V1.\\V2.V2 \\x.V2 x";
Ok "\\V1.\\V2.V2 \\x.V2 x";
Ok "\\V1.\\V2.V2 (\\x.V2) x";
Ok "\\V1.\\V2.V2 (\\x.V2) x";
Ok "\\x.\\y.\\x.x";
];
[ // Test 3
Ok "qwerty";
Ok "ololo (A_ B_)";
Ok "\\x.\\y.z \\x.y x";
Ok "Mult (Sum \\P.P)";
Ok "second third \\x.x first";
Ok "second third";
];
[ // Test 4
Ok "x y";
Ok "x";
Ok "\\y'.y y'";
Ok "(\\x.x x) (\\x.x x) (\\x.x x) \\x.x x";
];
[ // Test 5
Ok "\\y.ololo";
Ok "snd";
Ok "res";
Ok "\\U.\\V.V \\x.U";
Ok "\\left.\\right.left (\\x.x) right";
Ok "\\x.\\y.\\z.z (z y x)";
];
[ // Test 6
Ok "a";
Ok "\\a.\\b.b a";
Ok "baz bar";
];
[ // Test 7
Ok "var";
Ok "\\x.x";
Ok "exitCode";
Ok "helpMe";
Ok "toClear";
Ok "reset_vars";
Ok "no_exit_1";
];
[ // Test 8
];
[ // Test 9
Ok "U";
Ok "V";
Ok "\\f.f V U";
Ok "V";
Ok "U";
];
[ // Test 10
Ok "\\f.\\x.f (f x)";
Ok "\\f.\\x.f (f (f x))";
Ok "\\f.\\x.f (f (f x))";
Ok "\\f.\\x.x";
Ok "\\f.\\x.f (f (f (f (f x))))";
Ok "\\f.\\x.f (f (f (f (f (f x)))))";
Ok "\\f.\\x.x";
Ok "\\f.\\x.f (f (f (f (f (f (f (f x)))))))";
];
[ // Test 11
Ok "\\f.\\x.f x";
Ok "\\f.\\x.f x";
Ok "\\f.\\x.f (f x)";
Ok "\\f.\\x.f (f (f (f (f (f x)))))";
Ok "\\f.\\x.f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f x)))))))))))))))))))))))";
];
[ // Test 12
Ok "\\f.\\x.f x";
Ok "\\f.\\x.f x";
Ok "\\f.\\x.f (f x)";
Ok "\\f.\\x.f (f (f x))";
Ok "\\f.\\x.f (f (f (f (f x))))";
Ok "\\f.\\x.f (f (f (f (f (f (f (f x)))))))";
];
]

let unsuccessfulCasesResults: Result<string, string> list list = [
[ // Test 1
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Ok "res";
];
[ // Test 2
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
];
[ // Test 3
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
Error e;
];
[ // Test 4
Ok "\\x.\\y.x";
Ok "\\x.\\y.x";
Error e;
Ok "bar";
Ok "foo bar";
];
[ // Test 5
Error e;
Ok "(\\x.x x) \\x.x x";
Ok "(\\x.x x) (\\x.x x) ((\\x.x x) \\x.x x) ((\\x.x x) \\x.x x)";
];
]

let successfulCases =
successfulCasesResults
|> Seq.zip successfulCasesSources
|> Seq.map (fun (file, res) -> file, res, false)

let unsuccessfulCases =
unsuccessfulCasesResults
|> Seq.zip unsuccessfulCasesSources
|> Seq.map (fun (file, res) -> file, res, true)

let testCases = Seq.append successfulCases unsuccessfulCases |> Seq.map TestCaseData

let outputsMatch (actual: Result<string, string> list) (expected: Result<string, string> list) =
actual.Length = expected.Length &&
Seq.zip actual expected
|> Seq.map (function
| Ok res1, Ok res2 -> res1 = res2
| Error _, Error _ -> true
| Ok _, Error _ | Error _, Ok _ -> false
) |> Seq.forall (( = ) true)

[<TestCaseSourceAttribute(nameof(testCases))>]
let testInterpreter (sourceFile: string, expectedOutput: Result<string, string> list, shouldFail: bool) =
let interpreter = Interpreter.StartOnFile sourceFile
let output = interpreter.RunToEnd () |> Seq.toList
output |> outputsMatch expectedOutput |> should be True
(interpreter.SyntaxError || interpreter.MaxDepthExceeded) |> should equal shouldFail
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="LambdaTermTests.fs" />
<Compile Include="ParserTests.fs" />
<Compile Include="ReducerTests.fs" />
<Compile Include="InterpreterTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -20,4 +22,9 @@
<ItemGroup>
<ProjectReference Include="..\LambdaInterpreter\LambdaInterpreter.fsproj" />
</ItemGroup>
<ItemGroup>
<Content Include="TestFiles/**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
110 changes: 0 additions & 110 deletions Tasks/LambdaInterpreter/LambdaInterpreter.Tests/LambdaTermTests.fs

This file was deleted.

Loading