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

Function TestLen

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

Source from the content-addressed store, hash-verified

134}
135
136func TestLen(t *testing.T) {
137 t.Run("EmptyMapIsZeroLen", func(t *testing.T) {
138 m := orderedmap.NewOrderedMap()
139 assert.Equal(t, 0, m.Len())
140 })
141
142 t.Run("SingleElementIsLenOne", func(t *testing.T) {
143 m := orderedmap.NewOrderedMap()
144 m.Set(123, true)
145 assert.Equal(t, 1, m.Len())
146 })
147
148 t.Run("ThreeElements", func(t *testing.T) {
149 m := orderedmap.NewOrderedMap()
150 m.Set(1, true)
151 m.Set(2, true)
152 m.Set(3, true)
153 assert.Equal(t, 3, m.Len())
154 })
155
156 t.Run("Performance", func(t *testing.T) {
157 if testing.Short() {
158 t.Skip("performance test skipped in short mode")
159 }
160
161 res1 := testing.Benchmark(benchmarkOrderedMap_Len(100))
162 res4 := testing.Benchmark(benchmarkOrderedMap_Len(400))
163
164 // O(1) would mean that res4 should take about the same time as res1,
165 // because we are accessing the same amount of elements, just on
166 // different sized maps.
167
168 assert.InDelta(t,
169 res1.NsPerOp(), res4.NsPerOp(),
170 0.5*float64(res1.NsPerOp()))
171 })
172}
173
174func TestKeys(t *testing.T) {
175 t.Run("EmptyMap", func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

LenMethod · 0.95
SetMethod · 0.95
NewOrderedMapFunction · 0.92
benchmarkOrderedMap_LenFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…