Switch the project language to English
CI / test (push) Has been cancelled

Comments, doc comments, test names, error and log messages, CLI help, README,
Makefile, CI step names and the design document are now all in English.
No behaviour changes; the full suite passes under the race detector.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ilkerandClaude Opus 5 committed 2026-09-16 01:15:21 +02:00
1 parent b7417e1a69
commit 28029eb43b
21 files changed
+910 -869

No files matched your search

+27 -27
View File
@@ -2,76 +2,76 @@ package sim
import "testing"
func TestBlockHashesZincirleme(t *testing.T) {
// Aynı içerik farklı ön ekten sonra geliyorsa blok hash'i farklı olmalı.
func TestBlockHashesAreChained(t *testing.T) {
// The same content following a different prefix must hash differently.
a := BlockHashes(Tokenize("AAAAAAAABBBBBBBB"), 2)
b := BlockHashes(Tokenize("CCCCCCCCBBBBBBBB"), 2)
if len(a) != 2 || len(b) != 2 {
t.Fatalf("beklenen 2 blok, alınan a=%d b=%d", len(a), len(b))
t.Fatalf("expected 2 blocks each, got a=%d b=%d", len(a), len(b))
}
if a[1] == b[1] {
t.Error("farklı ön ekten sonra gelen aynı blok aynı hash'i verdi; zincirleme çalışmıyor")
t.Error("identical block after different prefixes hashed the same; chaining is broken")
}
}
func TestBlockHashesOnEkKararli(t *testing.T) {
// Blok sınırına hizalı bir ön ek, uzun metinde aynı blok hash'lerini vermeli.
// Hizalama şart: son yarım token farklı olursa onu içeren blok da farklı
// çıkar — gerçek tokenizer'larda da olan sınır etkisi, bu yüzden prefix
// cache hit'i her zaman tam blok cinsinden ölçülür.
const aligned = "merhaba " // 8 bayt = 2 token = blockSize 2 ile 1 tam blok
func TestBlockHashesArePrefixStable(t *testing.T) {
// A prefix aligned to a block boundary must hash identically in a longer
// text. Alignment matters: a differing trailing partial token changes the
// block containing it — the same boundary effect real tokenizers have,
// which is why cache hits are always measured in whole blocks.
const aligned = "merhaba " // 8 bytes = 2 tokens = 1 full block at blockSize 2
short := BlockHashes(Tokenize(aligned), 2)
long := BlockHashes(Tokenize(aligned+"dunya nasilsin"), 2)
if len(short) != 1 {
t.Fatalf("beklenen 1 blok, alınan %d", len(short))
t.Fatalf("expected 1 block, got %d", len(short))
}
if short[0] != long[0] {
t.Fatal("hizalı ön ek blok hash'i değişti; ön ek kararlı değil")
t.Fatal("aligned prefix produced a different block hash; not prefix stable")
}
}
func TestBlockHashesYarimBlokAtilir(t *testing.T) {
// 3 token, blockSize 2 -> 1 tam blok
func TestBlockHashesDropPartialBlock(t *testing.T) {
// 3 tokens at blockSize 2 -> 1 full block
if got := len(BlockHashes(make([]Token, 3), 2)); got != 1 {
t.Errorf("beklenen 1 blok, alınan %d", got)
t.Errorf("expected 1 block, got %d", got)
}
if got := len(BlockHashes(make([]Token, 1), 2)); got != 0 {
t.Errorf("tam blok yokken blok üretildi: %d", got)
t.Errorf("produced %d blocks with no full block available", got)
}
}
func TestPrefixCacheKesintisizOnEk(t *testing.T) {
func TestPrefixCacheReturnsContiguousPrefix(t *testing.T) {
c := NewPrefixCache(10)
h := []BlockHash{1, 2, 3, 4}
c.Insert(h)
if n := c.Lookup(h); n != 4 {
t.Fatalf("tam eşleşme beklendi, alınan %d", n)
t.Fatalf("expected a full match, got %d", n)
}
// Ortası eksik: ilk blok hit, sonrası miss olmalı.
// With a gap in the middle only the first block counts.
if n := c.Lookup([]BlockHash{1, 99, 3}); n != 1 {
t.Errorf("kesintisiz ön ek 1 olmalıydı, alınan %d", n)
t.Errorf("contiguous prefix should have been 1, got %d", n)
}
}
func TestPrefixCacheLRUTahliye(t *testing.T) {
func TestPrefixCacheEvictsLRU(t *testing.T) {
c := NewPrefixCache(2)
c.Insert([]BlockHash{1, 2})
c.Lookup([]BlockHash{1}) // 1'i tazele
c.Insert([]BlockHash{3}) // kapasite aşıldı, en eski (2) düşmeli
c.Lookup([]BlockHash{1}) // refresh 1
c.Insert([]BlockHash{3}) // over capacity: the oldest (2) must go
if n := c.Lookup([]BlockHash{1}); n != 1 {
t.Error("taze blok tahliye edildi")
t.Error("recently used block was evicted")
}
if n := c.Lookup([]BlockHash{2}); n != 0 {
t.Error("en eski blok tahliye edilmeliydi")
t.Error("least recently used block should have been evicted")
}
}
func TestPrefixCacheKapali(t *testing.T) {
func TestPrefixCacheDisabled(t *testing.T) {
c := NewPrefixCache(0)
c.Insert([]BlockHash{1, 2})
if n := c.Lookup([]BlockHash{1}); n != 0 {
t.Errorf("kapalı cache hit verdi: %d", n)
t.Errorf("disabled cache reported a hit: %d", n)
}
}