github.com/blend/go-sdk@v1.20220411.3/consistenthash/insertion_sort_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package consistenthash
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func Test_insertionSort(t *testing.T) {
    17  	its := assert.New(t)
    18  
    19  	ring := []HashedBucket{}
    20  	ring = InsertionSort(ring, HashedBucket{Hashcode: 3})
    21  	ring = InsertionSort(ring, HashedBucket{Hashcode: 1})
    22  	ring = InsertionSort(ring, HashedBucket{Hashcode: 4})
    23  	ring = InsertionSort(ring, HashedBucket{Hashcode: 2})
    24  	ring = InsertionSort(ring, HashedBucket{Hashcode: 0})
    25  	ring = InsertionSort(ring, HashedBucket{Hashcode: 5})
    26  
    27  	its.Len(ring, 6)
    28  
    29  	its.Equal(0, ring[0].Hashcode)
    30  	its.Equal(1, ring[1].Hashcode)
    31  	its.Equal(2, ring[2].Hashcode)
    32  	its.Equal(3, ring[3].Hashcode)
    33  	its.Equal(4, ring[4].Hashcode)
    34  	its.Equal(5, ring[5].Hashcode)
    35  }