Skip to content

Commit

Permalink
[x/tour] pic: add a test
Browse files Browse the repository at this point in the history
It's hard to write a normal test because ShowImage writes
to os.Stdout unconditionally. Add an example test instead.

Change-Id: I52e02908e94aa212a05c058edb4f504851b5bb8d
Reviewed-on: https://go-review.googlesource.com/c/tour/+/232866
Run-TryBot: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Alexander Rakoczy <[email protected]>
X-Tour-Commit: 6a4383abac21758536e477d3eed0a63ba560173c
  • Loading branch information
dmitshur committed May 8, 2020
1 parent cc41fcf commit 0f95301
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tour/pic/pic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package pic_test

import "golang.org/x/tour/pic"

func ExampleShow() {
f := func(dx, dy int) [][]uint8 {
ss := make([][]uint8, dy)
for y := 0; y < dy; y++ {
s := make([]uint8, dx)
for x := 0; x < dx; x++ {
s[x] = uint8((x + y) / 2)
}
ss[y] = s
}
return ss
}

pic.Show(f)

// Output:
// IMAGE:iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADKElEQVR4nOzVoRHAMAzAQCfX/VduxjDQk8di+mb+mTlnyKB3vYBc9K4XkIs6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6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