mirror of
https://github.com/ManyakRus/starter.git
synced 2024-11-28 09:33:45 +02:00
сделал IntNot0()
This commit is contained in:
parent
ce9c53ba0d
commit
17dc9ee496
@ -1230,3 +1230,17 @@ func Substring(input string, StartIndex int, length int) string {
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user