-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
107 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fmtutil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gookit/goutil/fmtutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDataSize(t *testing.T) { | ||
tests := []struct { | ||
args uint64 | ||
want string | ||
}{ | ||
{346, "346B"}, | ||
{3467, "3.39K"}, | ||
{346778, "338.65K"}, | ||
{1200346778, "1.12G"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
assert.Equal(t, tt.want, fmtutil.DataSize(tt.args)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fmtutil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gookit/goutil/fmtutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHowLongAgo(t *testing.T) { | ||
tests := []struct { | ||
args int64 | ||
want string | ||
}{ | ||
{-36, "unknown"}, | ||
{36, "36 secs"}, | ||
{346, "5 mins"}, | ||
{3467, "57 mins"}, | ||
{346778, "4 days"}, | ||
{1200346778, "13892 days"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
assert.Equal(t, tt.want, fmtutil.HowLongAgo(tt.args)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package maputil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gookit/goutil/maputil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMergeStringMap(t *testing.T) { | ||
ret := maputil.MergeStringMap(map[string]string{"A": "v0"}, map[string]string{"A": "v1"}, false) | ||
assert.Equal(t, map[string]string{"A": "v0"}, ret) | ||
|
||
ret = maputil.MergeStringMap(map[string]string{"A": "v0"}, map[string]string{"a": "v1"}, true) | ||
assert.Equal(t, map[string]string{"a": "v0"}, ret) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package mathutil_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/gookit/goutil/mathutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPercent(t *testing.T) { | ||
assert.Equal(t, float64(34), mathutil.Percent(34, 100)) | ||
assert.Equal(t, float64(0), mathutil.Percent(34, 0)) | ||
assert.Equal(t, float64(-100), mathutil.Percent(34, -34)) | ||
} | ||
|
||
func TestElapsedTime(t *testing.T) { | ||
ct := time.Now() | ||
time.Sleep(time.Second * 1) | ||
assert.Contains(t, mathutil.ElapsedTime(ct), "100") | ||
} | ||
|
||
func TestDataSize(t *testing.T) { | ||
assert.Equal(t, "3.38K", mathutil.DataSize(3456)) | ||
} | ||
|
||
func TestHowLongAgo(t *testing.T) { | ||
assert.Equal(t, "57 mins", mathutil.HowLongAgo(3456)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters