github.com/attic-labs/noms@v0.0.0-20210827224422-e5fa29d95e8b/go/hash/hash_slice_test.go (about)

     1  // Copyright 2016 Attic Labs, Inc. All rights reserved.
     2  // Licensed under the Apache License, version 2.0:
     3  // http://www.apache.org/licenses/LICENSE-2.0
     4  
     5  package hash
     6  
     7  import (
     8  	"sort"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestHashSliceSort(t *testing.T) {
    15  	assert := assert.New(t)
    16  
    17  	rs := HashSlice{}
    18  	for i := 1; i <= 3; i++ {
    19  		for j := 1; j <= 3; j++ {
    20  			h := Hash{}
    21  			for k := 1; k <= j; k++ {
    22  				h[k-1] = byte(i)
    23  			}
    24  			rs = append(rs, h)
    25  		}
    26  	}
    27  
    28  	rs2 := HashSlice(make([]Hash, len(rs)))
    29  	copy(rs2, rs)
    30  	sort.Sort(sort.Reverse(rs2))
    31  	assert.False(rs.Equals(rs2))
    32  
    33  	sort.Sort(rs2)
    34  	assert.True(rs.Equals(rs2))
    35  }