Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
emirpasic committed Apr 12, 2022
2 parents 3bca87d + 364a244 commit 9641d19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions containers/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
package containers

import (
"fmt"
"github.com/emirpasic/gods/utils"
"strings"
"testing"
)

Expand All @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ 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:
return strconv.FormatUint(uint64(value), 10)
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:
Expand Down

0 comments on commit 9641d19

Please sign in to comment.