-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_test.go
65 lines (52 loc) · 1.42 KB
/
render_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
// Copyright 2020 Andrew Quinn. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gofrac_test
import (
"github.com/cfdwalrus/gofrac"
"image/color"
"testing"
)
// mocks
type fakePlotter struct {
gofrac.PlotterBase
}
func (p fakePlotter) Plot(r *gofrac.Result) float64 {
return float64(r.Iterations % 2)
}
type fakePalette struct{}
var mockSampleColor func(float64, int) color.Color
func (p fakePalette) SampleColor(val float64, maxIterations int) color.Color {
return mockSampleColor(val, maxIterations)
}
// real stuff
func TestRender(t *testing.T) {
rows := 10
cols := 6
fakeResults := gofrac.NewResults(rows, cols, rows)
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
fakeResults.SetResult(row, col, 0, 0, row)
}
}
mockSampleColor = func(val float64, _ int) color.Color {
if val == 0.0 {
return color.Black
}
return color.White
}
// feed Render fakePlotter, which maps fakeResults to alternating {0, 1}
// values, then map those values to black and white, respectively, with
// fakePalette
bitmap := gofrac.Render(&fakeResults, &fakePlotter{}, fakePalette{})
for row := 0; row < rows; row++ {
c := mockSampleColor(float64(row%2), 0)
for col := 0; col < cols; col++ {
want := c
got := bitmap[row][col]
if want != got {
t.Errorf("Render: want: %v, got: %v", want, got)
}
}
}
}