source: trunk/source/tests/ansi-tests/sort-aux.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 1.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Jul 17 06:42:27 2003
4;;;; Contains: Routines for testing SORT, NSORT
5
6(in-package :cl-test)
7
8(defun my-numeric-sort (list)
9  "Sort (nondestructively) a list of reals."
10  (if (null (cdr list))
11      list
12    (let* ((len2 (ash (length list) -1))
13           (l1 (my-numeric-sort (subseq list 0 len2)))
14           (l2 (my-numeric-sort (subseq list len2))))
15      (my-numeric-merge l1 l2))))
16
17(defun my-numeric-merge (l1 l2)
18  (cond
19   ((null l1) l2)
20   ((null l2) l1)
21   ((<= (car l1) (car l2))
22    (cons (car l1) (my-numeric-merge (cdr l1) l2)))
23   (t
24    (cons (car l2) (my-numeric-merge l1 (cdr l2))))))
25
26(defun generate-random-sort-test (n m)
27  (loop for i below n collect (random m)))
28
29(defun random-sort-test (n m reps)
30  (loop
31   for i below reps
32   for list = (generate-random-sort-test (random n) m)
33   unless (equal (my-numeric-sort list)
34                 (sort (copy-seq list) #'<))
35   collect list))
36
37(defun random-stable-sort-test (n m reps)
38  (loop
39   for i below reps
40   for list = (generate-random-sort-test (random n) m)
41   unless (equal (my-numeric-sort list)
42                 (stable-sort (copy-seq list) #'<))
43   collect list))
Note: See TracBrowser for help on using the repository browser.