mirror of
https://github.com/ziglang/zig.git
synced 2025-12-17 19:53:06 +00:00
30 lines
559 B
Zig
30 lines
559 B
Zig
const std = @import("std");
|
|
const testing = std.testing;
|
|
const mem = std.mem;
|
|
const expect = testing.expect;
|
|
const expectEqual = testing.expectEqual;
|
|
|
|
test "arrays" {
|
|
var array: [5]u32 = undefined;
|
|
|
|
var i: u32 = 0;
|
|
while (i < 5) {
|
|
array[i] = i + 1;
|
|
i = array[i];
|
|
}
|
|
|
|
i = 0;
|
|
var accumulator = @as(u32, 0);
|
|
while (i < 5) {
|
|
accumulator += array[i];
|
|
|
|
i += 1;
|
|
}
|
|
|
|
try expect(accumulator == 15);
|
|
try expect(getArrayLen(&array) == 5);
|
|
}
|
|
fn getArrayLen(a: []const u32) usize {
|
|
return a.len;
|
|
}
|