package strategy import ( "strings" "testing" "git.mleku.dev/mleku/dendrite/pkg/axiom" "git.mleku.dev/mleku/dendrite/pkg/lattice" ) func TestChaptersParse(t *testing.T) { chs := Chapters() for i, ch := range chs { if ch.Number != i+1 { t.Errorf("chapter %d: got Number=%d", i+1, ch.Number) } if ch.Title == "" { t.Errorf("chapter %d: empty title", i+1) } if ch.Text == "" { t.Errorf("chapter %d %q: empty text", i+1, ch.Title) } if int(ch.Category) != i { t.Errorf("chapter %d: expected category %d, got %d", i+1, i, ch.Category) } } } func TestChaptersHaveMaxims(t *testing.T) { chs := Chapters() total := 0 for _, ch := range chs { total += len(ch.Maxims) } if total < 20 { t.Errorf("expected at least 20 maxims across all chapters, got %d", total) } t.Logf("total maxims across 13 chapters: %d", total) } func TestStrategyElementInterfaces(t *testing.T) { e := StrategyElement{ Content: "All warfare is based on deception.", Ch: 1, Cat: CatAssessment, Lvl: LevelMaxim, } // axiom.Element var elem axiom.Element = e if elem.Type() != "strategy:assessment:maxim" { t.Errorf("unexpected type: %s", elem.Type()) } if elem.Value().(string) != "All warfare is based on deception." { t.Errorf("unexpected value: %v", elem.Value()) } // axiom.StickyElement var sticky axiom.StickyElement = e if !sticky.IsSticky() { t.Error("strategy element should be sticky") } // axiom.LayeredElement var layered axiom.LayeredElement = e if layered.Layer().Name != "strategy" { t.Errorf("unexpected layer: %s", layered.Layer().Name) } if layered.Layer().Depth != int(LevelMaxim) { t.Errorf("unexpected depth: %d", layered.Layer().Depth) } } func TestStrategyConstraintAdmits(t *testing.T) { c := StrategyConstraint{Cat: CatAssessment, MinLevel: LevelMaxim} // Should admit matching element. good := StrategyElement{Cat: CatAssessment, Lvl: LevelMaxim} if !c.Admits(good) { t.Error("constraint should admit matching element") } // Should admit finer level. finer := StrategyElement{Cat: CatAssessment, Lvl: LevelTactic} if !c.Admits(finer) { t.Error("constraint should admit finer-grained element") } // Should reject coarser level. coarser := StrategyElement{Cat: CatAssessment, Lvl: LevelChapter} if c.Admits(coarser) { t.Error("constraint should reject coarser element") } // Should reject wrong category. wrong := StrategyElement{Cat: CatIntelligence, Lvl: LevelMaxim} if c.Admits(wrong) { t.Error("constraint should reject wrong category") } } func TestCategoryConstraint(t *testing.T) { c := CategoryConstraint{} if c.Tag() != "strategy" { t.Errorf("unexpected tag: %s", c.Tag()) } good := StrategyElement{Cat: CatForce, Lvl: LevelTactic} if !c.Admits(good) { t.Error("category constraint should admit any strategy element") } } func TestEnzymeDigest(t *testing.T) { ch := DigestEmbedded() counts := map[Level]int{} total := 0 for elem := range ch { se, ok := elem.(StrategyElement) if !ok { t.Fatalf("expected StrategyElement, got %T", elem) } counts[se.Lvl]++ total++ } if counts[LevelChapter] != 13 { t.Errorf("expected 13 chapter elements, got %d", counts[LevelChapter]) } if counts[LevelPrinciple] < 10 { t.Errorf("expected at least 10 principle elements, got %d", counts[LevelPrinciple]) } if counts[LevelMaxim] < 10 { t.Errorf("expected at least 10 maxim elements, got %d", counts[LevelMaxim]) } t.Logf("enzyme emitted %d elements: chapter=%d principle=%d maxim=%d tactic=%d", total, counts[LevelChapter], counts[LevelPrinciple], counts[LevelMaxim], counts[LevelTactic]) } func TestSeed(t *testing.T) { l := lattice.New() bonded := Seed(l) if bonded == 0 { t.Error("expected at least some elements to bond") } if l.Size() < 260 { t.Errorf("expected at least 260 nodes, got %d", l.Size()) } // Check that bonded elements are sticky. for _, n := range l.Nodes() { if !n.Occupied() { continue } if sticky, ok := n.Occupant().(axiom.StickyElement); ok { if !sticky.IsSticky() { t.Error("strategy element should be sticky") } } } t.Logf("seed: %d elements bonded to %d-node lattice", bonded, l.Size()) } func TestSplitSentences(t *testing.T) { text := "All warfare is based on deception. Hence, when able to attack, we must seem unable." sentences := splitSentences(text) if len(sentences) != 2 { t.Errorf("expected 2 sentences, got %d", len(sentences)) } } func TestCategoryString(t *testing.T) { if CatAssessment.String() != "assessment" { t.Errorf("unexpected: %s", CatAssessment.String()) } if CatIntelligence.String() != "intelligence" { t.Errorf("unexpected: %s", CatIntelligence.String()) } } func TestLevelString(t *testing.T) { if LevelChapter.String() != "chapter" { t.Errorf("unexpected: %s", LevelChapter.String()) } if LevelTactic.String() != "tactic" { t.Errorf("unexpected: %s", LevelTactic.String()) } } func TestEmbeddedTextPresent(t *testing.T) { if len(artOfWarText) < 1000 { t.Errorf("embedded Art of War text too short: %d bytes", len(artOfWarText)) } if !strings.Contains(artOfWarText, "## I.") { t.Error("embedded text missing chapter I marker") } if !strings.Contains(artOfWarText, "## XIII.") { t.Error("embedded text missing chapter XIII marker") } }