2024-04-25 01:41:47 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const expect = std.testing.expect;
|
|
|
|
|
|
|
|
const mat4x4 = [4][4]f32{
|
|
|
|
[_]f32{ 1.0, 0.0, 0.0, 0.0 },
|
|
|
|
[_]f32{ 0.0, 1.0, 0.0, 1.0 },
|
|
|
|
[_]f32{ 0.0, 0.0, 1.0, 0.0 },
|
|
|
|
[_]f32{ 0.0, 0.0, 0.0, 1.0 },
|
|
|
|
};
|
|
|
|
test "multidimensional arrays" {
|
|
|
|
// Access the 2D array by indexing the outer array, and then the inner array.
|
|
|
|
try expect(mat4x4[1][1] == 1.0);
|
|
|
|
|
|
|
|
// Here we iterate with for loops.
|
|
|
|
for (mat4x4, 0..) |row, row_index| {
|
|
|
|
for (row, 0..) |cell, column_index| {
|
|
|
|
if (row_index == column_index) {
|
|
|
|
try expect(cell == 1.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-08 20:39:11 +01:00
|
|
|
|
|
|
|
// initialize a multidimensional array to zeros
|
|
|
|
const all_zero: [4][4]f32 = .{.{0} ** 4} ** 4;
|
|
|
|
try expect(all_zero[0][0] == 0);
|
2024-04-25 01:41:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// test
|