<commit_before>package state

import (
	"os"
	"testing"
)

func Test_PutAndGet_WithCreatedBucket_PutsAndGetsCorrectly(t *testing.T) {
	dataStoreFile := "test_temp_db"

	bolt, err := NewBoltDataStore(dataStoreFile)
	if err != nil {
		t.Error("Creating BoltDataStore failed:", err)
	}

	bolt.Put("key", "value")

	value, _ := bolt.Get("key")
	if value != "value" {
		t.Error("Retrieved value did not equal expected:", "value", value)
	}

	os.Remove(dataStoreFile)
}<commit_msg>Add log entry tests for BoltDataStore<commit_after>package state

import (
	"os"
	"testing"
)

func Test_BoltPutAndGet_WithCreatedBucket_PutsAndGetsCorrectly(t *testing.T) {
	dataStoreFile := "test_temp_db"

	bolt, err := NewBoltDataStore(dataStoreFile)
	if err != nil {
		t.Fatal("Creating BoltDataStore failed:", err)
	}

	bolt.Put("key", "value")

	value, _ := bolt.Get("key")
	if value != "value" {
		t.Error("Retrieved value did not equal expected:", "value", value)
	}

	os.Remove(dataStoreFile)
}

func Test_RetrieveBoltLogEntries_WhenNoEntriesExist_ReturnsEmptySlice(t *testing.T) {
	dataStoreFile := "test_temp_db"

	bolt, err := NewBoltDataStore(dataStoreFile)
	if err != nil {
		t.Fatal("Creating BoltDataStore failed:", err)
	}

	entries, err := bolt.RetrieveLogEntries(1, 5)
	if err != nil {
		t.Fatal(err)
	}

	if len(entries) != 0 {
		t.Error("Number of returned entries is not 0:", len(entries))
	}

	os.Remove(dataStoreFile)
}

func Test_RetrieveBoltLogEntries_WhenWholeRangeExists_ReturnsLogEntriesInRange(t *testing.T) {
	var tests = []struct {
		key string
		entry LogEntry
		jsonRep string
	}{
		{"1", LogEntry{"a", "A", 0}, "{\"Key\":\"a\",\"Value\":\"A\",\"Term\":0}"},
		{"2", LogEntry{"b", "B", 0}, "{\"Key\":\"b\",\"Value\":\"B\",\"Term\":0}"},
		{"3", LogEntry{"c", "C", 1}, "{\"Key\":\"c\",\"Value\":\"C\",\"Term\":1}"},
		{"4", LogEntry{"d", "D", 2}, "{\"Key\":\"d\",\"Value\":\"D\",\"Term\":2}"},
	}

	dataStoreFile := "test_temp_db"

	bolt, err := NewBoltDataStore(dataStoreFile)
	if err != nil {
		t.Fatal("Creating BoltDataStore failed:", err)
	}

	for _, test := range tests {
		bolt.Put(test.key, test.jsonRep)
	}

	retrievedEntries, err := bolt.RetrieveLogEntries(1, len(tests))
	if err != nil {
		os.Remove(dataStoreFile)
		t.Fatal(err)
	}

	if len(retrievedEntries) != len(tests) {
		os.Remove(dataStoreFile)
		t.Fatalf("Number of returned entries is not %d: %d", len(tests), len(retrievedEntries))
	}

	for i := 0; i < len(tests); i++ {
		if retrievedEntries[i] != tests[i].entry {
			t.Errorf("The retrieved entry at index %d does not match expected %v: %v", i, tests[i].entry, retrievedEntries[i])
		}
	}

	os.Remove(dataStoreFile)
}
{'fraction_non_alphanumeric': 0.1895054737636844, 'fraction_numerical': 0.006795016987542469, 'mean_word_length': 4.602536997885835, 'pattern_counts': {'":': 12, '<': 4, '<?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': '6587349', 'n_tokens_mistral': 1067, 'n_tokens_neox': 988, 'n_words': 210}