~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/sort/sort_test.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
var float64s = [...]float64{74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8}
17
17
var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"}
18
18
 
19
 
func TestSortIntArray(t *testing.T) {
 
19
func TestSortIntSlice(t *testing.T) {
20
20
        data := ints
21
 
        a := IntArray(data[0:])
 
21
        a := IntSlice(data[0:])
22
22
        Sort(a)
23
23
        if !IsSorted(a) {
24
24
                t.Errorf("sorted %v", ints)
26
26
        }
27
27
}
28
28
 
29
 
func TestSortFloat64Array(t *testing.T) {
 
29
func TestSortFloat64Slice(t *testing.T) {
30
30
        data := float64s
31
 
        a := Float64Array(data[0:])
 
31
        a := Float64Slice(data[0:])
32
32
        Sort(a)
33
33
        if !IsSorted(a) {
34
34
                t.Errorf("sorted %v", float64s)
36
36
        }
37
37
}
38
38
 
39
 
func TestSortStringArray(t *testing.T) {
 
39
func TestSortStringSlice(t *testing.T) {
40
40
        data := strings
41
 
        a := StringArray(data[0:])
 
41
        a := StringSlice(data[0:])
42
42
        Sort(a)
43
43
        if !IsSorted(a) {
44
44
                t.Errorf("sorted %v", strings)
46
46
        }
47
47
}
48
48
 
49
 
func TestSortInts(t *testing.T) {
 
49
func TestInts(t *testing.T) {
50
50
        data := ints
51
 
        SortInts(data[0:])
 
51
        Ints(data[0:])
52
52
        if !IntsAreSorted(data[0:]) {
53
53
                t.Errorf("sorted %v", ints)
54
54
                t.Errorf("   got %v", data)
55
55
        }
56
56
}
57
57
 
58
 
func TestSortFloat64s(t *testing.T) {
 
58
func TestFloat64s(t *testing.T) {
59
59
        data := float64s
60
 
        SortFloat64s(data[0:])
 
60
        Float64s(data[0:])
61
61
        if !Float64sAreSorted(data[0:]) {
62
62
                t.Errorf("sorted %v", float64s)
63
63
                t.Errorf("   got %v", data)
64
64
        }
65
65
}
66
66
 
67
 
func TestSortStrings(t *testing.T) {
 
67
func TestStrings(t *testing.T) {
68
68
        data := strings
69
 
        SortStrings(data[0:])
 
69
        Strings(data[0:])
70
70
        if !StringsAreSorted(data[0:]) {
71
71
                t.Errorf("sorted %v", strings)
72
72
                t.Errorf("   got %v", data)
85
85
        if IntsAreSorted(data) {
86
86
                t.Fatalf("terrible rand.rand")
87
87
        }
88
 
        SortInts(data)
 
88
        Ints(data)
89
89
        if !IntsAreSorted(data) {
90
90
                t.Errorf("sort didn't sort - 1M ints")
91
91
        }
99
99
                        data[i] = strconv.Itoa(i ^ 0x2cc)
100
100
                }
101
101
                b.StartTimer()
102
 
                SortStrings(data)
 
102
                Strings(data)
103
103
                b.StopTimer()
104
104
        }
105
105
}
112
112
                        data[i] = i ^ 0x2cc
113
113
                }
114
114
                b.StartTimer()
115
 
                SortInts(data)
 
115
                Ints(data)
116
116
                b.StopTimer()
117
117
        }
118
118
}
125
125
                        data[i] = i ^ 0xcccc
126
126
                }
127
127
                b.StartTimer()
128
 
                SortInts(data)
 
128
                Ints(data)
129
129
                b.StopTimer()
130
130
        }
131
131
}
161
161
func (d *testingData) Less(i, j int) bool { return d.data[i] < d.data[j] }
162
162
func (d *testingData) Swap(i, j int) {
163
163
        if d.nswap >= d.maxswap {
164
 
                d.t.Errorf("%s: used %d swaps sorting array of %d", d.desc, d.nswap, len(d.data))
 
164
                d.t.Errorf("%s: used %d swaps sorting slice of %d", d.desc, d.nswap, len(d.data))
165
165
                d.t.FailNow()
166
166
        }
167
167
        d.nswap++
241
241
                                                for i := 0; i < n; i++ {
242
242
                                                        mdata[i] = data[i]
243
243
                                                }
244
 
                                                // SortInts is known to be correct
 
244
                                                // Ints is known to be correct
245
245
                                                // because mode Sort runs after mode _Copy.
246
 
                                                SortInts(mdata)
 
246
                                                Ints(mdata)
247
247
                                        case _Dither:
248
248
                                                for i := 0; i < n; i++ {
249
249
                                                        mdata[i] = data[i] + i%5
255
255
                                        Sort(d)
256
256
 
257
257
                                        // If we were testing C qsort, we'd have to make a copy
258
 
                                        // of the array and sort it ourselves and then compare
 
258
                                        // of the slice and sort it ourselves and then compare
259
259
                                        // x against it, to ensure that qsort was only permuting
260
260
                                        // the data, not (for example) overwriting it with zeros.
261
261
                                        //
262
262
                                        // In go, we don't have to be so paranoid: since the only
263
263
                                        // mutating method Sort can call is TestingData.swap,
264
 
                                        // it suffices here just to check that the final array is sorted.
 
264
                                        // it suffices here just to check that the final slice is sorted.
265
265
                                        if !IntsAreSorted(mdata) {
266
266
                                                t.Errorf("%s: ints not sorted", desc)
267
267
                                                t.Errorf("\t%v", mdata)