package linguistics

import "testing"

func TestKeywordExtractor_Basic(t *testing.T) {
	e := NewKeywordExtractor()
	text := Text{Body: "The quick brown fox jumps over the lazy dog. The quick brown fox!"}
	keywords, err := e.Extract(text)
	if err != nil {
		t.Fatalf("Extract returned error: %v", err)
	}
	if len(keywords) == 0 {
		t.Fatalf("expected some keywords, got 0")
	}
	// Ensure stop words filtered and most frequent word appears first
	if keywords[0].Text != "quick" && keywords[0].Text != "brown" && keywords[0].Text != "fox" {
		t.Errorf("expected a content word as top keyword, got %q", keywords[0].Text)
	}
	for _, kw := range keywords {
		if kw.Text == "the" || kw.Text == "over" {
			t.Errorf("stop word %q should be filtered out", kw.Text)
		}
		if kw.Relevance <= 0 {
			t.Errorf("keyword %q has non-positive relevance", kw.Text)
		}
	}
}
