Simplify GOOPS effective method cache format
[bpt/guile.git] / test-suite / tests / sort.test
CommitLineData
d339981a 1;;;; sort.test --- tests Guile's sort functions -*- scheme -*-
589bc528 2;;;; Copyright (C) 2003, 2006, 2007, 2009, 2011 Free Software Foundation, Inc.
d339981a 3;;;;
53befeb7
NJ
4;;;; This library is free software; you can redistribute it and/or
5;;;; modify it under the terms of the GNU Lesser General Public
6;;;; License as published by the Free Software Foundation; either
7;;;; version 3 of the License, or (at your option) any later version.
d339981a 8;;;;
53befeb7 9;;;; This library is distributed in the hope that it will be useful,
d339981a 10;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
53befeb7
NJ
11;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12;;;; Lesser General Public License for more details.
d339981a 13;;;;
53befeb7
NJ
14;;;; You should have received a copy of the GNU Lesser General Public
15;;;; License along with this library; if not, write to the Free Software
16;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d339981a
DH
17
18(use-modules (test-suite lib))
19
42fc3f2c
MV
20(define (randomize-vector! v n)
21 (array-index-map! v (lambda (i) (random n)))
22 v)
23
d339981a
DH
24(with-test-prefix "sort"
25
26 (pass-if-exception "less function taking less than two arguments"
95e59982 27 exception:wrong-num-args
d339981a
DH
28 (sort '(1 2) (lambda (x) #t)))
29
30 (pass-if-exception "less function taking more than two arguments"
95e59982 31 exception:wrong-num-args
42fc3f2c
MV
32 (sort '(1 2) (lambda (x y z) z)))
33
34 (pass-if "sort!"
35 (let ((v (randomize-vector! (make-vector 1000) 1000)))
36 (sorted? (sort! v <) <)))
37
38 (pass-if "sort! of non-contigous vector"
39 (let* ((a (make-array 0 1000 3))
40 (v (make-shared-array a (lambda (i) (list i 0)) 1000)))
41 (randomize-vector! v 1000)
42 (sorted? (sort! v <) <)))
43
44 (pass-if "sort! of negative-increment vector"
45 (let* ((a (make-array 0 1000 3))
46 (v (make-shared-array a (lambda (i) (list (- 999 i) 0)) 1000)))
47 (randomize-vector! v 1000)
48 (sorted? (sort! v <) <)))
49
50 (pass-if "stable-sort!"
51 (let ((v (randomize-vector! (make-vector 1000) 1000)))
52 (sorted? (stable-sort! v <) <)))
53
54 (pass-if "stable-sort! of non-contigous vector"
55 (let* ((a (make-array 0 1000 3))
56 (v (make-shared-array a (lambda (i) (list i 0)) 1000)))
57 (randomize-vector! v 1000)
58 (sorted? (stable-sort! v <) <)))
59
60 (pass-if "stable-sort! of negative-increment vector"
61 (let* ((a (make-array 0 1000 3))
62 (v (make-shared-array a (lambda (i) (list (- 999 i) 0)) 1000)))
63 (randomize-vector! v 1000)
64 (sorted? (stable-sort! v <) <))))
004be623
KR
65
66
67;;;
68;;; stable-sort
69;;;
70
71(with-test-prefix "stable-sort"
72
73 ;; in guile 1.8.0 and 1.8.1 this test failed, an empty list provoked a
74 ;; wrong-type-arg exception (where it shouldn't)
75 (pass-if "empty list"
589bc528
AR
76 (eq? '() (stable-sort '() <)))
77
78 ;; Ditto here, but up to 2.0.1 and 2.1.0 and invoking undefined
79 ;; behavior (integer underflow) leading to crashes.
80 (pass-if "empty vector"
81 (equal? '#() (stable-sort '#() <))))
004be623 82