2020-05-01 11:53:41 +02:00
|
|
|
package thumb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
func TestSize_ExceedsLimit(t *testing.T) {
|
|
|
|
SizePrecached = 1024
|
2020-07-18 17:33:02 +02:00
|
|
|
SizeUncached = 2048
|
2020-05-01 11:53:41 +02:00
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
fit4096 := Sizes[Fit4096]
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.True(t, fit4096.ExceedsLimit())
|
2020-05-01 11:53:41 +02:00
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
fit2048 := Sizes[Fit2048]
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.False(t, fit2048.ExceedsLimit())
|
2020-05-01 11:53:41 +02:00
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
tile500 := Sizes[Tile500]
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.False(t, tile500.ExceedsLimit())
|
2020-05-01 11:53:41 +02:00
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
SizePrecached = 2048
|
2020-07-18 17:33:02 +02:00
|
|
|
SizeUncached = 7680
|
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
func TestSize_Uncached(t *testing.T) {
|
|
|
|
SizePrecached = 1024
|
2020-07-18 17:33:02 +02:00
|
|
|
SizeUncached = 2048
|
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
fit4096 := Sizes[Fit4096]
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.True(t, fit4096.Uncached())
|
2020-07-18 17:33:02 +02:00
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
fit2048 := Sizes[Fit2048]
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.True(t, fit2048.Uncached())
|
2020-07-18 17:33:02 +02:00
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
tile500 := Sizes[Tile500]
|
2021-09-05 12:32:08 +02:00
|
|
|
assert.False(t, tile500.Uncached())
|
2020-07-18 17:33:02 +02:00
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
SizePrecached = 2048
|
2020-07-18 17:33:02 +02:00
|
|
|
SizeUncached = 7680
|
2020-05-01 11:53:41 +02:00
|
|
|
}
|
2020-05-14 17:28:55 +02:00
|
|
|
|
|
|
|
func TestResampleFilter_Imaging(t *testing.T) {
|
|
|
|
t.Run("Blackman", func(t *testing.T) {
|
|
|
|
r := ResampleBlackman.Imaging()
|
|
|
|
assert.Equal(t, float64(3), r.Support)
|
|
|
|
})
|
|
|
|
t.Run("Cubic", func(t *testing.T) {
|
|
|
|
r := ResampleCubic.Imaging()
|
|
|
|
assert.Equal(t, float64(2), r.Support)
|
|
|
|
})
|
|
|
|
t.Run("Linear", func(t *testing.T) {
|
|
|
|
r := ResampleLinear.Imaging()
|
|
|
|
assert.Equal(t, float64(1), r.Support)
|
|
|
|
})
|
|
|
|
}
|
2020-07-18 17:33:02 +02:00
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
func TestFind(t *testing.T) {
|
2020-07-18 17:33:02 +02:00
|
|
|
t.Run("2048", func(t *testing.T) {
|
2021-09-05 13:48:53 +02:00
|
|
|
name, size := Find(2048)
|
|
|
|
assert.Equal(t, Fit2048, name)
|
|
|
|
assert.Equal(t, 2048, size.Width)
|
|
|
|
assert.Equal(t, 2048, size.Height)
|
2020-07-18 17:33:02 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("2000", func(t *testing.T) {
|
2021-09-05 13:48:53 +02:00
|
|
|
name, size := Find(2000)
|
|
|
|
assert.Equal(t, Fit1920, name)
|
|
|
|
assert.Equal(t, 1920, size.Width)
|
|
|
|
assert.Equal(t, 1200, size.Height)
|
2020-07-18 17:33:02 +02:00
|
|
|
})
|
|
|
|
}
|