🚧 Add utils.HourMinSecToSeconds func
This commit is contained in:
parent
5472d7376a
commit
a706d16c5a
2 changed files with 44 additions and 0 deletions
30
utils/utils_hms_test.go
Normal file
30
utils/utils_hms_test.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
func hmsTest(t *testing.T, time string, expected float64) {
|
||||
found := HourMinSecToSeconds(time)
|
||||
if found != expected {
|
||||
t.Fatalf(`HourMinSecToSeconds("%s") = %v, want %v`, time, found, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJustSeconds(t *testing.T) {
|
||||
hmsTest(t, "4.23", 4.23)
|
||||
}
|
||||
|
||||
func TestMinuteSeconds(t *testing.T) {
|
||||
hmsTest(t, "2:3.45", 123.45)
|
||||
}
|
||||
|
||||
func TestHourMinuteSeconds(t *testing.T) {
|
||||
hmsTest(t, "3:5:12.43", 11112.43)
|
||||
}
|
||||
|
||||
func TestLeadingZeros(t *testing.T) {
|
||||
hmsTest(t, "03:05:02.43", 11102.43)
|
||||
}
|
||||
|
||||
func TestWholeSecond(t *testing.T) {
|
||||
hmsTest(t, "4:2", 242)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue