Skip to content

Commit 7194031

Browse files
committed
test(alloc): extend regression gates — atomics, more math, Result.Or, SliceClone (33 total)
Co-Authored-By: Virgil <virgil@lethean.io>
1 parent af9c188 commit 7194031

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

alloc_gate_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ var (
3131
gateStr string
3232
gateBytes []byte
3333
gateResult Result
34+
gateAny any
3435
)
3536

3637
func TestAllocs_HotPrimitives(t *T) {
3738
ptr := &struct{ n int }{}
3839
bs := []byte("homelab")
40+
var ai32 AtomicInt32
41+
var ab AtomicBool
42+
var au64 AtomicUint64
3943
cases := []struct {
4044
name string
4145
ceiling int
@@ -72,6 +76,26 @@ func TestAllocs_HotPrimitives(t *T) {
7276
{"Fail", 0, func() { gateResult = Fail(AnError) }},
7377
{"Ok_String", 1, func() { gateResult = Ok("ready") }},
7478
{"ResultOf_String", 1, func() { gateResult = ResultOf("ready", nil) }},
79+
80+
// Result accessors — pure reads, must stay 0
81+
{"Result_Or", 0, func() { gateAny = (Result{OK: false}).Or("fallback") }},
82+
83+
// atomics — lock-free, must stay 0
84+
{"AtomicInt32_Load", 0, func() { gateInt = int(ai32.Load()) }},
85+
{"AtomicInt32_Store", 0, func() { ai32.Store(7) }},
86+
{"AtomicInt32_Add", 0, func() { gateInt = int(ai32.Add(1)) }},
87+
{"AtomicBool_Load", 0, func() { gateBool = ab.Load() }},
88+
{"AtomicBool_Store", 0, func() { ab.Store(true) }},
89+
{"AtomicUint64_Add", 0, func() { gateInt = int(au64.Add(1)) }},
90+
91+
// more math — pure, must stay 0
92+
{"Pow", 0, func() { gateInt = int(Pow(2, 8)) }},
93+
{"Floor", 0, func() { gateInt = int(Floor(3.7)) }},
94+
{"Ceil", 0, func() { gateInt = int(Ceil(3.1)) }},
95+
{"Round", 0, func() { gateInt = int(Round(3.5)) }},
96+
97+
// slice — Clone copies (1 alloc for the backing array); Reverse is in-place (0)
98+
{"SliceClone", 1, func() { gateBytes = SliceClone(bs) }},
7599
}
76100
for _, c := range cases {
77101
avg := int(testing.AllocsPerRun(1000, c.fn))

0 commit comments

Comments
 (0)