(t *testing.T)
| 81 | } |
| 82 | |
| 83 | func TestSet(t *testing.T) { |
| 84 | t.Run("ReturnsTrueIfStringKeyIsNew", func(t *testing.T) { |
| 85 | m := orderedmap.NewOrderedMap() |
| 86 | ok := m.Set("foo", "bar") |
| 87 | assert.True(t, ok) |
| 88 | }) |
| 89 | |
| 90 | t.Run("ReturnsTrueIfNonStringKeyIsNew", func(t *testing.T) { |
| 91 | m := orderedmap.NewOrderedMap() |
| 92 | ok := m.Set(123, "bar") |
| 93 | assert.True(t, ok) |
| 94 | }) |
| 95 | |
| 96 | t.Run("ValueCanBeNonString", func(t *testing.T) { |
| 97 | m := orderedmap.NewOrderedMap() |
| 98 | ok := m.Set(123, true) |
| 99 | assert.True(t, ok) |
| 100 | }) |
| 101 | |
| 102 | t.Run("ReturnsFalseIfKeyIsNotNew", func(t *testing.T) { |
| 103 | m := orderedmap.NewOrderedMap() |
| 104 | m.Set("foo", "bar") |
| 105 | ok := m.Set("foo", "bar") |
| 106 | assert.False(t, ok) |
| 107 | }) |
| 108 | |
| 109 | t.Run("SetThreeDifferentKeys", func(t *testing.T) { |
| 110 | m := orderedmap.NewOrderedMap() |
| 111 | m.Set("foo", "bar") |
| 112 | m.Set("baz", "qux") |
| 113 | ok := m.Set("quux", "corge") |
| 114 | assert.True(t, ok) |
| 115 | }) |
| 116 | |
| 117 | t.Run("Performance", func(t *testing.T) { |
| 118 | if testing.Short() { |
| 119 | t.Skip("performance test skipped in short mode") |
| 120 | } |
| 121 | |
| 122 | res1 := testing.Benchmark(benchmarkOrderedMap_Set(100)) |
| 123 | res4 := testing.Benchmark(benchmarkOrderedMap_Set(400)) |
| 124 | |
| 125 | // O(1) would mean that res4 should take about 4 times longer than res1 |
| 126 | // because we are doing 4 times the amount of Set operations. Allow for |
| 127 | // a wide margin, but not too wide that it would permit the inflection |
| 128 | // to O(n^2). |
| 129 | |
| 130 | assert.InDelta(t, |
| 131 | 4*res1.NsPerOp(), res4.NsPerOp(), |
| 132 | 2*float64(res1.NsPerOp())) |
| 133 | }) |
| 134 | } |
| 135 | |
| 136 | func TestLen(t *testing.T) { |
| 137 | t.Run("EmptyMapIsZeroLen", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…