lotus/lib/rlepluslazy/bits_test.go
Jakub Sztandera e5b3c4757d
More iterative algorithms
- Add RunIterator and decoder from RLE
 - Add BitIterator and BitsFromRuns
 - Add BitsFromSlice
 - Add RunsFromBits

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
2019-12-07 15:48:19 +01:00

28 lines
586 B
Go

package rlepluslazy
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRunsFromBits(t *testing.T) {
expected := []Run{Run{Val: false, Len: 0x1},
{Val: true, Len: 0x3},
{Val: false, Len: 0x2},
{Val: true, Len: 0x3},
}
rit, err := RunsFromBits(BitsFromSlice([]uint64{1, 2, 3, 6, 7, 8}))
assert.NoError(t, err)
i := 10
output := make([]Run, 0, 4)
for rit.HasNext() && i > 0 {
run, err := rit.NextRun()
assert.NoError(t, err)
i--
output = append(output, run)
}
assert.NotEqual(t, 0, i, "too many iterations")
assert.Equal(t, expected, output)
}