123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- package drawimg
- import (
- "image"
- "image/color"
- "image/jpeg"
- "io"
- "testing"
- "github.com/bouk/monkey"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDrawimgString(t *testing.T) {
- convey.Convey("String", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := JPEG.String()
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgOpen(t *testing.T) {
- convey.Convey("Open", t, func(ctx convey.C) {
- var (
- filename = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1, err := Open(filename)
- ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldBeNil)
- ctx.So(err, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgEncode(t *testing.T) {
- convey.Convey("Encode", t, func(ctx convey.C) {
- var (
- w io.Writer
- img = image.NewRGBA(imgRectangle)
- format = JPEG
- )
- monkeyJpegEncode()
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- err := Encode(w, img, format)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- })
- })
- })
- }
- func TestDrawimgSave(t *testing.T) {
- convey.Convey("Save", t, func(ctx convey.C) {
- var (
- img image.Image
- filename = ""
- )
- ctx.Convey("When everything goes not positive", func(ctx convey.C) {
- err := Save(img, filename)
- ctx.Convey("Then err should be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgNewNRGBA(t *testing.T) {
- convey.Convey("NewNRGBA", t, func(ctx convey.C) {
- var (
- width = int(0)
- height = int(0)
- fillColor color.Color
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := NewNRGBA(width, height, fillColor)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgClone(t *testing.T) {
- convey.Convey("Clone", t, func(ctx convey.C) {
- var (
- rgba = image.NewRGBA(imgRectangle)
- rgba64 = image.NewNRGBA64(imgRectangle)
- )
- ctx.Convey("RGBA", func(ctx convey.C) {
- p1 := Clone(rgba)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- ctx.Convey("RGBA64", func(ctx convey.C) {
- p1 := Clone(rgba64)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgtoNRGBA(t *testing.T) {
- convey.Convey("toNRGBA", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := toNRGBA(img)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgAdjustFunc(t *testing.T) {
- convey.Convey("AdjustFunc", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- fn = func(c color.NRGBA) color.NRGBA { return c }
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := AdjustFunc(img, fn)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgAdjustGamma(t *testing.T) {
- convey.Convey("AdjustGamma", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- gamma = float64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := AdjustGamma(img, gamma)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgsigmoid(t *testing.T) {
- convey.Convey("sigmoid", t, func(ctx convey.C) {
- var (
- a = float64(0)
- b = float64(0)
- x = float64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := sigmoid(a, b, x)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgAdjustSigmoid(t *testing.T) {
- convey.Convey("AdjustSigmoid", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- midpoint = float64(0)
- factor = float64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := AdjustSigmoid(img, midpoint, factor)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgAdjustContrast(t *testing.T) {
- convey.Convey("AdjustContrast", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- percentage = float64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := AdjustContrast(img, percentage)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgAdjustBrightness(t *testing.T) {
- convey.Convey("AdjustBrightness", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- percentage = float64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := AdjustBrightness(img, percentage)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgGrayscale(t *testing.T) {
- convey.Convey("Grayscale", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := Grayscale(img)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgInvert(t *testing.T) {
- convey.Convey("Invert", t, func(ctx convey.C) {
- var (
- img = image.NewRGBA64(imgRectangle)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := Invert(img)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgparallel(t *testing.T) {
- convey.Convey("parallel", t, func(ctx convey.C) {
- var (
- dataSize = int(0)
- fn func(partStart int, partEnd int)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- parallel(dataSize, fn)
- ctx.Convey("No return values", func(ctx convey.C) {
- })
- })
- })
- }
- func TestDrawimgabsint(t *testing.T) {
- convey.Convey("absint", t, func(ctx convey.C) {
- var (
- i = int(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := absint(i)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDrawimgclamp(t *testing.T) {
- convey.Convey("clamp", t, func(ctx convey.C) {
- var (
- x = float64(0)
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := clamp(x)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func monkeyJpegEncode() {
- monkey.Patch(jpeg.Encode, func(_ io.Writer, _ image.Image, _ *jpeg.Options) error {
- return nil
- })
- }
|