| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
package main |
| 12 |
|
| 13 |
import "testing" |
| 14 |
|
| 15 |
func TestIJXYCorners(t *testing.T) { |
| 16 |
var d Dims |
| 17 |
d.Init(19, 100) |
| 18 |
xSize := (d.dim - 1) * d.squareWidth |
| 19 |
ySize := (d.dim - 1) * d.squareHeight |
| 20 |
ij := IJ{1, 1} |
| 21 |
xy := ij.XY(&d) |
| 22 |
if xy.x != d.xInset || xy.y != d.yInset+ySize { |
| 23 |
t.Errorf("%d got %d", ij, xy) |
| 24 |
} |
| 25 |
ij = IJ{1, d.dim} |
| 26 |
xy = ij.XY(&d) |
| 27 |
if xy.x != d.xInset || xy.y != d.yInset { |
| 28 |
t.Errorf("%d got %d", ij, xy) |
| 29 |
} |
| 30 |
ij = IJ{d.dim, 1} |
| 31 |
xy = ij.XY(&d) |
| 32 |
if xy.x != d.xInset+xSize || xy.y != d.yInset+ySize { |
| 33 |
t.Errorf("%d got %d", ij, xy) |
| 34 |
} |
| 35 |
ij = IJ{d.dim, d.dim} |
| 36 |
xy = ij.XY(&d) |
| 37 |
if xy.x != d.xInset+xSize || xy.y != d.yInset { |
| 38 |
t.Errorf("%d got %d", ij, xy) |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
func TestIJXYCenterRoundTrip(t *testing.T) { |
| 43 |
var d Dims |
| 44 |
d.Init(19, 100) |
| 45 |
for i := 1; i <= d.dim; i++ { |
| 46 |
for j := 1; j <= d.dim; j++ { |
| 47 |
ij := IJ{i, j} |
| 48 |
xy := ij.XYCenter(&d) |
| 49 |
ij2, ok := xy.IJ(&d) |
| 50 |
if !ok { |
| 51 |
t.Error("failed to round trip") |
| 52 |
} |
| 53 |
if ij2 != ij { |
| 54 |
t.Errorf("%d round trip got %d\n", ij, ij2) |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
func TestIJString(t *testing.T) { |
| 61 |
var d Dims |
| 62 |
d.Init(19, 100) |
| 63 |
ij := IJ{1, 1} |
| 64 |
if ij.String() != "A1" { |
| 65 |
t.Errorf("%#v prints as %q", ij, ij.String()) |
| 66 |
} |
| 67 |
ij = IJ{1, 19} |
| 68 |
if ij.String() != "A19" { |
| 69 |
t.Errorf("%#v prints as %q", ij, ij.String()) |
| 70 |
} |
| 71 |
ij = IJ{19, 1} |
| 72 |
if ij.String() != "S1" { |
| 73 |
t.Errorf("%#v prints as %q", ij, ij.String()) |
| 74 |
} |
| 75 |
ij = IJ{19, 19} |
| 76 |
if ij.String() != "S19" { |
| 77 |
t.Errorf("%#v prints as %q", ij, ij.String()) |
| 78 |
} |
| 79 |
} |