<commit_before>package packed

import (
	"math/rand"
	"testing"
)

func TestAppendDeltaPackedLongBuffer(t *testing.T) {
	buf := NewAppendingDeltaPackedLongBuffer(16, 1024, 0)
	assert(buf.Size() == 0)
	buf.Add(0)
	assert(buf.Size() == 1)
	assert(buf.Get(0) == 0)
	buf.Add(1)
	assert(buf.Size() == 2)
	assert(buf.Get(1) == 1)

	buf = NewAppendingDeltaPackedLongBuffer(4, 64, 0)
	for i := 0; i <= 65; i++ {
		buf.Add(int64(i))
	}
	assert(buf.Size() == 66)
	for i := 0; i <= 65; i++ {
		v := buf.Get(int64(i))
		if v != int64(i) {
			t.Errorf("buf[%v] should be %v (got %v)", i, i, v)
		}
	}

	next := buf.Iterator()
	for i := 0; i <= 65; i++ {
		v, ok := next()
		assert(ok)
		if v != int64(i) {
			t.Fatalf("buf[%v] should be %v (got %v)", i, i, v)
		}
	}
	_, ok := next()
	assert(!ok)
}

func TestAppendingLongBuffer(t *testing.T) {
	arr := make([]int64, rand.Intn(100)+1)
	radioOptions := []float32{PackedInts.DEFAULT, PackedInts.COMPACT, PackedInts.FAST}
	for _, bpv := range []int{0, 1, 63, 64, rand.Intn(61) + 2} {
		t.Logf("BPV: %v", bpv)
		pageSize := 1 << uint(rand.Intn(15)+6)
		initialPageCount := rand.Intn(17)
		acceptableOverheadRatio := radioOptions[rand.Intn(len(radioOptions))]
		t.Logf("Init AppendingDeltaPackedLongBuffer(%v,%v,%v)", initialPageCount, pageSize, acceptableOverheadRatio)

		// TODO support more data type
		var buf AppendingLongBuffer
		buf = NewAppendingDeltaPackedLongBuffer(initialPageCount, pageSize, acceptableOverheadRatio)
		inc := 0

		switch bpv {
		case 0:
			arr[0] = rand.Int63()
			for i := 1; i < len(arr); i++ {
				arr[i] = arr[i-1] + int64(inc)
			}
		case 64:
			panic("niy")
		default:
			minValue := rand.Int63n(MaxValue(bpv))
			for i := 0; i < len(arr); i++ {<commit_msg>finish simple test<commit_after>package packed

import (
	"math/rand"
	"testing"
)

func TestAppendDeltaPackedLongBuffer(t *testing.T) {
	buf := NewAppendingDeltaPackedLongBuffer(16, 1024, 0)
	assert(buf.Size() == 0)
	buf.Add(0)
	assert(buf.Size() == 1)
	assert(buf.Get(0) == 0)
	buf.Add(1)
	assert(buf.Size() == 2)
	assert(buf.Get(1) == 1)

	buf = NewAppendingDeltaPackedLongBuffer(4, 64, 0)
	for i := 0; i <= 65; i++ {
		buf.Add(int64(i))
	}
	assert(buf.Size() == 66)
	for i := 0; i <= 65; i++ {
		v := buf.Get(int64(i))
		if v != int64(i) {
			t.Errorf("buf[%v] should be %v (got %v)", i, i, v)
		}
	}

	next := buf.Iterator()
	for i := 0; i <= 65; i++ {
		v, ok := next()
		assert(ok)
		if v != int64(i) {
			t.Fatalf("buf[%v] should be %v (got %v)", i, i, v)
		}
	}
	_, ok := next()
	assert(!ok)
}

func TestAppendingLongBuffer(t *testing.T) {
	arr := make([]int64, rand.Intn(100)+1)
	radioOptions := []float32{PackedInts.DEFAULT, PackedInts.COMPACT, PackedInts.FAST}
	for _, bpv := range []int{0, 1, 63, 64, rand.Intn(61) + 2} {
		t.Logf("BPV: %v", bpv)
		pageSize := 1 << uint(rand.Intn(15)+6)
		initialPageCount := rand.Intn(17)
		acceptableOverheadRatio := radioOptions[rand.Intn(len(radioOptions))]
		t.Logf("Init AppendingDeltaPackedLongBuffer(%v,%v,%v)", initialPageCount, pageSize, acceptableOverheadRatio)

		// TODO support more data type
		var buf AppendingLongBuffer
		buf = NewAppendingDeltaPackedLongBuffer(initialPageCount, pageSize, acceptableOverheadRatio)
		inc := 0

		switch bpv {
		case 0:
			arr[0] = rand.Int63()
			for i := 1; i < len(arr); i++ {
				arr[i] = arr[i-1] + int64(inc)
			}
		case 64:
			for i := 0; i < len(arr); i++ {
				arr[i] = rand.Int63()
			}
		default:
			minValue := rand.Int63n(MaxValue(bpv))
			for i := 0; i < len(arr); i++ {
{'fraction_non_alphanumeric': 0.1914407988587732, 'fraction_numerical': 0.0442225392296719, 'mean_word_length': 3.8358620689655174, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2117484', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1462, 'n_words': 327}