2019-01-18 18:36:49 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-17 13:34:57 +00:00
|
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
2022-08-17 16:26:34 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2019-01-18 18:36:49 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFormatRoundedFloat(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2019-01-18 18:36:49 +00:00
|
|
|
cases := []struct {
|
|
|
|
input float64
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
1323,
|
|
|
|
"1323",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
10.321,
|
|
|
|
"10.321",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
100000.31324324,
|
|
|
|
"100000.313",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
100000.3,
|
|
|
|
"100000.3",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0.7654321,
|
|
|
|
"0.765",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
require.Equal(t, c.expected, formatFloat(c.input, 3))
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 16:26:34 +00:00
|
|
|
|
|
|
|
func Test_PointerOf(t *testing.T) {
|
|
|
|
s := "hello"
|
|
|
|
sPtr := pointerOf(s)
|
|
|
|
|
|
|
|
must.Eq(t, s, *sPtr)
|
|
|
|
|
|
|
|
b := "bye"
|
|
|
|
sPtr = &b
|
|
|
|
must.NotEq(t, s, *sPtr)
|
|
|
|
}
|