experimental-pigeongo/internal/codec/lipmaa_test.go

71 lines
1.6 KiB
Go

package codec
import (
"testing"
"github.com/stretchr/testify/assert"
)
type lipmaaLinkExample struct {
input, expected uint
}
func Test_lipmaaLink(t *testing.T) {
tt := []lipmaaLinkExample{
lipmaaLinkExample{0, 0},
lipmaaLinkExample{1, 0},
lipmaaLinkExample{2, 1},
lipmaaLinkExample{3, 2},
lipmaaLinkExample{4, 1},
lipmaaLinkExample{5, 4},
lipmaaLinkExample{6, 5},
lipmaaLinkExample{7, 6},
lipmaaLinkExample{8, 4},
lipmaaLinkExample{13, 4},
}
for _, td := range tt {
assert.Equal(t, td.expected, lipmaaLink(td.input))
}
// for _, td := range tt {
// assert.Equal(t, td.expected, lipmaaLink2(td.input))
// }
}
type lipmaaLSExample struct {
l, d uint
expected []uint
}
func TestCalculateLipmaaLayerSequence_fromzero(t *testing.T) {
tt := []lipmaaLSExample{}
var v, l, d uint = 0, 1, 10
s := []uint{0}
for l < d {
tl := lipmaaLSExample{l, l, s}
tt = append(tt, tl)
v = (v * 3) + 1
s = append(s, v)
l++
}
for _, td := range tt {
a := CalculateLipmaaLayerSequence(td.l, td.d, []uint{})
assert.Equal(t, td.expected, a)
}
}
func BenchmarkCalulatedLipmaaLayerSequence(b *testing.B) {
for i := 0; i < b.N; i++ {
b.Run("depth=10", newBenchmarkCalulatedLipmaaLayerSequence(10))
b.Run("depth=1000", newBenchmarkCalulatedLipmaaLayerSequence(1000))
b.Run("depth=100000", newBenchmarkCalulatedLipmaaLayerSequence(100000))
b.Run("depth=1000000", newBenchmarkCalulatedLipmaaLayerSequence(1000000))
}
}
func newBenchmarkCalulatedLipmaaLayerSequence(d uint) func(b *testing.B) {
return func(b *testing.B) {
var seq []uint
b.ResetTimer()
seq = CalculateLipmaaLayerSequence(1, d, seq)
}
}