diff --git a/containers/containers.go b/containers/containers.go index c35ab36d..a512a3cb 100644 --- a/containers/containers.go +++ b/containers/containers.go @@ -21,10 +21,11 @@ type Container interface { Size() int Clear() Values() []interface{} + String() string } // GetSortedValues returns sorted container's elements with respect to the passed comparator. -// Does not effect the ordering of elements within the container. +// Does not affect the ordering of elements within the container. func GetSortedValues(container Container, comparator utils.Comparator) []interface{} { values := container.Values() if len(values) < 2 { diff --git a/containers/containers_test.go b/containers/containers_test.go index 94cf4f80..60e0332e 100644 --- a/containers/containers_test.go +++ b/containers/containers_test.go @@ -7,7 +7,9 @@ package containers import ( + "fmt" "github.com/emirpasic/gods/utils" + "strings" "testing" ) @@ -32,6 +34,16 @@ func (container ContainerTest) Values() []interface{} { return container.values } +func (container ContainerTest) String() string { + str := "ContainerTest\n" + var values []string + for _, value := range container.values { + values = append(values, fmt.Sprintf("%v", value)) + } + str += strings.Join(values, ", ") + return str +} + func TestGetSortedValuesInts(t *testing.T) { container := ContainerTest{} container.values = []interface{}{5, 1, 3, 2, 4} diff --git a/utils/utils.go b/utils/utils.go index d305a7c8..262c6257 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,7 +26,7 @@ func ToString(value interface{}) string { case int32: return strconv.FormatInt(int64(value), 10) case int64: - return strconv.FormatInt(int64(value), 10) + return strconv.FormatInt(value, 10) case uint8: return strconv.FormatUint(uint64(value), 10) case uint16: @@ -34,11 +34,11 @@ func ToString(value interface{}) string { case uint32: return strconv.FormatUint(uint64(value), 10) case uint64: - return strconv.FormatUint(uint64(value), 10) + return strconv.FormatUint(value, 10) case float32: return strconv.FormatFloat(float64(value), 'g', -1, 64) case float64: - return strconv.FormatFloat(float64(value), 'g', -1, 64) + return strconv.FormatFloat(value, 'g', -1, 64) case bool: return strconv.FormatBool(value) default: