package main import "testing" func TestGridCellFullRow(t *testing.T) { x0, w0 := gridCell(0, 2, gridCols, 0, 100) x1, w1 := gridCell(1, 2, gridCols, 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, gridCols, 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) } } // The panel is a fixed 600x1024, so whether everything fits is decidable here // rather than on the hardware, with enough spare that the gaps stay readable. func TestPanelFitsScreen(t *testing.T) { d := &display{} for _, spec := range []struct { dst **textFace bold bool size float64 }{ {&d.big, true, 40}, {&d.grid, false, 34}, {&d.gridB, true, 34}, } { face, err := loadFace(spec.bold, spec.size) if err != nil { t.Fatal(err) } *spec.dst = face } if err := d.layout(600, 1024); err != nil { t.Fatal(err) } gap := d.nowYs[0] - (d.nowPanel.y + uiBorder) t.Logf("panel gap %dpx, since panel ends at %dpx", gap, d.sincePanel.y+d.sincePanel.h) if gap < spaceTight { t.Errorf("panel gap is %dpx, want at least %d", gap, spaceTight) } }