github.com/cilium/cilium@v1.16.2/pkg/math/int_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package math
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  const (
    13  	maxIntValue = int(^uint(0) >> 1)
    14  	minIntValue = -maxIntValue - 1
    15  )
    16  
    17  func TestIntMin(t *testing.T) {
    18  	require.Equal(t, IntMin(10, 20), 10)
    19  	require.Equal(t, IntMin(20, 10), 10)
    20  	require.Equal(t, IntMin(10, 10), 10)
    21  	require.Equal(t, IntMin(-10, 10), -10)
    22  	require.Equal(t, IntMin(0, 10), 0)
    23  	require.Equal(t, IntMin(minIntValue, maxIntValue), minIntValue)
    24  }
    25  
    26  func TestIntMax(t *testing.T) {
    27  	require.Equal(t, IntMax(10, 20), 20)
    28  	require.Equal(t, IntMax(20, 10), 20)
    29  	require.Equal(t, IntMax(10, 10), 10)
    30  	require.Equal(t, IntMax(-10, 10), 10)
    31  	require.Equal(t, IntMax(0, 10), 10)
    32  	require.Equal(t, IntMax(minIntValue, maxIntValue), maxIntValue)
    33  }