1
0
mirror of https://github.com/ManyakRus/starter.git synced 2024-11-24 08:52:34 +02:00

сделал IntNot0()

This commit is contained in:
Nikitin Aleksandr 2024-11-18 13:27:46 +03:00
parent ce9c53ba0d
commit 17dc9ee496
2 changed files with 34 additions and 0 deletions

View File

@ -1230,3 +1230,17 @@ func Substring(input string, StartIndex int, length int) string {
return string(asRunes[StartIndex : StartIndex+length]) return string(asRunes[StartIndex : StartIndex+length])
} }
// IntNot0 - возвращает первое ненулевое значение
func IntNot0(MassInt ...int) int {
Otvet := 0
for _, v := range MassInt {
if v != 0 {
Otvet = v
break
}
}
return Otvet
}

View File

@ -1228,3 +1228,23 @@ func TestSubstring(t *testing.T) {
} }
} }
} }
func TestIntNot0(t *testing.T) {
// Testing when all input integers are 0
result1 := IntNot0(0, 0, 0)
if result1 != 0 {
t.Errorf("Expected 0, but got %d", result1)
}
// Testing when some input integers are 0 and some are non-zero
result2 := IntNot0(0, 5, 0, 10)
if result2 != 5 {
t.Errorf("Expected 5, but got %d", result2)
}
// Testing when all input integers are non-zero
result3 := IntNot0(3, 7, 2)
if result3 != 3 {
t.Errorf("Expected 3, but got %d", result3)
}
}