1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// findNearestZigBuildDir walk-up test:
//
// When this file is the active editor in Nova, the "Current Zig File" clean
// action calls findNearestZigBuildDir starting at packages/beta/src/.
// It finds packages/beta/build.zig after one walk step and uses that
// directory as the working directory — NOT the monorepo root build.zig.
//
// To verify: open this file, trigger clean, observe the task console shows
// the beta package directory, not the monorepo root.
const std = @import("std");
/// Halve a value (integer division, truncated toward zero).
pub fn halve(x: i32) i32 {
return @divTrunc(x, 2);
}
/// Negate a value.
pub fn negate(x: i32) i32 {
return -x;
}
/// Absolute value.
pub fn abs(x: i32) i32 {
return if (x < 0) -x else x;
}
test "beta: halve" {
try std.testing.expectEqual(@as(i32, 3), halve(6));
try std.testing.expectEqual(@as(i32, 3), halve(7)); // truncated
try std.testing.expectEqual(@as(i32, -2), halve(-5));
try std.testing.expectEqual(@as(i32, 0), halve(0));
}
test "beta: negate" {
try std.testing.expectEqual(@as(i32, -7), negate(7));
try std.testing.expectEqual(@as(i32, 7), negate(-7));
try std.testing.expectEqual(@as(i32, 0), negate(0));
}
test "beta: abs" {
try std.testing.expectEqual(@as(i32, 5), abs(5));
try std.testing.expectEqual(@as(i32, 5), abs(-5));
try std.testing.expectEqual(@as(i32, 0), abs(0));
}
|