Skip to content

Commit

Permalink
Remove duplicate test data, rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
HECki committed Jun 9, 2023
1 parent 397f1c1 commit 2dedb55
Show file tree
Hide file tree
Showing 52 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gocrop/cropper.go → gocropper/cropper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gocrop
package gocropper

import (
"fmt"
Expand Down
26 changes: 13 additions & 13 deletions gocrop/cropper_test.go → gocropper/cropper_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package gocrop_test
package gocropper_test

import (
"image"
"path"
"sync"
"testing"

"github.com/H3Cki/gocrop/gocrop"
"github.com/H3Cki/gocrop/gocropper"
"github.com/stretchr/testify/assert"
)

Expand All @@ -19,24 +19,24 @@ func TestLoad(t *testing.T) {
{"blank.png", nil},
{"circle.png", nil},
{"line.gif", nil},
{"white.jpg", gocrop.ErrUnsupportedFormat},
{"white.jpg", gocropper.ErrUnsupportedFormat},
{"rect.png", nil},
}

for _, tt := range tests {
t.Run(tt.fn, func(t *testing.T) {
croppable, err := gocrop.Load(path.Join("testdata", tt.fn))
croppable, err := gocropper.Load(path.Join("testdata", tt.fn))
assert.ErrorIs(t, tt.exErr, err)
assert.Equal(t, croppable != nil, tt.exErr == nil)
})
}
}

