29 lines
719 B
Go
29 lines
719 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestGridCellFullRow(t *testing.T) {
|
|
x0, w0 := gridCell(0, 2, 0, 100)
|
|
x1, w1 := gridCell(1, 2, 0, 100)
|
|
if w0 != w1 {
|
|
t.Errorf("cells differ in width: %d vs %d", w0, w1)
|
|
}
|
|
if x0 != 0 {
|
|
t.Errorf("first cell x = %d, want 0", x0)
|
|
}
|
|
if x1+w1 != 100 {
|
|
t.Errorf("row ends at %d, want 100", x1+w1)
|
|
}
|
|
if got := x1 - (x0 + w0); got != chipGap {
|
|
t.Errorf("gap between cells = %d, want %d", got, chipGap)
|
|
}
|
|
}
|
|
|
|
// A last row that does not fill the grid is centred.
|
|
func TestGridCellShortLastRow(t *testing.T) {
|
|
cx, cw := gridCell(2, 3, 0, 100)
|
|
if left, right := cx, 100-(cx+cw); left != right {
|
|
t.Errorf("lone cell has %d left and %d right, want centred", left, right)
|
|
}
|
|
}
|