Files

37 lines
854 B
Go
Raw Permalink Normal View History

package coord
import "testing"
// TestFloorDiv 验证负坐标安全的向下取整除法(设计.md §4.1 踩坑)。
func TestFloorDiv(t *testing.T) {
cases := []struct {
a, b, want int32
}{
{15, 16, 0},
{16, 16, 1},
{-1, 16, -1},
{-16, 16, -1},
{-17, 16, -2},
{0, 16, 0},
}
for _, c := range cases {
if got := FloorDiv(c.a, c.b); got != c.want {
t.Fatalf("FloorDiv(%d, %d) = %d,期望 %d", c.a, c.b, got, c.want)
}
}
}
// TestChunkLocal 验证区块坐标与局部坐标互转(含负数)。
func TestChunkLocal(t *testing.T) {
for _, wx := range []int32{-33, -17, -16, -1, 0, 15, 16, 31} {
cx := ChunkCoord(wx)
lx := LocalCoord(wx)
if lx < 0 || lx >= 16 {
t.Fatalf("LocalCoord(%d) = %d 越界", wx, lx)
}
if cx*16+lx != wx {
t.Fatalf("坐标还原失败: %d → cx=%d lx=%d", wx, cx, lx)
}
}
}