2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-03-30 02:51:37 +00:00
|
|
|
package lib_test
|
2016-02-12 07:58:48 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2016-03-30 02:51:37 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/lib"
|
2016-02-12 07:58:48 +00:00
|
|
|
)
|
|
|
|
|
2016-03-30 18:47:37 +00:00
|
|
|
func TestMathAbsInt(t *testing.T) {
|
|
|
|
tests := [][3]int{{1, 1}, {-1, 1}, {0, 0}}
|
|
|
|
for _, test := range tests {
|
|
|
|
if test[1] != lib.AbsInt(test[0]) {
|
|
|
|
t.Fatalf("expected %d, got %d", test[1], test[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 07:58:48 +00:00
|
|
|
func TestMathMaxInt(t *testing.T) {
|
|
|
|
tests := [][3]int{{1, 2, 2}, {-1, 1, 1}, {2, 0, 2}}
|
2016-03-30 18:47:37 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
expected := test[2]
|
|
|
|
actual := lib.MaxInt(test[0], test[1])
|
2016-02-12 07:58:48 +00:00
|
|
|
if expected != actual {
|
2016-03-30 18:47:37 +00:00
|
|
|
t.Fatalf("expected %d, got %d", expected, actual)
|
2016-02-12 07:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMathMinInt(t *testing.T) {
|
|
|
|
tests := [][3]int{{1, 2, 1}, {-1, 1, -1}, {2, 0, 0}}
|
2016-03-30 18:47:37 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
expected := test[2]
|
|
|
|
actual := lib.MinInt(test[0], test[1])
|
2016-02-12 07:58:48 +00:00
|
|
|
if expected != actual {
|
2016-03-30 18:47:37 +00:00
|
|
|
t.Fatalf("expected %d, got %d", expected, actual)
|
2016-02-12 07:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-23 23:16:04 +00:00
|
|
|
|
|
|
|
func TestMathMaxUint64(t *testing.T) {
|
|
|
|
tests := [][3]uint64{{1, 2, 2}, {0, 1, 1}, {2, 0, 2}}
|
|
|
|
for _, test := range tests {
|
|
|
|
expected := test[2]
|
|
|
|
actual := lib.MaxUint64(test[0], test[1])
|
|
|
|
if expected != actual {
|
|
|
|
t.Fatalf("expected %d, got %d", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|