MCPcopy Create free account
hub / github.com/elliotchance/orderedmap / TestGet

Function TestGet

orderedmap_test.go:17–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15}
16
17func TestGet(t *testing.T) {
18 t.Run("ReturnsNotOKIfStringKeyDoesntExist", func(t *testing.T) {
19 m := orderedmap.NewOrderedMap()
20 _, ok := m.Get("foo")
21 assert.False(t, ok)
22 })
23
24 t.Run("ReturnsNotOKIfNonStringKeyDoesntExist", func(t *testing.T) {
25 m := orderedmap.NewOrderedMap()
26 _, ok := m.Get(123)
27 assert.False(t, ok)
28 })
29
30 t.Run("ReturnsOKIfKeyExists", func(t *testing.T) {
31 m := orderedmap.NewOrderedMap()
32 m.Set("foo", "bar")
33 _, ok := m.Get("foo")
34 assert.True(t, ok)
35 })
36
37 t.Run("ReturnsValueForKey", func(t *testing.T) {
38 m := orderedmap.NewOrderedMap()
39 m.Set("foo", "bar")
40 value, _ := m.Get("foo")
41 assert.Equal(t, "bar", value)
42 })
43
44 t.Run("ReturnsDynamicValueForKey", func(t *testing.T) {
45 m := orderedmap.NewOrderedMap()
46 m.Set("foo", "baz")
47 value, _ := m.Get("foo")
48 assert.Equal(t, "baz", value)
49 })
50
51 t.Run("KeyDoesntExistOnNonEmptyMap", func(t *testing.T) {
52 m := orderedmap.NewOrderedMap()
53 m.Set("foo", "baz")
54 _, ok := m.Get("bar")
55 assert.False(t, ok)
56 })
57
58 t.Run("ValueForKeyDoesntExistOnNonEmptyMap", func(t *testing.T) {
59 m := orderedmap.NewOrderedMap()
60 m.Set("foo", "baz")
61 value, _ := m.Get("bar")
62 assert.Nil(t, value)
63 })
64
65 t.Run("Performance", func(t *testing.T) {
66 if testing.Short() {
67 t.Skip("performance test skipped in short mode")
68 }
69
70 res1 := testing.Benchmark(benchmarkOrderedMap_Get(100))
71 res4 := testing.Benchmark(benchmarkOrderedMap_Get(400))
72
73 // O(1) would mean that res4 should take about the same time as res1,
74 // because we are accessing the same amount of elements, just on

Callers

nothing calls this directly

Calls 4

GetMethod · 0.95
SetMethod · 0.95
NewOrderedMapFunction · 0.92
benchmarkOrderedMap_GetFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…