github.com/mymmsc/gox@v1.3.33/util/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 util 8 9 import ( 10 "testing" 11 ) 12 13 // For testing purposes 14 type ContainerTest struct { 15 values []interface{} 16 } 17 18 func (container ContainerTest) Empty() bool { 19 return len(container.values) == 0 20 } 21 22 func (container ContainerTest) Size() int { 23 return len(container.values) 24 } 25 26 func (container ContainerTest) Clear() { 27 container.values = []interface{}{} 28 } 29 30 func (container ContainerTest) Values() []interface{} { 31 return container.values 32 } 33 34 func TestGetSortedValuesInts(t *testing.T) { 35 container := ContainerTest{} 36 container.values = []interface{}{5, 1, 3, 2, 4} 37 values := GetSortedValues(container, IntComparator) 38 for i := 1; i < container.Size(); i++ { 39 if values[i-1].(int) > values[i].(int) { 40 t.Errorf("Not sorted!") 41 } 42 } 43 } 44 45 func TestGetSortedValuesStrings(t *testing.T) { 46 container := ContainerTest{} 47 container.values = []interface{}{"g", "a", "d", "e", "f", "c", "b"} 48 values := GetSortedValues(container, StringComparator) 49 for i := 1; i < container.Size(); i++ { 50 if values[i-1].(string) > values[i].(string) { 51 t.Errorf("Not sorted!") 52 } 53 } 54 }