MCPcopy Create free account
hub / github.com/google/gapid / TestDictionary

Function TestDictionary

core/data/dictionary/dictionary_test.go:54–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestDictionary(t *testing.T) {
55 ctx := log.Testing(t)
56
57 assert.For(ctx, "dictionary.From(nil)").That(dictionary.From(nil)).Equals(nil)
58
59 apple := keyTy("apple")
60 orange := keyTy("orange")
61 grape := keyTy("grape")
62 kiwi := keyTy("kiwi")
63 lemon := keyTy("lemon")
64 banana := keyTy("banana")
65
66 one := valTy(1)
67 two := valTy(2)
68 three := valTy(3)
69 four := valTy(4)
70 five := valTy(5)
71
72 newMap := func() map[keyTy]valTy {
73 return map[keyTy]valTy{
74 apple: one,
75 orange: two,
76 grape: three,
77 kiwi: four,
78 lemon: five,
79 }
80 }
81 newCustom := func() custom { m := newMap(); return custom{&m} }
82
83 for _, test := range []struct {
84 name string
85 source interface{}
86 }{
87 {"map", newMap()},
88 {"custom", newCustom()},
89 } {
90 ctx := log.Enter(ctx, test.name)
91
92 d := dictionary.From(test.source)
93
94 if !assert.For(ctx, "d").That(d).IsNotNil() {
95 continue
96 }
97
98 assert.For(ctx, "d.Get('apple')").That(d.Get(apple)).Equals(one)
99 assert.For(ctx, "d.Get('grape')").That(d.Get(grape)).Equals(three)
100 assert.For(ctx, "d.KeyTy()").That(d.KeyTy()).Equals(reflect.TypeOf(apple))
101 assert.For(ctx, "d.ValTy()").That(d.ValTy()).Equals(reflect.TypeOf(one))
102 assert.For(ctx, "d.Len()").That(d.Len()).Equals(5)
103 assert.For(ctx, "d.Keys()").ThatSlice(d.Keys()).Equals([]keyTy{
104 apple, grape, kiwi, lemon, orange,
105 })
106
107 val, ok := d.Lookup(banana)
108 assert.For(ctx, "d.Get('banana').val").That(val).Equals(valTy(0))
109 assert.For(ctx, "d.Get('banana').ok").That(ok).Equals(false)
110 assert.For(ctx, "d.Contains('banana')").That(d.Contains(banana)).Equals(false)
111

Callers

nothing calls this directly

Calls 15

keyTyTypeAlias · 0.85
valTyTypeAlias · 0.85
ThatMethod · 0.80
ForMethod · 0.80
IsNotNilMethod · 0.80
ThatSliceMethod · 0.80
EntriesMethod · 0.80
EqualsMethod · 0.65
GetMethod · 0.65
KeyTyMethod · 0.65
ValTyMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected