github.com/dusk-network/dusk-crypto@v0.1.3/hash/hash_test.go (about)

     1  package hash
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func randomMessage(size int) []byte {
    11  	msg := make([]byte, size)
    12  	_, _ = rand.Read(msg)
    13  	return msg
    14  }
    15  
    16  func BenchmarkXxhash(b *testing.B) {
    17  
    18  	testBytes := randomMessage(32)
    19  
    20  	for i := 0; i < b.N; i++ {
    21  		_, _ = Xxhash(testBytes)
    22  	}
    23  }
    24  
    25  func BenchmarkSha3(b *testing.B) {
    26  
    27  	testBytes := randomMessage(32)
    28  
    29  	for i := 0; i < b.N; i++ {
    30  		_, _ = Sha3256(testBytes)
    31  	}
    32  }
    33  
    34  func TestRandEntropy(t *testing.T) {
    35  
    36  	for i := 0; i < 100; i++ {
    37  		n := uint32(rand.Intn(1e3))
    38  		en, err := RandEntropy(n)
    39  
    40  		assert.Equal(t, nil, err)
    41  		assert.Equal(t, uint32(len(en)), uint32(n))
    42  
    43  	}
    44  }