Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / container / vector / nogen_test.go
blob790d3749fc2355008caba2b290bd80c791fe9dca
1 // Copyright 2009 The Go Authors. 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.
5 package vector
8 import (
9 "fmt"
10 "sort"
11 "testing"
14 var (
15 zero interface{}
16 intzero int
17 strzero string
21 func int2Value(x int) int { return x }
22 func int2IntValue(x int) int { return x }
23 func int2StrValue(x int) string { return string(x) }
26 func elem2Value(x interface{}) int { return x.(int) }
27 func elem2IntValue(x int) int { return x }
28 func elem2StrValue(x string) string { return x }
31 func intf2Value(x interface{}) int { return x.(int) }
32 func intf2IntValue(x interface{}) int { return x.(int) }
33 func intf2StrValue(x interface{}) string { return x.(string) }
36 type VectorInterface interface {
37 Len() int
38 Cap() int
42 func checkSize(t *testing.T, v VectorInterface, len, cap int) {
43 if v.Len() != len {
44 t.Errorf("%T expected len = %d; found %d", v, len, v.Len())
46 if v.Cap() < cap {
47 t.Errorf("%T expected cap >= %d; found %d", v, cap, v.Cap())
52 func val(i int) int { return i*991 - 1234 }
55 func TestSorting(t *testing.T) {
56 const n = 100
58 a := new(IntVector).Resize(n, 0)
59 for i := n - 1; i >= 0; i-- {
60 a.Set(i, n-1-i)
62 if sort.IsSorted(a) {
63 t.Error("int vector not sorted")
66 b := new(StringVector).Resize(n, 0)
67 for i := n - 1; i >= 0; i-- {
68 b.Set(i, fmt.Sprint(n-1-i))
70 if sort.IsSorted(b) {
71 t.Error("string vector not sorted")
76 func tname(x interface{}) string { return fmt.Sprintf("%T: ", x) }