go-pattern-examples/structure/18_flyweight/flyweight_test.go
2020-04-21 22:53:23 +08:00

20 lines
360 B
Go

package flyweight
import "testing"
func ExampleFlyweight() {
viewer := NewImageViewer("image1.png")
viewer.Display()
// Output:
// Display: image data image1.png
}
func TestFlyweight(t *testing.T) {
viewer1 := NewImageViewer("image1.png")
viewer2 := NewImageViewer("image1.png")
if viewer1.ImageFlyweight != viewer2.ImageFlyweight {
t.Fail()
}
}