1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-26 23:10:42 +02:00

сделал StringFromMassInt64()

This commit is contained in:
Nikitin Aleksandr
2024-07-17 17:11:11 +03:00
parent 604f3c7d95
commit c4a01b094c
2 changed files with 39 additions and 0 deletions

View File

@@ -946,3 +946,18 @@ func IsNilInterface(i any) bool {
return false
}
}
// StringFromMassInt64 - преобразование массива int64 в строку
func StringFromMassInt64(A []int64, delim string) string {
var buffer bytes.Buffer
for i := 0; i < len(A); i++ {
s1 := StringFromInt64(A[i])
buffer.WriteString(s1)
if i != len(A)-1 {
buffer.WriteString(delim)
}
}
return buffer.String()
}

View File

@@ -829,3 +829,27 @@ func TestIsNilInterface(t *testing.T) {
t.Error("Expected true for nil interface")
}
}
func TestStringFromMassInt64(t *testing.T) {
// Test with an empty array
emptyArray := []int64{}
emptyResult := StringFromMassInt64(emptyArray, ",")
if emptyResult != "" {
t.Errorf("Expected empty string, but got: %s", emptyResult)
}
// Test with an array of single element
singleArray := []int64{42}
singleResult := StringFromMassInt64(singleArray, ",")
if singleResult != "42" {
t.Errorf("Expected '42', but got: %s", singleResult)
}
// Test with an array of multiple elements
multipleArray := []int64{1, 2, 3}
multipleResult := StringFromMassInt64(multipleArray, "-")
expectedResult := "1-2-3"
if multipleResult != expectedResult {
t.Errorf("Expected '%s', but got: %s", expectedResult, multipleResult)
}
}