Added FirstIntNonEmpty and FirstDurationNonEmpty functions in utils

This commit is contained in:
nickolasdaniel
2021-07-15 16:52:50 +03:00
committed by Dan Christian Bogos
parent aa6951eef8
commit 2e30aac220
2 changed files with 69 additions and 0 deletions

View File

@@ -57,6 +57,57 @@ func TestFirstNonEmpty(t *testing.T) {
}
}
func TestFirstIntNonEmpty(t *testing.T) {
//check for default value
rcv := FirstIntNonEmpty(0)
if rcv != 0 {
t.Errorf("Expected 0 \n but received \n %d", rcv)
}
//case the first non empty value is on the first position
rcv = FirstIntNonEmpty(21, 0, 0)
if rcv != 21 {
t.Errorf("Expected 21 \n but received \n %d", rcv)
}
//case the first non empty value is on the second position
rcv = FirstIntNonEmpty(0, 21, 0)
if rcv != 21 {
t.Errorf("Expected 21 \n but received \n %d", rcv)
}
//case the first non empty value is on the third position
rcv = FirstIntNonEmpty(0, 0, 21)
if rcv != 21 {
t.Errorf("Expected 21 \n but received \n %d", rcv)
}
}
func TestFirstDurationNonEmpty(t *testing.T) {
//check for default value
rcv := FirstDurationNonEmpty(0)
if rcv != 0 {
t.Errorf("Expected 0 \n but received \n %d", rcv)
}
//case the first non empty value is on the first position
rcv = FirstDurationNonEmpty(2*time.Minute, 0, 0)
if rcv != 2*time.Minute {
t.Errorf("Expected 2m \n but received \n %d", rcv)
}
//case the first non empty value is on the second position
rcv = FirstDurationNonEmpty(0, 2*time.Minute, 0)
if rcv != 2*time.Minute {
t.Errorf("Expected 2m \n but received \n %d", rcv)
}
//case the first non empty value is on the third position
rcv = FirstDurationNonEmpty(0, 0, 2*time.Minute)
if rcv != 2*time.Minute {
t.Errorf("Expected 2m \n but received \n %d", rcv)
}
}
func TestSha1(t *testing.T) {
//empty check
rcv := Sha1(" ")