package nmath_test import ( "git.noahlan.cn/noahlan/ntool/nmath" "git.noahlan.cn/noahlan/ntool/ntest/assert" "testing" ) func TestMaxFloat(t *testing.T) { assert.Eq(t, float64(3), nmath.MaxFloat(2, 3)) assert.Eq(t, 3.3, nmath.MaxFloat(2.1, 3.3)) assert.Eq(t, 3.3, nmath.Max(2.1, 3.3)) assert.Eq(t, 3.3, nmath.Max(3.3, 2.1)) assert.Eq(t, 2.1, nmath.Min(2.1, 3.3)) assert.Eq(t, 2.1, nmath.Min(3.3, 2.1)) } func TestMaxI64(t *testing.T) { assert.Eq(t, 3, nmath.MaxInt(2, 3)) assert.Eq(t, 3, nmath.MaxInt(3, 2)) assert.Eq(t, int64(3), nmath.MaxI64(2, 3)) assert.Eq(t, int64(3), nmath.MaxI64(3, 2)) assert.Eq(t, 3, nmath.Max[int](3, 2)) assert.Eq(t, int64(3), nmath.Max[int64](3, 2)) assert.Eq(t, int64(3), nmath.Max(int64(3), int64(2))) } func TestSwapMaxInt(t *testing.T) { x, y := nmath.SwapMax(2, 34) assert.Eq(t, 34, x) assert.Eq(t, 2, y) x, y = nmath.SwapMax(34, 2) assert.Eq(t, 34, x) assert.Eq(t, 2, y) x, y = nmath.SwapMin(2, 34) assert.Eq(t, 2, x) assert.Eq(t, 34, y) x, y = nmath.SwapMin(34, 2) assert.Eq(t, 2, x) assert.Eq(t, 34, y) x, y = nmath.SwapMaxInt(2, 34) assert.Eq(t, 34, x) assert.Eq(t, 2, y) x64, y64 := nmath.SwapMaxI64(2, 34) assert.Eq(t, int64(34), x64) assert.Eq(t, int64(2), y64) } func TestOrElse(t *testing.T) { assert.Eq(t, 23, nmath.OrElse(23, 21)) assert.Eq(t, 21.3, nmath.OrElse[float64](0, 21.3)) }