Enforce String() inteface on Container

pull/194/head
Emir Pasic 2 years ago
parent a27d480bcc
commit 364a244af9

@ -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 {

@ -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}

Loading…
Cancel
Save