-
Notifications
You must be signed in to change notification settings - Fork 15
/
overlap-model_test.go
69 lines (61 loc) · 1.64 KB
/
overlap-model_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package wfc
import (
"github.com/shawnridgeway/wfc/internal/testutils"
"image"
"testing"
)
func overlappingTest(t *testing.T, filename, snapshotFilename string, iterations int) {
// Set test parameters
periodicInput := true
periodicOutput := true
hasGround := true
width := 48
height := 48
n := 3
symetry := 2
seed := int64(42)
// Load input sample image
inputImg, err := testutils.LoadImage("internal/input/" + filename)
if err != nil {
panic(err)
}
// Generate output image
var outputImg image.Image
success, finished := false, false
model := NewOverlappingModel(inputImg, n, width, height, periodicInput, periodicOutput, symetry, hasGround)
model.SetSeed(seed)
if iterations == -1 {
outputImg, success = model.Generate()
if !success {
t.Log("Failed to generate image on the first try.")
t.FailNow()
}
} else {
outputImg, finished, _ = model.Iterate(iterations)
if finished {
t.Log("Test for incomplete state actually finished.")
t.FailNow()
}
}
// Save output
// err = testutils.SaveImage("internal/snapshots/"+snapshotFilename, outputImg)
// if err != nil {
// panic(err)
// }
// Test that files match
snapshotImg, err := testutils.LoadImage("internal/snapshots/" + snapshotFilename)
if err != nil {
panic(err)
}
areEqual := testutils.CompareImages(outputImg, snapshotImg)
if !areEqual {
t.Log("Output image is not the same as the snapshot image.")
t.FailNow()
}
}
func TestOverlappingGenerationCompletes(t *testing.T) {
overlappingTest(t, "flowers.png", "flowers.png", -1)
}
func TestOverlappingIterationIncomplete(t *testing.T) {
overlappingTest(t, "flowers.png", "flowers_incomplete.png", 5)
}