github.com/alexandrestein/gods@v1.0.1/containers/containers_test.go (about) 1 // Copyright (c) 2015, Emir Pasic. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // All data structures must implement the container structure 6 7 package containers 8 9 import ( 10 "github.com/alexandrestein/gods/utils" 11 "testing" 12 ) 13 14 // For testing purposes 15 type ContainerTest struct { 16 values []interface{} 17 } 18 19 func (container ContainerTest) Empty() bool { 20 return len(container.values) == 0 21 } 22 23 func (container ContainerTest) Size() int { 24 return len(container.values) 25 } 26 27 func (container ContainerTest) Clear() { 28 container.values = []interface{}{} 29 } 30 31 func (container ContainerTest) Values() []interface{} { 32 return container.values 33 } 34 35 func TestGetSortedValuesInts(t *testing.T) { 36 container := ContainerTest{} 37 container.values = []interface{}{5, 1, 3, 2, 4} 38 values := GetSortedValues(container, utils.IntComparator) 39 for i := 1; i < container.Size(); i++ { 40 if values[i-1].(int) > values[i].(int) { 41 t.Errorf("Not sorted!") 42 } 43 } 44 } 45 46 func TestGetSortedValuesStrings(t *testing.T) { 47 container := ContainerTest{} 48 container.values = []interface{}{"g", "a", "d", "e", "f", "c", "b"} 49 values := GetSortedValues(container, utils.StringComparator) 50 for i := 1; i < container.Size(); i++ { 51 if values[i-1].(string) > values[i].(string) { 52 t.Errorf("Not sorted!") 53 } 54 } 55 }