package lattice import "testing" func TestBigramKeyDeterministic(t *testing.T) { k1 := BigramKey(LangEN, []byte("going"), []byte("home")) k2 := BigramKey(LangEN, []byte("going"), []byte("home")) if k1 != k2 { t.Errorf("BigramKey not deterministic: %x != %x", k1, k2) } } func TestBigramKeyDifferentPairs(t *testing.T) { k1 := BigramKey(LangEN, []byte("going"), []byte("home")) k2 := BigramKey(LangEN, []byte("going"), []byte("house")) if k1 == k2 { t.Errorf("different pairs produced same key: %x", k1) } } func TestBigramKeyDifferentLanguages(t *testing.T) { k1 := BigramKey(LangEN, []byte("going"), []byte("home")) k2 := BigramKey(LangBG, []byte("going"), []byte("home")) if k1 == k2 { t.Errorf("different languages produced same key: %x", k1) } } func TestBigramKeyLanguageTag(t *testing.T) { k := BigramKey(LangEN, []byte("going"), []byte("home")) if KeyLang(k) != LangEN { t.Errorf("BigramKey lang = %d, want %d", KeyLang(k), LangEN) } k2 := BigramKey(LangBG, []byte("отивам"), []byte("вкъщи")) if KeyLang(k2) != LangBG { t.Errorf("BigramKey lang = %d, want %d", KeyLang(k2), LangBG) } } func TestBigramKeyOrderMatters(t *testing.T) { k1 := BigramKey(LangEN, []byte("big"), []byte("house")) k2 := BigramKey(LangEN, []byte("house"), []byte("big")) if k1 == k2 { t.Errorf("reversed pairs should have different keys: %x", k1) } } func TestBigramKeyInsertAndLookup(t *testing.T) { tree := NewTree(100) k := BigramKey(LangEN, []byte("going"), []byte("home")) insertWord(t, tree, Bcooccur, k) _, _, found, err := tree.Walk(Bcooccur, k) if err != nil || !found { t.Errorf("bigram key not found after insert (%v)", err) } }