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

Function TestUnifyExtendPositive

unionfind/unionfind_test.go:123–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestUnifyExtendPositive(t *testing.T) {
124 tests := []struct {
125 name string
126 // The substitution that will be extended.
127 base map[ast.Variable]ast.BaseTerm
128 left []ast.BaseTerm
129 right []ast.BaseTerm
130 // Bindings that we want to see in the result.
131 want map[ast.Variable]ast.BaseTerm
132 }{
133 {
134 name: "unify X = Y extending empty subst",
135 base: map[ast.Variable]ast.BaseTerm{},
136 left: []ast.BaseTerm{term("X")},
137 right: []ast.BaseTerm{term("Y")},
138 want: map[ast.Variable]ast.BaseTerm{
139 ast.Variable{"X"}: term("Y"),
140 ast.Variable{"Y"}: term("Y"),
141 },
142 },
143 {
144 name: "unify X = Y where X is already bound",
145 base: map[ast.Variable]ast.BaseTerm{
146 ast.Variable{"X"}: term("/c"),
147 },
148 left: []ast.BaseTerm{term("X")},
149 right: []ast.BaseTerm{term("Y")},
150 want: map[ast.Variable]ast.BaseTerm{
151 ast.Variable{"X"}: term("/c"),
152 ast.Variable{"Y"}: term("/c"),
153 },
154 },
155 {
156 name: "unify X = Y where both X and Y were bound",
157 base: map[ast.Variable]ast.BaseTerm{
158 ast.Variable{"X"}: term("/c"),
159 ast.Variable{"Y"}: term("X"),
160 },
161 left: []ast.BaseTerm{term("X")},
162 right: []ast.BaseTerm{term("Y")},
163 want: map[ast.Variable]ast.BaseTerm{
164 ast.Variable{"X"}: term("/c"),
165 ast.Variable{"Y"}: term("/c"),
166 },
167 },
168 {
169 name: "unify X = Y where both X and Y were unified before",
170 base: map[ast.Variable]ast.BaseTerm{
171 ast.Variable{"X"}: term("Z"),
172 ast.Variable{"Y"}: term("Z"),
173 },
174 left: []ast.BaseTerm{term("X")},
175 right: []ast.BaseTerm{term("/c")},
176 want: map[ast.Variable]ast.BaseTerm{
177 ast.Variable{"X"}: term("/c"),
178 ast.Variable{"Y"}: term("/c"),
179 ast.Variable{"Z"}: term("/c"),
180 },

Callers

nothing calls this directly

Calls 4

termFunction · 0.85
unionFindFromMapFunction · 0.85
UnifyTermsExtendFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected