mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-22 20:06:02 +03:00
20 lines
360 B
Go
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()
|
|
}
|
|
}
|