57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package chunk
|
||
|
||
import (
|
||
"testing"
|
||
|
||
"mc/internal/block"
|
||
)
|
||
|
||
// TestIndex 验证一维索引换算。
|
||
func TestIndex(t *testing.T) {
|
||
c := New(0, 0)
|
||
if got := Index(0, 0, 0); got != 0 {
|
||
t.Fatalf("Index(0,0,0) = %d", got)
|
||
}
|
||
if got := Index(1, 0, 0); got != 1 {
|
||
t.Fatalf("Index(1,0,0) = %d", got)
|
||
}
|
||
if got := Index(0, 0, 1); got != 16 {
|
||
t.Fatalf("Index(0,0,1) = %d", got)
|
||
}
|
||
if got := Index(0, 1, 0); got != 256 {
|
||
t.Fatalf("Index(0,1,0) = %d", got)
|
||
}
|
||
_ = c
|
||
}
|
||
|
||
// TestSetGet 验证读写与脏标记。
|
||
func TestSetGet(t *testing.T) {
|
||
c := New(3, -7)
|
||
s := block.NewState(5, 0)
|
||
c.SetBlock(2, 64, 3, s)
|
||
if got := c.Block(2, 64, 3); got != s {
|
||
t.Fatalf("读回 %v,期望 %v", got, s)
|
||
}
|
||
if !c.Dirty.Load() || !c.SaveDirty.Load() {
|
||
t.Fatal("SetBlock 应标记 dirty/saveDirty")
|
||
}
|
||
}
|
||
|
||
// TestNibble 验证 4-bit 光照打包(每字节 2 方块)。
|
||
func TestNibble(t *testing.T) {
|
||
c := New(0, 0)
|
||
// 相邻两个方块:一个偶数索引一个奇数索引,共用一个字节
|
||
c.SetSkyLight(0, 10, 0, 15)
|
||
c.SetSkyLight(1, 10, 0, 7)
|
||
if got := c.SkyLight(0, 10, 0); got != 15 {
|
||
t.Fatalf("sky(0) = %d,期望 15", got)
|
||
}
|
||
if got := c.SkyLight(1, 10, 0); got != 7 {
|
||
t.Fatalf("sky(1) = %d,期望 7", got)
|
||
}
|
||
// 未设置的保持 0
|
||
if got := c.BlockLight(0, 10, 0); got != 0 {
|
||
t.Fatalf("blockLight(0) = %d,期望 0", got)
|
||
}
|
||
}
|