MCPcopy
hub / github.com/google/mangle / TestInclusionCheck

Function TestInclusionCheck

engine/inclusioncheck_test.go:25–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestInclusionCheck(t *testing.T) {
26 store := factstore.NewSimpleInMemoryStore()
27
28 for i := 0; i < 255; i++ {
29 store.Add(atom(fmt.Sprintf("range(%d)", i)))
30 }
31 store.Add(atom("color(1,2,3)"))
32 store.Add(atom("color(123,243,33)"))
33 store.Add(atom("color(13,23,33)"))
34
35 rangeDecl, err := ast.NewDecl(
36 ast.NewAtom("range", ast.Variable{"N"}),
37 nil,
38 []ast.BoundDecl{
39 ast.NewBoundDecl(ast.NumberBound)}, nil)
40 if err != nil {
41 t.Fatal(err)
42 }
43 colorDecl, err := ast.NewDecl(
44 ast.NewAtom("color", ast.Variable{"R"}, ast.Variable{"G"}, ast.Variable{"B"}),
45 nil,
46 []ast.BoundDecl{
47 ast.NewBoundDecl(ast.String("range"), ast.String("range"), ast.String("range"))}, nil)
48 if err != nil {
49 t.Fatal(err)
50 }
51 paletteDecl, err := ast.NewDecl(
52 ast.NewAtom("palette", ast.Variable{"Name"}, ast.Variable{"R"}, ast.Variable{"G"}, ast.Variable{"B"}),
53 nil,
54 []ast.BoundDecl{
55 ast.NewBoundDecl(ast.StringBound, ast.NumberBound, ast.NumberBound, ast.NumberBound)},
56 &ast.InclusionConstraint{[]ast.Atom{
57 ast.NewAtom("color", ast.Variable{"R"}, ast.Variable{"G"}, ast.Variable{"B"})}, nil})
58 if err != nil {
59 t.Fatal(err)
60 }
61 decl := map[ast.PredicateSym]ast.Decl{
62 ast.PredicateSym{"palette", 4}: paletteDecl,
63 ast.PredicateSym{"color", 3}: colorDecl,
64 ast.PredicateSym{"range", 1}: rangeDecl,
65 }
66
67 checker, err := NewInclusionChecker(decl)
68 if err != nil {
69 t.Fatal(err)
70 }
71 badColor := atom("color(999,99,99)")
72 if err = checker.CheckFact(badColor, store); err == nil { // if NO error
73 t.Errorf("CheckFact(%v) succeeded, expected error %v", badColor, store)
74 }
75 okFact := atom("palette('kind of blue', 13, 23, 33)")
76 if err = checker.CheckFact(okFact, store); err != nil {
77 t.Errorf("CheckFact(%v) failed %v", okFact, err)
78 }
79 badFact := atom("palette('kind of black', 0, 0, 0)")
80 if err = checker.CheckFact(badFact, store); err == nil { // if NO error
81 t.Errorf("CheckFact(%v) succeeded, expected error %v", badFact, store)
82 }

Callers

nothing calls this directly

Calls 9

AddMethod · 0.95
CheckFactMethod · 0.95
NewSimpleInMemoryStoreFunction · 0.92
NewDeclFunction · 0.92
NewAtomFunction · 0.92
NewBoundDeclFunction · 0.92
StringFunction · 0.92
NewInclusionCheckerFunction · 0.85
atomFunction · 0.70

Tested by

no test coverage detected