github.com/rposudnevskiy/consul@v1.4.5/lib/math_test.go (about)

     1  package lib_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/consul/lib"
     7  )
     8  
     9  func TestMathAbsInt(t *testing.T) {
    10  	tests := [][3]int{{1, 1}, {-1, 1}, {0, 0}}
    11  	for _, test := range tests {
    12  		if test[1] != lib.AbsInt(test[0]) {
    13  			t.Fatalf("expected %d, got %d", test[1], test[0])
    14  		}
    15  	}
    16  }
    17  
    18  func TestMathMaxInt(t *testing.T) {
    19  	tests := [][3]int{{1, 2, 2}, {-1, 1, 1}, {2, 0, 2}}
    20  	for _, test := range tests {
    21  		expected := test[2]
    22  		actual := lib.MaxInt(test[0], test[1])
    23  		if expected != actual {
    24  			t.Fatalf("expected %d, got %d", expected, actual)
    25  		}
    26  	}
    27  }
    28  
    29  func TestMathMinInt(t *testing.T) {
    30  	tests := [][3]int{{1, 2, 1}, {-1, 1, -1}, {2, 0, 0}}
    31  	for _, test := range tests {
    32  		expected := test[2]
    33  		actual := lib.MinInt(test[0], test[1])
    34  		if expected != actual {
    35  			t.Fatalf("expected %d, got %d", expected, actual)
    36  		}
    37  	}
    38  }