package lattice import "testing" func TestMakeTritPath(t *testing.T) { // Empty path: all zeros = unassigned. p := MakeTritPath() if p.Depth() != 0 { t.Errorf("empty path depth: got %d, want 0", p.Depth()) } if p.Branch() != TritEnd { t.Errorf("empty path branch: got %d, want %d", p.Branch(), TritEnd) } if uint32(p) != 0 { t.Errorf("empty path value: got 0x%08x, want 0x00000000", uint32(p)) } // Noun, common: [1, 1, 0, 0, ...] p = MakeTritPath(BranchType, SubField) if p.Depth() != 2 { t.Errorf("noun common depth: got %d, want 2", p.Depth()) } if p.Branch() != BranchType { t.Errorf("noun common branch: got %d, want %d", p.Branch(), BranchType) } if p.Trit(1) != 1 { t.Errorf("noun common trit[1]: got %d, want 1", p.Trit(1)) } // Verb, finite: [2, 1, 0, ...] p = MakeTritPath(BranchFunc, SubField) if p.Branch() != BranchFunc { t.Errorf("verb branch: got %d, want %d", p.Branch(), BranchFunc) } if p.Depth() != 2 { t.Errorf("verb depth: got %d, want 2", p.Depth()) } // Modifier, connective, conjunction: [3, 3, 2, 0, ...] p = MakeTritPath(BranchData, 3, 2) if p.Depth() != 3 { t.Errorf("conjunction depth: got %d, want 3", p.Depth()) } if p.Trit(0) != BranchData { t.Errorf("conjunction trit[0]: got %d, want %d", p.Trit(0), BranchData) } if p.Trit(1) != 3 { t.Errorf("conjunction trit[1]: got %d, want 3", p.Trit(1)) } if p.Trit(2) != 2 { t.Errorf("conjunction trit[2]: got %d, want 2", p.Trit(2)) } } func TestPOSToTritPath(t *testing.T) { tests := []struct { pos POS branch uint8 depth int }{ {POSNoun, BranchType, 2}, {POSProperNoun, BranchType, 2}, {POSPronoun, BranchType, 2}, {POSVerb, BranchFunc, 2}, {POSAuxiliary, BranchFunc, 2}, {POSAdjective, BranchData, 2}, {POSAdverb, BranchData, 2}, {POSPreposition, BranchData, 3}, {POSConjunction, BranchData, 3}, {POSUnknown, TritEnd, 0}, } for _, tt := range tests { p := POSToTritPath(tt.pos) if p.Branch() != tt.branch { t.Errorf("POS %d: branch got %d, want %d", tt.pos, p.Branch(), tt.branch) } if p.Depth() != tt.depth { t.Errorf("POS %d: depth got %d, want %d", tt.pos, p.Depth(), tt.depth) } } } func TestMetaEntryTritPathRoundtrip(t *testing.T) { var m MetaEntry p := MakeTritPath(BranchData, 3, 2) m.SetTritPath(p) got := m.TritPath() if got != p { t.Errorf("roundtrip: got %08x, want %08x", uint32(got), uint32(p)) } } func TestZeroExtraMeansUnassigned(t *testing.T) { var m MetaEntry // zero-initialized p := m.TritPath() if p.Depth() != 0 { t.Errorf("zero Extra depth: got %d, want 0", p.Depth()) } if p.Branch() != TritEnd { t.Errorf("zero Extra branch: got %d, want %d (TritEnd)", p.Branch(), TritEnd) } }