github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/exp/shiny/example/goban/xy_test.go (about)

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