main_test.go 533 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestPosToGrid(t *testing.T) {
  6. if id := posToGrid(Pos{5, 3}, 3); id != 29 {
  7. t.Errorf("expected 21; got %d", id)
  8. }
  9. pos := gridToPos(29, 8, 3)
  10. if pos.x != 5 || pos.y != 3 {
  11. t.Errorf("expected (5, 3); got (%d, %d)", pos.x, pos.y)
  12. }
  13. pos = gridToPos(0, 8, 3)
  14. if pos.x != 0 || pos.y != 0 {
  15. t.Errorf("expected (0, 0); got (%d, %d)", pos.x, pos.y)
  16. }
  17. pos = gridToPos(524288, 1024, 10)
  18. if pos.x != 0 || pos.y != 512 {
  19. t.Errorf("expected (0, 512); got (%d, %d)", pos.x, pos.y)
  20. }
  21. }