diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-02-02 00:48:12 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-02-02 00:48:12 +0000 |
| commit | 6bbcd9536522386a53cd2f87ece7aa6cf423829f (patch) | |
| tree | 55d6dc2b4e2a9d84c09a67acb36f1ab4131e290c /tests/std/test_slice_iteration.zc | |
| parent | ec140e5e1823ed72e1ac8ab4af121dbe1b3f85d7 (diff) | |
| parent | dadabf8b9d11d099777acc261068a3ed8ca06f24 (diff) | |
Merge branch 'main' of https://github.com/z-libs/Zen-C into patch-1
Diffstat (limited to 'tests/std/test_slice_iteration.zc')
| -rw-r--r-- | tests/std/test_slice_iteration.zc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/std/test_slice_iteration.zc b/tests/std/test_slice_iteration.zc new file mode 100644 index 0000000..b7eddf4 --- /dev/null +++ b/tests/std/test_slice_iteration.zc @@ -0,0 +1,29 @@ +import "std/slice.zc" +import "std/io.zc" + +test "slice from array iteration" { + let ints: int[5] = [1, 2, 3, 4, 5]; + let slice = Slice<int>::from_array((int*)(&ints), 5); + + // Test iteration + let sum = 0; + for val in slice { + sum = sum + val; + } + + if (sum != 15) { + panic("Slice iteration failed: expected sum 15"); + } +} + +test "slice methods" { + let arr: int[3] = [10, 20, 30]; + let slice = Slice<int>::from_array((int*)(&arr), 3); + + if (slice.length() != 3) panic("Slice length wrong"); + if (slice.is_empty()) panic("Slice should not be empty"); + + let opt = slice.get(1); + if (opt.is_none()) panic("Slice get failed"); + if (opt.unwrap() != 20) panic("Slice get returned wrong value"); +} |
