mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал StringFromMassInt64()
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user