You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
836 B
Go
37 lines
836 B
Go
package nmath_test
|
|
|
|
import (
|
|
"git.noahlan.cn/noahlan/ntool/ngo"
|
|
"git.noahlan.cn/noahlan/ntool/nmath"
|
|
"git.noahlan.cn/noahlan/ntool/ntest/assert"
|
|
"git.noahlan.cn/noahlan/ntool/ntime"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestIsNumeric(t *testing.T) {
|
|
assert.True(t, nmath.IsNumeric('3'))
|
|
assert.False(t, nmath.IsNumeric('a'))
|
|
}
|
|
|
|
func TestPercent(t *testing.T) {
|
|
assert.Eq(t, float64(34), nmath.Percent(34, 100))
|
|
assert.Eq(t, float64(0), nmath.Percent(34, 0))
|
|
assert.Eq(t, float64(-100), nmath.Percent(34, -34))
|
|
}
|
|
|
|
func TestElapsedTime(t *testing.T) {
|
|
nt := time.Now().Add(-time.Second * 3)
|
|
num := ntime.ElapsedTime(nt)
|
|
|
|
assert.Eq(t, 3000, int(nmath.MustFloat(num)))
|
|
}
|
|
|
|
func TestDataSize(t *testing.T) {
|
|
assert.Eq(t, "3.38K", ngo.DataSize(3456))
|
|
}
|
|
|
|
func TestHowLongAgo(t *testing.T) {
|
|
assert.Eq(t, "57 mins", ntime.HowLongAgo(3456))
|
|
}
|