feat(numx): 自 go-hua/common 迁入数值工具并独立成包
- 流量格式化、低位取整、多整数取最值(Max/Min 自 version.go 归位) - 附单元测试、examples/numx 例程与包 README
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package numx
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFormatFlow(t *testing.T) {
|
||||
cases := []struct {
|
||||
in int64
|
||||
want string
|
||||
}{
|
||||
{500, "500 B"},
|
||||
{1536, "1.5 KB"},
|
||||
{1024 * 1024, "1.0 MB"},
|
||||
{1024 * 1024 * 1024, "1.0 GB"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := FormatFlow(c.in); got != c.want {
|
||||
t.Errorf("FormatFlow(%d) = %q, want %q", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoreDigits(t *testing.T) {
|
||||
if got := IgnoreDigits(12345, 3); got != 12000 {
|
||||
t.Errorf("IgnoreDigits(12345,3) = %d, want 12000", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxMin(t *testing.T) {
|
||||
if got := Max(3, 7, 5); got != 7 {
|
||||
t.Errorf("Max = %d, want 7", got)
|
||||
}
|
||||
if got := Min(3, 1, 2); got != 1 {
|
||||
t.Errorf("Min = %d, want 1", got)
|
||||
}
|
||||
if got := Min(2, 5); got != 2 {
|
||||
t.Errorf("Min(2,5) = %d, want 2", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user