20 lines
426 B
Zig
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);
|
|
}
|