## Summary This PR enhances the testing infrastructure with dynamic test discovery, automated validation, and improved error handling. ## Changes ### Testing Infrastructure - Added `TestSamplesValidity` integration test that validates all test files against their expected output. - Implemented dynamic test discovery using `filepath.Glob` to automatically find all `.test` files. - Renamed `benchmark_test.go` to `lambda_test.go` for better naming consistency. - Consolidated helper functions into a single `runSample` function. - Replaced all error handling with `assert` for consistent and clear test output. - Required all `.test` files to have corresponding `.expected` files. ### Iterator Improvements - Added `Swap` method to iterator for better reduction algorithm. - Improved reduction algorithm with LIFO-based iterator implementation. ### Build System - Added `make test` target to run tests without benchmarks. - Updated Makefile help text to include the new test target. ### Test Cases - Added new test cases with expected outputs: `church_5^5`, `church_6^6`, `fast_list_2^30`, `list_2^30`. - Added validation files for all test cases. ## Test plan - Run tests with expected output validation. - Run benchmarks to ensure performance is maintained. - Verify make targets work correctly. Reviewed-on: #20 Co-authored-by: M.V. Hutz <git@maximhutz.me> Co-committed-by: M.V. Hutz <git@maximhutz.me>
31 lines
632 B
Go
31 lines
632 B
Go
package lambda
|
|
|
|
func IsViable(e *Expression) (*Abstraction, Expression, bool) {
|
|
if e == nil {
|
|
return nil, nil, false
|
|
} else if app, appOk := (*e).(*Application); !appOk {
|
|
return nil, nil, false
|
|
} else if fn, fnOk := app.abstraction.(*Abstraction); !fnOk {
|
|
return nil, nil, false
|
|
} else {
|
|
return fn, app.argument, true
|
|
}
|
|
}
|
|
|
|
func ReduceAll(e *Expression, step func()) {
|
|
it := NewIterator(e)
|
|
|
|
for !it.Done() {
|
|
if fn, arg, ok := IsViable(it.Current()); !ok {
|
|
it.Next()
|
|
} else {
|
|
it.Swap(Substitute(fn.body, fn.parameter, arg))
|
|
step()
|
|
|
|
if _, _, ok := IsViable(it.Parent()); ok {
|
|
it.Back()
|
|
}
|
|
}
|
|
}
|
|
}
|