github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/util/util_test.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package util 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 ) 24 25 func TestGetSortedKeys(t *testing.T) { 26 mapKeyValue := make(map[string]int) 27 mapKeyValue["blue"] = 10 28 mapKeyValue["apple"] = 15 29 mapKeyValue["red"] = 12 30 mapKeyValue["123"] = 22 31 mapKeyValue["a"] = 33 32 mapKeyValue[""] = 30 33 assert.Equal(t, []string{"", "123", "a", "apple", "blue", "red"}, GetSortedKeys(mapKeyValue)) 34 } 35 36 func TestGetValuesBySortedKeys(t *testing.T) { 37 type name struct { 38 fName string 39 lName string 40 } 41 mapKeyValue := make(map[string]*name) 42 mapKeyValue["2"] = &name{"Two", "two"} 43 mapKeyValue["3"] = &name{"Three", "three"} 44 mapKeyValue["5"] = &name{"Five", "five"} 45 mapKeyValue[""] = &name{"None", "none"} 46 47 sortedRes := []*name{} 48 GetValuesBySortedKeys(&mapKeyValue, &sortedRes) 49 assert.Equal( 50 t, 51 []*name{{"None", "none"}, {"Two", "two"}, {"Three", "three"}, {"Five", "five"}}, 52 sortedRes, 53 ) 54 }