github.com/matrixorigin/matrixone@v0.7.0/pkg/hakeeper/task/cn_ordered_map_test.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package task 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestOrderedMap(t *testing.T) { 24 orderedMap := newOrderedMap(nil) 25 orderedMap.set("a", 100) 26 orderedMap.set("b", 110) 27 orderedMap.set("c", 90) 28 orderedMap.set("d", 80) 29 orderedMap.set("e", 120) 30 orderedMap.set("f", 50) 31 assert.Equal(t, 6, len(orderedMap.m)) 32 assert.True(t, len(orderedMap.m) == len(orderedMap.orderedKeys)) 33 assert.Equal(t, "f", orderedMap.min()) 34 35 orderedMap.set("f", 150) 36 assert.Equal(t, "d", orderedMap.min()) 37 38 orderedMap.set("b", 70) 39 assert.Equal(t, "b", orderedMap.min()) 40 41 orderedMap.set("b", 100) 42 for i := 0; i < 100; i++ { 43 orderedMap.inc("g") 44 assert.Equal(t, uint32(i+1), orderedMap.get("g")) 45 } 46 assert.Equal(t, "d", orderedMap.min()) 47 assert.Equal(t, 7, len(orderedMap.m)) 48 assert.True(t, len(orderedMap.m) == len(orderedMap.orderedKeys)) 49 }