diff options
| author | czjstmax <jstmaxlol@disroot.org> | 2026-01-31 15:10:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-31 15:10:20 +0100 |
| commit | d2e2617dec584884b92eb452f377b20c0bf8f321 (patch) | |
| tree | d7cdc28d1a83f16a0fc7e945963aa070bfa9d3e4 /tests/std/test_direct_array_iteration.zc | |
| parent | 0427d254207a69e394499d1abaea768f484f1cb5 (diff) | |
| parent | 051400c70a4d5384923113cfbcbc69e8e58d27a0 (diff) | |
Merge pull request #1 from z-libs/main
Merge newer updates
Diffstat (limited to 'tests/std/test_direct_array_iteration.zc')
| -rw-r--r-- | tests/std/test_direct_array_iteration.zc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/std/test_direct_array_iteration.zc b/tests/std/test_direct_array_iteration.zc new file mode 100644 index 0000000..359951f --- /dev/null +++ b/tests/std/test_direct_array_iteration.zc @@ -0,0 +1,37 @@ +import "std/slice.zc" + +test "direct array iteration" { + let arr: int[5] = [1, 2, 3, 4, 5]; + + let sum = 0; + for val in arr { + sum = sum + val; + } + + assert(sum == 15, "Sum should be 1+2+3+4+5 = 15"); +} + +test "direct array iteration with different types" { + let floats: float[3] = [1.5, 2.5, 3.0]; + let count = 0; + + for f in floats { + count = count + 1; + } + + assert(count == 3, "Should iterate over all 3 elements"); +} + +// TODO: Nested array iteration needs special handling +// test "nested array iteration" { +// let matrix: int[2][3] = [[1, 2, 3], [4, 5, 6]]; +// let total = 0; +// +// for row in matrix { +// for val in row { +// total = total + val; +// } +// } +// +// assert(total == 21, "Sum should be 1+2+3+4+5+6 = 21"); +// } |
