fix: improve width calculation for ratios option (#2347)

* fix: improve width calculation for `ratios` option

* Update `CHANGELOG.md`

* round window ends instead of floor

* grammar
This commit is contained in:
Joe Lim authored and GitHub committed 2026-01-14 11:13:06 +11:00
1 parent 48689f9eab
commit b5d981ad4a
4 files changed
+74 -39

No files matched your search

+27
View File
@@ -559,3 +559,30 @@ func TestReadLines(t *testing.T) {
}
}
}
func TestGetWidths(t *testing.T) {
tests := []struct {
wtot int
ratios []int
drawbox bool
exp []int
}{
{0, []int{1}, false, []int{0}},
{0, []int{1}, true, []int{0}},
{0, []int{1, 3, 2}, false, []int{0, 0, 0}},
{0, []int{1, 3, 2}, true, []int{0, 0, 0}},
{14, []int{1, 3, 2}, false, []int{2, 6, 4}},
{16, []int{1, 3, 2}, true, []int{2, 6, 4}},
{23, []int{1, 3, 2, 4}, false, []int{2, 6, 4, 8}}, // windows end at 2.0, 8.0, 12.0, 20.0 respectively
{24, []int{1, 3, 2, 4}, false, []int{2, 6, 5, 8}}, // windows end at 2.1, 8.4, 12.6, 21.0 respectively
{25, []int{1, 3, 2, 4}, false, []int{2, 7, 4, 9}}, // windows end at 2.2, 8.8, 13.2, 22.0 respectively
{26, []int{1, 3, 2, 4}, false, []int{2, 7, 5, 9}}, // windows end at 2.3, 9.2, 13.8, 23.0 respectively
}
for _, test := range tests {
widths := getWidths(test.wtot, test.ratios, test.drawbox)
if !reflect.DeepEqual(widths, test.exp) {
t.Errorf("at input (%v, %v, %v) expected %v but got %v", test.wtot, test.ratios, test.drawbox, test.exp, widths)
}
}
}