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

Function TestHash

ast/ast_test.go:214–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

212}
213
214func TestHash(t *testing.T) {
215 tests := []struct {
216 c Constant
217 want uint64
218 }{
219 {
220 c: fooName,
221 want: hashBytes([]byte("/foo")),
222 },
223 {
224 c: barString,
225 want: hashBytes([]byte(`bar`)),
226 },
227 {
228 c: Number(num),
229 want: uint64(num),
230 },
231 {
232 c: floatNumConstant,
233 want: math.Float64bits(floatNum),
234 },
235 {
236 c: fooBarPair,
237 want: uint64(hashPair(&fooName, &barString, PairShape)),
238 },
239 {
240 c: List([]Constant{fooName}),
241 want: uint64(hashPair(&fooName, &ListNil, ListShape)),
242 },
243 {
244 c: MapCons(&fooName, &barString, &MapNil),
245 want: uint64(hashPair(&fooBarPair, &MapNil, MapShape)),
246 },
247 {
248 c: StructCons(&fooName, &barString, &StructNil),
249 want: uint64(hashPair(&fooBarPair, &StructNil, StructShape)),
250 },
251 }
252 for _, test := range tests {
253 if got := test.c.Hash(); got != test.want {
254 t.Errorf("(%v).Hash() expected %v got %v", test.c, test.want, got)
255 }
256 }
257}
258
259func TestAtomHash(t *testing.T) {
260 a := NewAtom("bar", String("foo"))

Callers

nothing calls this directly

Calls 7

hashBytesFunction · 0.85
NumberFunction · 0.85
hashPairFunction · 0.85
ListFunction · 0.85
MapConsFunction · 0.85
StructConsFunction · 0.85
HashMethod · 0.65

Tested by

no test coverage detected