aboutsummaryrefslogtreecommitdiff
path: root/cmds/negcap_test.go
blob: 5076163baf7b64869e7b771c6b9a625dd8c61d0b (plain)
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
// The shared per-feed negative ceiling: uncapped at pct 0, floored so a
// young pool isn't strangled, and clamped to the target itself.
package cmds

import "testing"

func TestFeedNegCap(t *testing.T) {
	for _, tc := range []struct {
		name                  string
		pct, ratio, pos, want int
	}{
		{"uncapped at 0", 0, 20, 500, 0},
		{"normal: 5% of 10000-target", 5, 20, 500, 500},
		{"floor wins for young pools", 5, 20, 10, 50},    // target 200, 5% = 10 → floor 50
		{"clamped to the target", 90, 20, 3, 54},         // target 60, 90% = 54
		{"floor can exceed a tiny target", 5, 20, 1, 20}, // target 20 → clamp to 20
	} {
		t.Run(tc.name, func(t *testing.T) {
			if got := feedNegCap(tc.pct, tc.ratio, tc.pos); got != tc.want {
				t.Errorf("feedNegCap(%d, %d, %d) = %d, want %d",
					tc.pct, tc.ratio, tc.pos, got, tc.want)
			}
		})
	}
}