github.com/insolar/vanilla@v0.0.0-20201023172447-248fdf805322/capacity/capacity_test.go (about)

     1  // Copyright 2020 Insolar Network Ltd.
     2  // All rights reserved.
     3  // This material is licensed under the Insolar License version 1.0,
     4  // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md.
     5  
     6  package capacity
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestDefaultPercent(t *testing.T) {
    15  	require.Equal(t, 20, LevelMinimal.DefaultPercent())
    16  
    17  	require.Panics(t, func() { Level(LevelCount).DefaultPercent() })
    18  }
    19  
    20  func TestChooseInt(t *testing.T) {
    21  	var options [LevelCount]int
    22  	l := LevelMinimal
    23  	options[l] = 5
    24  	require.Equal(t, 5, l.ChooseInt(options))
    25  
    26  	require.Panics(t, func() { Level(LevelCount).ChooseInt(options) })
    27  }
    28  
    29  func TestChooseUint(t *testing.T) {
    30  	require.Equal(t, uint(5), LevelMinimal.ChooseUint([LevelCount]uint{LevelMinimal: 5}))
    31  }
    32  
    33  func TestChooseUint32(t *testing.T) {
    34  	require.Equal(t, uint32(5), LevelMinimal.ChooseUint32([LevelCount]uint32{LevelMinimal: 5}))
    35  }
    36  
    37  func TestChooseUint8(t *testing.T) {
    38  	require.Equal(t, uint8(5), LevelMinimal.ChooseUint8([LevelCount]uint8{LevelMinimal: 5}))
    39  }
    40  
    41  func TestChooseFloat32(t *testing.T) {
    42  	require.Equal(t, float32(5.5), LevelMinimal.ChooseFloat32([LevelCount]float32{LevelMinimal: 5.5}))
    43  }