added CountVarUint64, CountVarUint32, CountVarSize

This commit is contained in:
2025-11-01 16:16:20 +00:00
parent 142699e328
commit 7fa2d0f292
2 changed files with 151 additions and 15 deletions

View File

@@ -703,6 +703,96 @@ func TestWriteReadBool(t *testing.T) {
}
}
// VAR SIZE COUNT
func TestCountVarUint32(t *testing.T) {
var testCases = []struct {
Num uint32
Count int
}{
{Num: (1 << 7) - 1, Count: 1},
{Num: (1 << 7), Count: 2},
{Num: (1 << 14) - 1, Count: 2},
{Num: (1 << 14), Count: 3},
{Num: (1 << 21) - 1, Count: 3},
{Num: (1 << 21), Count: 4},
{Num: (1 << 28) - 1, Count: 4},
{Num: (1 << 28), Count: 5},
{Num: (1 << 32) - 1, Count: 5},
}
for _, testCase := range testCases {
count := CountVarUint32(testCase.Num)
if count != testCase.Count {
t.Fatalf("calculated count %d is not equal %d for num %d\n",
count, testCase.Count, testCase.Num)
}
}
}
func TestCountVarUint64(t *testing.T) {
var testCases = []struct {
Num uint64
Count int
}{
{Num: (1 << 7) - 1, Count: 1},
{Num: (1 << 7), Count: 2},
{Num: (1 << 14) - 1, Count: 2},
{Num: (1 << 14), Count: 3},
{Num: (1 << 21) - 1, Count: 3},
{Num: (1 << 21), Count: 4},
{Num: (1 << 28) - 1, Count: 4},
{Num: (1 << 28), Count: 5},
{Num: (1 << 35) - 1, Count: 5},
{Num: (1 << 35), Count: 6},
{Num: (1 << 42) - 1, Count: 6},
{Num: (1 << 42), Count: 7},
{Num: (1 << 49) - 1, Count: 7},
{Num: (1 << 49), Count: 8},
{Num: (1 << 56) - 1, Count: 8},
{Num: (1 << 56), Count: 9},
{Num: (1 << 64) - 1, Count: 9},
}
for _, testCase := range testCases {
count := CountVarUint64(testCase.Num)
if count != testCase.Count {
t.Fatalf("calculated count %d is not equal %d for num %d\n",
count, testCase.Count, testCase.Num)
}
}
}
func TestCountVarSize(t *testing.T) {
var testCases = []struct {
Num int
Count int
}{
{Num: (1 << 7) - 1, Count: 1},
{Num: (1 << 7), Count: 2},
{Num: (1 << 14) - 1, Count: 2},
{Num: (1 << 14), Count: 3},
{Num: (1 << 21) - 1, Count: 3},
{Num: (1 << 21), Count: 4},
{Num: (1 << 28) - 1, Count: 4},
{Num: (1 << 28), Count: 5},
{Num: (1 << 35) - 1, Count: 5},
{Num: (1 << 35), Count: 6},
{Num: (1 << 42) - 1, Count: 6},
{Num: (1 << 42), Count: 7},
{Num: (1 << 49) - 1, Count: 7},
{Num: (1 << 49), Count: 8},
{Num: (1 << 56) - 1, Count: 8},
{Num: (1 << 56), Count: 9},
{Num: (1 << 63) - 1, Count: 9},
}
for _, testCase := range testCases {
count := CountVarSize(testCase.Num)
if count != testCase.Count {
t.Fatalf("calculated count %d is not equal %d for num %d\n",
count, testCase.Count, testCase.Num)
}
}
}
// HELPERS
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"