From 3792e97d20b7103c132d5406032cf7b9d6ef1683 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 15 Oct 2026 22:38:03 +0000 Subject: [PATCH] Test that fit=cover serves a source whose centre is under a pixel wide (part of #282) An 8192x1 source at 1x8192, or the same turned on its side, has a centre with the requested proportions 1/8192 of a pixel wide. The crop must keep at least one pixel of it, or the request fails. The test's cases are now named by source and requested size. Model: opus-5-5 --- .../imageprocessor/fit_cover_internal_test.go | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/internal/imageprocessor/fit_cover_internal_test.go b/internal/imageprocessor/fit_cover_internal_test.go index 50bdc30..9aaa3e8 100644 --- a/internal/imageprocessor/fit_cover_internal_test.go +++ b/internal/imageprocessor/fit_cover_internal_test.go @@ -9,20 +9,24 @@ import ( ) // TestImageProcessor_FitCoverServesThinSource verifies that FitCover serves -// a source of 8192x64 or 8192x1, or one of those turned on its side, at -// 8192x8192. Scaling such a source to cover that size makes it 128 or 8192 -// times as long as the output on its long side. +// a thin source at the requested size. A source of 8192x64 or 8192x1 scaled +// to cover 8192x8192 is 128 or 8192 times as long as the output on its long +// side. The centre of an 8192x1 source with the proportions of 1x8192 is +// 1/8192 of a pixel wide. Each case is also turned on its side. func TestImageProcessor_FitCoverServesThinSource(t *testing.T) { t.Parallel() tests := []struct { name string inputWidth, inputHeight int + size Size }{ - {"8192x64", 8192, 64}, - {"8192x1", 8192, 1}, - {"64x8192", 64, 8192}, - {"1x8192", 1, 8192}, + {"8192x64 at 8192x8192", 8192, 64, Size{Width: 8192, Height: 8192}}, + {"8192x1 at 8192x8192", 8192, 1, Size{Width: 8192, Height: 8192}}, + {"8192x1 at 1x8192", 8192, 1, Size{Width: 1, Height: 8192}}, + {"64x8192 at 8192x8192", 64, 8192, Size{Width: 8192, Height: 8192}}, + {"1x8192 at 8192x8192", 1, 8192, Size{Width: 8192, Height: 8192}}, + {"1x8192 at 8192x1", 1, 8192, Size{Width: 8192, Height: 1}}, } for _, tt := range tests { @@ -33,14 +37,7 @@ func TestImageProcessor_FitCoverServesThinSource(t *testing.T) { result, err := New(Params{}).Process(t.Context(), bytes.NewReader(input), - &Request{ - Size: Size{ - Width: MaxOutputDimension, - Height: MaxOutputDimension, - }, - Format: FormatJPEG, - FitMode: FitCover, - }) + &Request{Size: tt.size, Format: FormatJPEG, FitMode: FitCover}) if err != nil { t.Fatalf("Process() error = %v", err) } @@ -49,11 +46,9 @@ func TestImageProcessor_FitCoverServesThinSource(t *testing.T) { t.Logf("Process() made %dx%d", result.Width, result.Height) - if result.Width != MaxOutputDimension || - result.Height != MaxOutputDimension { + if result.Width != tt.size.Width || result.Height != tt.size.Height { t.Errorf("Process() made %dx%d, want %dx%d", - result.Width, result.Height, - MaxOutputDimension, MaxOutputDimension) + result.Width, result.Height, tt.size.Width, tt.size.Height) } }) }