func TestCropper_Rect(t *testing.T) {
basicCropper, _ := gocrop.NewCropper()
basicCropper, _ := gocropper.NewCropper()

tests := []struct {
cropper *gocrop.Cropper
cropper *gocropper.Cropper
fn string
exRect image.Rectangle
}{
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestCropper_Rect(t *testing.T) {

for _, tt := range tests {
t.Run(tt.fn, func(t *testing.T) {
croppable, err := gocrop.Load(path.Join("testdata/described", tt.fn))
croppable, err := gocropper.Load(path.Join("testdata/described", tt.fn))
assert.NoError(t, err)
assert.NotNil(t, croppable)

Expand All @@ -86,10 +86,10 @@ func TestCropper_Rect(t *testing.T) {

// TODO test only checks img size
func TestCropper_Crop(t *testing.T) {
basicCropper, _ := gocrop.NewCropper()
basicCropper, _ := gocropper.NewCropper()

tests := []struct {
cropper *gocrop.Cropper
cropper *gocropper.Cropper
fn string
exFn string
ok bool
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestCropper_Crop(t *testing.T) {

for _, tt := range tests {
t.Run(tt.fn, func(t *testing.T) {
croppable, err := gocrop.Load(path.Join("testdata/described", tt.fn))
croppable, err := gocropper.Load(path.Join("testdata/described", tt.fn))
assert.NoError(t, err)
assert.NotNil(t, croppable)

Expand All @@ -145,7 +145,7 @@ func TestCropper_Crop(t *testing.T) {
return
}

expectedCrop, err := gocrop.Load(path.Join("testdata/described/cropped", tt.fn))
expectedCrop, err := gocropper.Load(path.Join("testdata/described/cropped", tt.fn))
assert.NoError(t, err)

assert.True(t, imagesEqual(expectedCrop.Image, cropped.Image))
Expand All @@ -158,8 +158,8 @@ func imagesEqual(img1, img2 image.Image) bool {
}

func BenchmarkCropper_Crop(b *testing.B) {
cropper, _ := gocrop.NewCropper(gocrop.WithOutDir("testoutput"))
cpbl, err := gocrop.Load("testdata/bigblank.png")
cropper, _ := gocropper.NewCropper(gocropper.WithOutDir("testoutput"))
cpbl, err := gocropper.Load("testdata/bigblank.png")
assert.NoError(b, err)

n := 10
Expand Down
2 changes: 1 addition & 1 deletion gocrop/finder.go → gocropper/finder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gocrop
package gocropper

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion gocrop/io.go → gocropper/io.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gocrop
package gocropper

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion gocrop/io_test.go → gocropper/io_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gocrop
package gocropper

import (
"runtime"
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
28 changes: 14 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"sync"

"github.com/H3Cki/gocrop/gocrop"
"github.com/H3Cki/gocrop/gocropper"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -107,7 +107,7 @@ func main() {

for _, path := range paths {
go func(p string) {
croppable, err := gocrop.Load(p)
croppable, err := gocropper.Load(p)
if err != nil {
fmt.Println("error loading image: ", err.Error())
return
Expand Down Expand Up @@ -136,15 +136,15 @@ func main() {
return errors.New("no directories specified")
}

opts := []gocrop.FinderOptions{
gocrop.WithRecursive(cCtx.Bool("recursive")),
opts := []gocropper.FinderOptions{
gocropper.WithRecursive(cCtx.Bool("recursive")),
}

if cCtx.IsSet("regex") {
opts = append(opts, gocrop.WithRegex(cCtx.String("regex")))
opts = append(opts, gocropper.WithRegex(cCtx.String("regex")))
}

loader, err := gocrop.NewFinder(opts...)
loader, err := gocropper.NewFinder(opts...)
if err != nil {
return err
}
Expand All @@ -163,7 +163,7 @@ func main() {
wg.Add(len(crops))

for _, croppable := range crops {
go func(c *gocrop.Croppable) {
go func(c *gocropper.Croppable) {
defer wg.Done()

if err := c.Load(); err != nil {
Expand Down Expand Up @@ -191,12 +191,12 @@ func main() {
}
}

func cropperFromCtx(ctx *cli.Context) (*gocrop.Cropper, error) {
return gocrop.NewCropper(
gocrop.WithThreshold(uint32(ctx.Int64("threshold"))),
gocrop.WithPadding(ctx.Int("padding")),
gocrop.WithOutDir(ctx.String("out_dir")),
gocrop.WithOutPrefix(ctx.String("prefix")),
gocrop.WithOutSuffix(ctx.String("suffix")),
func cropperFromCtx(ctx *cli.Context) (*gocropper.Cropper, error) {
return gocropper.NewCropper(
gocropper.WithThreshold(uint32(ctx.Int64("threshold"))),
gocropper.WithPadding(ctx.Int("padding")),
gocropper.WithOutDir(ctx.String("out_dir")),
gocropper.WithOutPrefix(ctx.String("prefix")),
gocropper.WithOutSuffix(ctx.String("suffix")),
)
}
Binary file removed testdata/2squares.png
Binary file not shown.
Binary file removed testdata/bigblank.png
Binary file not shown.
Binary file removed testdata/bigdot.png
Diff not rendered.
Binary file removed testdata/blank.png
Diff not rendered.
Binary file removed testdata/circle.png
Diff not rendered.
Binary file removed testdata/described/circle-25-25-75-75.png
Diff not rendered.
Binary file removed testdata/described/cropped/circle-25-25-75-75.png
Diff not rendered.
Binary file removed testdata/described/cropped/line1px-49-0-50-100.gif
Diff not rendered.
Binary file removed testdata/described/cropped/line1px-49-0-50-100.png
Diff not rendered.
Binary file removed testdata/described/cropped/rect-25-30-75-70.png
Diff not rendered.
Binary file removed testdata/described/cropped/recthollow-25-30-75-70.png
Diff not rendered.
Binary file removed testdata/described/cropped/white-0-0-100-100.png
Diff not rendered.
Binary file removed testdata/described/line1px-49-0-50-100.gif
Diff not rendered.
Binary file removed testdata/described/line1px-49-0-50-100.png
Diff not rendered.
Binary file removed testdata/described/rect-25-30-75-70.png
Diff not rendered.
Binary file removed testdata/described/recthollow-25-30-75-70.png
Diff not rendered.
Binary file removed testdata/described/white-0-0-100-100.png
Diff not rendered.
Binary file removed testdata/line.gif
Diff not rendered.
Binary file removed testdata/rect.png
Diff not rendered.
Binary file removed testdata/rect_inrect.png
Diff not rendered.
Binary file removed testdata/square.png
Diff not rendered.
Binary file removed testdata/square_inrect.png
Diff not rendered.
Binary file removed testdata/white.jpg
Diff not rendered.

0 comments on commit 2dedb55

Please sign in to comment.