add unit test for paletteSection

This commit is contained in:
Tnze
2020-05-19 16:15:39 +08:00
parent 39c9525525
commit 97dca98819
2 changed files with 56 additions and 20 deletions

View File

@ -6,7 +6,7 @@ import (
"testing"
)
func newDirectSection(bpb int) *directSection {
func newDirectSection(bpb int) Section {
return &directSection{
bpb: bpb,
data: make([]uint64, 16*16*16*bpb/64),
@ -14,16 +14,26 @@ func newDirectSection(bpb int) *directSection {
}
func TestDirectSection(t *testing.T) {
for bpb := 3; bpb <= data.BitsPerBlock; bpb++ {
s := newDirectSection(bpb)
for _, dataset := range [][16 * 16 * 16]BlockStatus{secData(bpb), randData(bpb)} {
for i := 0; i < 16*16*16; i++ {
s.SetBlock(i%16, i/16%16, i/16/16, dataset[i])
}
for i := 0; i < 16*16*16; i++ {
if s := s.GetBlock(i%16, i/16%16, i/16/16); dataset[i] != s {
t.Fatalf("direct section error: want: %v, get %v", dataset[i], s)
}
for bpb := 4; bpb < data.BitsPerBlock; bpb++ {
testSection(t, newDirectSection(bpb), bpb)
}
}
func TestPaletteSection(t *testing.T) {
testSection(t, &paletteSection{
palettesIndex: make(map[BlockStatus]int),
directSection: *(newDirectSection(7).(*directSection)),
}, 7)
}
func testSection(t *testing.T, s Section, bpb int) {
for _, dataset := range [][16 * 16 * 16]BlockStatus{secData(bpb), randData(bpb)} {
for i := 0; i < 16*16*16; i++ {
s.SetBlock(i%16, i/16%16, i/16/16, dataset[i])
}
for i := 0; i < 16*16*16; i++ {
if s := s.GetBlock(i%16, i/16%16, i/16/16); dataset[i] != s {
t.Fatalf("direct section error: want: %v, get %v", dataset[i], s)
}
}
}