Files
ngzz-mc/internal/coord/coord_test.go

37 lines
854 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
}
}