mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-29 23:38:14 +02:00
сделал IsInt()
This commit is contained in:
@@ -961,3 +961,20 @@ func StringFromMassInt64(A []int64, delim string) string {
|
|||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsInt - проверяет, является ли строка целым числом
|
||||||
|
func IsInt(s string) bool {
|
||||||
|
Otvet := false
|
||||||
|
if s == "" {
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range s {
|
||||||
|
if !unicode.IsDigit(c) {
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = true
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|||||||
@@ -853,3 +853,23 @@ func TestStringFromMassInt64(t *testing.T) {
|
|||||||
t.Errorf("Expected '%s', but got: %s", expectedResult, multipleResult)
|
t.Errorf("Expected '%s', but got: %s", expectedResult, multipleResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsInt(t *testing.T) {
|
||||||
|
// Test with an empty string
|
||||||
|
emptyResult := IsInt("")
|
||||||
|
if emptyResult != false {
|
||||||
|
t.Errorf("Expected false for empty string, but got: %v", emptyResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with a string containing only digits
|
||||||
|
digitResult := IsInt("12345")
|
||||||
|
if digitResult != true {
|
||||||
|
t.Errorf("Expected true for string containing only digits, but got: %v", digitResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with a string containing non-digit characters
|
||||||
|
nonDigitResult := IsInt("abc123")
|
||||||
|
if nonDigitResult != false {
|
||||||
|
t.Errorf("Expected false for string containing non-digit characters, but got: %v", nonDigitResult)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user