mirror of
https://github.com/esimov/caire.git
synced 2025-10-30 03:21:48 +08:00
test: added new test cases
This commit is contained in:
@@ -5,25 +5,14 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProcessor_Resize(t *testing.T) {
|
||||
reduceImageH(t)
|
||||
reduceImageV(t)
|
||||
}
|
||||
|
||||
func reduceImageH(t *testing.T) {
|
||||
func TestResize_ReduceImageWidth(t *testing.T) {
|
||||
img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight))
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newWidth := ImgWidth / 2
|
||||
p := &Processor{
|
||||
BlurRadius: 2,
|
||||
SobelThreshold: 10,
|
||||
NewWidth: newWidth,
|
||||
NewHeight: ImgHeight,
|
||||
Percentage: false,
|
||||
Square: false,
|
||||
Debug: false,
|
||||
}
|
||||
// Reduce image size horizontally
|
||||
|
||||
p.NewWidth = newWidth
|
||||
p.NewHeight = ImgHeight
|
||||
|
||||
for x := 0; x < newWidth; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
@@ -38,20 +27,14 @@ func reduceImageH(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func reduceImageV(t *testing.T) {
|
||||
func TestResize_ReduceImageHeight(t *testing.T) {
|
||||
img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight))
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newHeight := ImgHeight / 2
|
||||
p := &Processor{
|
||||
BlurRadius: 2,
|
||||
SobelThreshold: 10,
|
||||
NewWidth: ImgWidth,
|
||||
NewHeight: newHeight,
|
||||
Percentage: false,
|
||||
Square: false,
|
||||
Debug: false,
|
||||
}
|
||||
// Reduce image size horizontally
|
||||
|
||||
p.NewWidth = ImgWidth
|
||||
p.NewHeight = newHeight
|
||||
|
||||
img = c.RotateImage90(img)
|
||||
for x := 0; x < newHeight; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
@@ -67,3 +50,51 @@ func reduceImageV(t *testing.T) {
|
||||
t.Errorf("Resulted image height expected to be %v. Got %v", newHeight, imgHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResize_IncreaseImageWidth(t *testing.T) {
|
||||
img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight))
|
||||
origImgWidth := img.Bounds().Dx()
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newWidth := ImgWidth * 2
|
||||
|
||||
p.NewWidth = newWidth
|
||||
p.NewHeight = ImgHeight
|
||||
|
||||
for x := 0; x < newWidth; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
c.ComputeSeams(img, p)
|
||||
seams := c.FindLowestEnergySeams()
|
||||
img = c.AddSeam(img, seams, p.Debug)
|
||||
}
|
||||
imgWidth := img.Bounds().Max.X - origImgWidth
|
||||
|
||||
if imgWidth != newWidth {
|
||||
t.Errorf("Resulted image width expected to be %v. Got %v", newWidth, imgWidth)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResize_IncreaseImageHeight(t *testing.T) {
|
||||
img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight))
|
||||
origImgHeigth := img.Bounds().Dy()
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newHeight := ImgHeight * 2
|
||||
|
||||
p.NewWidth = ImgWidth
|
||||
p.NewHeight = newHeight
|
||||
|
||||
img = c.RotateImage90(img)
|
||||
for x := 0; x < newHeight; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
c.ComputeSeams(img, p)
|
||||
seams := c.FindLowestEnergySeams()
|
||||
img = c.AddSeam(img, seams, p.Debug)
|
||||
}
|
||||
img = c.RotateImage270(img)
|
||||
imgHeight := img.Bounds().Max.Y - origImgHeigth
|
||||
|
||||
if imgHeight != newHeight {
|
||||
t.Errorf("Resulted image height expected to be %v. Got %v", newHeight, imgHeight)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user