Files
lux/examples/test_lists.lux
Brandon Lucas ee9acce6ec feat: add Test effect and native testing framework
- Add Test effect with operations: assert, assertEqual, assertNotEqual,
  assertTrue, assertFalse, fail
- Implement Test effect handlers in interpreter with TestResults tracking
- Add values_equal method for comparing Value types in tests
- Update lux test command to discover and run test_* functions
- Create example test files: test_math.lux, test_lists.lux
- Add TESTING_DESIGN.md documentation
- Fix AST mismatches in C backend and compiler.rs for compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 01:20:30 -05:00

58 lines
1.8 KiB
Plaintext

// List Operations Test Suite
// Run with: lux test examples/test_lists.lux
fn test_list_length(): Unit with {Test} = {
Test.assertEqual(0, List.length([]))
Test.assertEqual(1, List.length([1]))
Test.assertEqual(3, List.length([1, 2, 3]))
}
fn test_list_head(): Unit with {Test} = {
Test.assertEqual(Some(1), List.head([1, 2, 3]))
Test.assertEqual(None, List.head([]))
}
fn test_list_tail(): Unit with {Test} = {
Test.assertEqual(Some([2, 3]), List.tail([1, 2, 3]))
Test.assertEqual(None, List.tail([]))
}
fn test_list_get(): Unit with {Test} = {
let xs = [10, 20, 30]
Test.assertEqual(Some(10), List.get(xs, 0))
Test.assertEqual(Some(20), List.get(xs, 1))
Test.assertEqual(Some(30), List.get(xs, 2))
Test.assertEqual(None, List.get(xs, 3))
}
fn test_list_map(): Unit with {Test} = {
let double = fn(x: Int): Int => x * 2
Test.assertEqual([2, 4, 6], List.map([1, 2, 3], double))
Test.assertEqual([], List.map([], double))
}
fn test_list_filter(): Unit with {Test} = {
let isEven = fn(x: Int): Bool => x % 2 == 0
Test.assertEqual([2, 4], List.filter([1, 2, 3, 4, 5], isEven))
Test.assertEqual([], List.filter([1, 3, 5], isEven))
}
fn test_list_fold(): Unit with {Test} = {
let sum = fn(acc: Int, x: Int): Int => acc + x
Test.assertEqual(6, List.fold([1, 2, 3], 0, sum))
Test.assertEqual(10, List.fold([1, 2, 3], 4, sum))
Test.assertEqual(0, List.fold([], 0, sum))
}
fn test_list_reverse(): Unit with {Test} = {
Test.assertEqual([3, 2, 1], List.reverse([1, 2, 3]))
Test.assertEqual([], List.reverse([]))
Test.assertEqual([1], List.reverse([1]))
}
fn test_list_concat(): Unit with {Test} = {
Test.assertEqual([1, 2, 3, 4], List.concat([1, 2], [3, 4]))
Test.assertEqual([1, 2], List.concat([1, 2], []))
Test.assertEqual([3, 4], List.concat([], [3, 4]))
}