From d721f2b43dc2d14843dab6b5001accccc779675e Mon Sep 17 00:00:00 2001 From: qeesung <1245712564@qq.com> Date: Sun, 28 Oct 2018 15:02:18 +0800 Subject: [PATCH] add convert examples --- convert/convert_test.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/convert/convert_test.go b/convert/convert_test.go index 6710b66..b43eab3 100644 --- a/convert/convert_test.go +++ b/convert/convert_test.go @@ -1,6 +1,7 @@ package convert import ( + "fmt" "github.com/stretchr/testify/assert" "reflect" "testing" @@ -93,7 +94,6 @@ func TestImageFile2ASCIIString(t *testing.T) { } } - // BenchmarkBigImage2ASCIIMatrix benchmark convert big image to ascii func BenchmarkBigImage2ASCIIMatrix(b *testing.B) { convertOptions := DefaultOptions @@ -102,7 +102,7 @@ func BenchmarkBigImage2ASCIIMatrix(b *testing.B) { convertOptions.ExpectedWidth = 200 convertOptions.ExpectedHeight = 200 - for i:=0; i< b.N; i++ { + for i := 0; i < b.N; i++ { _ = ImageFile2ASCIIMatrix("testdata/cat_2000x1500.jpg", &convertOptions) } } @@ -115,7 +115,22 @@ func BenchmarkSmallImage2ASCIIMatrix(b *testing.B) { convertOptions.ExpectedWidth = 200 convertOptions.ExpectedHeight = 200 - for i:=0; i< b.N; i++ { + for i := 0; i < b.N; i++ { _ = ImageFile2ASCIIMatrix("testdata/husky_200x200.jpg", &convertOptions) } } + +// ExampleImage2ASCIIMatrix is example +func ExampleImage2ASCISString() { + imageFilename := "testdata/3x3_white.png" + convertOptions := DefaultOptions + convertOptions.FitScreen = false + convertOptions.Colored = false + asciiString := ImageFile2ASCIIString(imageFilename, &convertOptions) + fmt.Println(asciiString) + /* Output: +@@@ +@@@ +@@@ + */ +} -- 2.45.2