sqlite-wasm/testdata/addupto.zig
jmug aa1e940362 Try not to optimize the loop
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2025-04-28 00:50:32 -07:00

20 lines
426 B
Zig

const expect = @import("std").testing.expect;
pub export fn addUpTo(to: i32) i32 {
var res: i32 = 0;
for (0..@intCast(to)) |i| {
const ii: i32 = @intCast(i);
if (ii < 20) {
res += ii * to;
} else {
res += ii + to * 2;
}
}
return res;
}
test "addUpTo" {
const expected: u32 = 15;
const actual = addUpTo(6);
try expect(actual == expected);
}