2024-07-27 14:15:25 +08:00
|
|
|
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
|
2022-08-13 23:55:48 +08:00
|
|
|
|
|
|
|
|
package numberutils_test
|
|
|
|
|
|
|
|
|
|
import (
|
2022-10-14 10:03:29 +08:00
|
|
|
"math"
|
2022-08-13 23:55:48 +08:00
|
|
|
"testing"
|
2024-07-27 14:15:25 +08:00
|
|
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
2022-08-13 23:55:48 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMax(t *testing.T) {
|
|
|
|
|
t.Log(numberutils.Max[int](1, 2, 3))
|
|
|
|
|
t.Log(numberutils.Max[int32](1, 2, 3))
|
|
|
|
|
t.Log(numberutils.Max[float32](1.2, 2.3, 3.4))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMin(t *testing.T) {
|
|
|
|
|
t.Log(numberutils.Min[int](1, 2, 3))
|
|
|
|
|
t.Log(numberutils.Min[int32](1, 2, 3))
|
|
|
|
|
t.Log(numberutils.Min[float32](1.2, 2.3, 3.4))
|
|
|
|
|
}
|
2022-10-14 10:03:29 +08:00
|
|
|
|
|
|
|
|
func TestMaxFloat32(t *testing.T) {
|
|
|
|
|
t.Logf("%f", math.MaxFloat32/(1<<100))
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 11:54:00 +08:00
|
|
|
func TestFloorFloat64(t *testing.T) {
|
|
|
|
|
t.Logf("%f", numberutils.FloorFloat64(123.456, -1))
|
|
|
|
|
t.Logf("%f", numberutils.FloorFloat64(123.456, 0))
|
|
|
|
|
t.Logf("%f", numberutils.FloorFloat64(123, 2))
|
|
|
|
|
t.Logf("%f, %f", numberutils.FloorFloat64(123.456, 1), 123.456*10)
|
|
|
|
|
t.Logf("%f, %f", numberutils.FloorFloat64(123.456, 2), 123.456*10*10)
|
|
|
|
|
t.Logf("%f, %f", numberutils.FloorFloat64(123.456, 3), 123.456*10*10*10)
|
|
|
|
|
t.Logf("%f, %f", numberutils.FloorFloat64(123.456, 4), 123.456*10*10*10*10)
|
|
|
|
|
t.Logf("%f, %f", numberutils.FloorFloat64(123.456789, 4), 123.456789*10*10*10*10)
|
|
|
|
|
t.Logf("%f", numberutils.FloorFloat64(-123.45678, 2))
|
2022-10-14 10:03:29 +08:00
|
|
|
}
|
2022-10-23 09:25:20 +08:00
|
|
|
|
2022-10-23 11:54:00 +08:00
|
|
|
func TestFloorFloat64_Special(t *testing.T) {
|
|
|
|
|
for _, f := range []float64{17.88, 1.11, 1.23456} {
|
|
|
|
|
t.Logf("%f", numberutils.FloorFloat64(f, 2))
|
2022-10-23 09:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|