merge from 1.8 branch
[bpt/guile.git] / test-suite / tests / sort.test
CommitLineData
d339981a 1;;;; sort.test --- tests Guile's sort functions -*- scheme -*-
6e7d5622 2;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
d339981a
DH
3;;;;
4;;;; This program is free software; you can redistribute it and/or modify
5;;;; it under the terms of the GNU General Public License as published by
6;;;; the Free Software Foundation; either version 2, or (at your option)
7;;;; any later version.
8;;;;
9;;;; This program is distributed in the hope that it will be useful,
10;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12;;;; GNU General Public License for more details.
13;;;;
14;;;; You should have received a copy of the GNU General Public License
15;;;; along with this software; see the file COPYING. If not, write to
92205699
MV
16;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17;;;; Boston, MA 02110-1301 USA
d339981a
DH
18
19(use-modules (test-suite lib))
20
42fc3f2c
MV
21(define (randomize-vector! v n)
22 (array-index-map! v (lambda (i) (random n)))
23 v)
24
d339981a
DH
25(with-test-prefix "sort"
26
27 (pass-if-exception "less function taking less than two arguments"
28 exception:wrong-type-arg
29 (sort '(1 2) (lambda (x) #t)))
30
31 (pass-if-exception "less function taking more than two arguments"
32 exception:wrong-type-arg
42fc3f2c
MV
33 (sort '(1 2) (lambda (x y z) z)))
34
35 (pass-if "sort!"
36 (let ((v (randomize-vector! (make-vector 1000) 1000)))
37 (sorted? (sort! v <) <)))
38
39 (pass-if "sort! of non-contigous vector"
40 (let* ((a (make-array 0 1000 3))
41 (v (make-shared-array a (lambda (i) (list i 0)) 1000)))
42 (randomize-vector! v 1000)
43 (sorted? (sort! v <) <)))
44
45 (pass-if "sort! of negative-increment vector"
46 (let* ((a (make-array 0 1000 3))
47 (v (make-shared-array a (lambda (i) (list (- 999 i) 0)) 1000)))
48 (randomize-vector! v 1000)
49 (sorted? (sort! v <) <)))
50
51 (pass-if "stable-sort!"
52 (let ((v (randomize-vector! (make-vector 1000) 1000)))
53 (sorted? (stable-sort! v <) <)))
54
55 (pass-if "stable-sort! of non-contigous vector"
56 (let* ((a (make-array 0 1000 3))
57 (v (make-shared-array a (lambda (i) (list i 0)) 1000)))
58 (randomize-vector! v 1000)
59 (sorted? (stable-sort! v <) <)))
60
61 (pass-if "stable-sort! of negative-increment vector"
62 (let* ((a (make-array 0 1000 3))
63 (v (make-shared-array a (lambda (i) (list (- 999 i) 0)) 1000)))
64 (randomize-vector! v 1000)
65 (sorted? (stable-sort! v <) <))))