1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-20 18:50:21 +02:00

Merge until e0bcda4ad9 from stable-2.2

This commit is contained in:
Andy Wingo 2017-11-29 21:04:59 +01:00
commit f85d3c0bd8
21 changed files with 507 additions and 312 deletions

View file

@ -1,17 +1,17 @@
;;;; array-map.test --- test array mapping functions -*- scheme -*-
;;;;
;;;;
;;;; Copyright (C) 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@ -92,6 +92,10 @@
(array-copy! #2:0:2() c)
(array-equal? #2f64:0:2() c)))
(pass-if "empty/immutable vector"
(array-copy! #() (vector))
#t)
;; FIXME add empty, type 'b cases.
)
@ -520,6 +524,14 @@
(array-slice-for-each 1 (lambda (a) (sort! a <)) a)
a))
(pass-if-equal "1 argument frame rank 1, non-zero base indices"
#2@1@1((1 3 9) (2 7 8))
(let* ((a (make-array *unspecified* '(1 2) '(1 3)))
(b #2@1@1((9 1 3) (7 8 2))))
(array-copy! b a)
(array-slice-for-each 1 (lambda (a) (sort! a <)) a)
a))
(pass-if-equal "2 arguments frame rank 1"
#f64(8 -1)
(let* ((x (list->typed-array 'f64 2 '((9 1) (7 8))))

View file

@ -999,4 +999,57 @@
"#1(b c)"
(format #f "~a" (make-shared-array #(a b c)
(lambda (i) (list (+ i 1)))
2))))
2)))
(pass-if-equal "0-array"
"#0(9)"
(format #f "~a" (make-array 9)))
(pass-if-equal "2-array"
"#2f64((0.0 1.0) (2.0 3.0))"
(format #f "~a" #2f64((0 1) (2 3))))
(pass-if-equal "empty 3-array"
"#3()"
(format #f "~a" (make-array 1 0 0 0)))
(pass-if-equal "empty 3-array with last nonempty dim."
"#3:0:0:1()"
(format #f "~a" (make-array 1 0 0 1)))
(pass-if-equal "empty 3-array with middle nonempty dim."
"#3:0:1:0()"
(format #f "~a" (make-array 1 0 1 0)))
(pass-if-equal "empty 3-array with first nonempty dim."
"#3(())"
(format #f "~a" (make-array 1 1 0 0)))
(pass-if-equal "3-array with non-zero lower bounds"
"#3@1@0@1(((1 1 1) (1 1 1)) ((1 1 1) (1 1 1)))"
(format #f "~a" (make-array 1 '(1 2) '(0 1) '(1 3))))
(pass-if-equal "3-array with non-zero-lower bounds and last nonempty dim."
"#3@0:0@0:0@1:3()"
(format #f "~a" (make-array 1 0 0 '(1 3))))
(pass-if-equal "3-array with non-zero-lower bounds and middle nonempty dim."
"#3@0:0@1:3@0:0()"
(format #f "~a" (make-array 1 0 '(1 3) 0)))
(pass-if-equal "3-array with non-zero-lower bounds and first nonempty dim."
"#3@1@0@0(() () ())"
(format #f "~a" (make-array 1 '(1 3) 0 0)))
(pass-if-equal "3-array with singleton dim case I"
"#3@1@1@-1(((1 1 1)))"
(format #f "~a" (make-array 1 '(1 1) '(1 1) '(-1 1))))
(pass-if-equal "3-array with singleton dim case II"
"#3@-1@1@1(((1) (1) (1)))"
(format #f "~a" (make-array 1 '(-1 -1) '(1 3) '(1 1))))
(pass-if-equal "3-array with singleton dim case III"
"#3@1@-1@1(((1)) ((1)) ((1)))"
(format #f "~a" (make-array 1 '(1 3) '(-1 -1) '(1 1)))))

View file

@ -602,6 +602,34 @@
(pass-if "unread residue"
(string=? (read-line) "moon"))))
(pass-if-equal "close-port & revealed port"
EBADF
(let* ((port (open-file "/dev/null" "r0"))
(fdes (port->fdes port))) ;increments revealed count of PORT
(close-port port) ;closes FDES as a side-effect
(catch 'system-error
(lambda ()
(seek fdes 0 SEEK_CUR)
#f)
(lambda args
(system-error-errno args)))))
(pass-if "revealed port fdes not closed"
(let* ((port (open-file "/dev/null" "r0"))
(fdes (port->fdes port)) ;increments revealed count of PORT
(guardian (make-guardian)))
(guardian port)
(set! port #f)
(gc)
(if (port? (guardian))
(and (zero? (seek fdes 0 SEEK_CUR))
(begin
(close-fdes fdes)
#t))
(begin
(close-fdes fdes)
(throw 'unresolved)))))
(when (provided? 'threads)
(let* ((p (pipe))
(r (car p))

View file

@ -147,6 +147,35 @@
(pass-if-equal "#<directory (test-…>"
(tprint (current-module) 20 "UTF-8"))
;; bitvectors
(let ((testv (bitvector #t #f #f #t #t #f #t #t)))
(pass-if-equal "#*10011011"
(tprint testv 11 "UTF-8"))
(pass-if-equal "#*10011011"
(tprint testv 11 "ISO-8859-1"))
(pass-if-equal "#*10011…"
(tprint testv 8 "UTF-8"))
(pass-if-equal "#*100..."
(tprint testv 8 "ISO-8859-1"))
(pass-if-equal "#*10…"
(tprint testv 5 "UTF-8"))
(pass-if-equal "#*..."
(tprint testv 5 "ISO-8859-1"))
(pass-if-equal "#*1…"
(tprint testv 4 "UTF-8"))
(pass-if-equal "#"
(tprint testv 4 "ISO-8859-1")))
;; rank 0 arrays
(pass-if-equal "#0(#)"
(tprint (make-typed-array #t 9.0) 6 "UTF-8"))
@ -162,18 +191,31 @@
(pass-if-equal "#"
(tprint (make-typed-array 's32 0 20 20) 7 "UTF-8"))
(pass-if-equal "#2s32(…)"
(tprint (make-typed-array 's32 0 20 20) 8 "UTF-8"))
;; higher dimensional arrays
(pass-if-equal "#2s32(# …)"
(tprint (make-typed-array 's32 0 20 20) 10 "UTF-8"))
(let ((testa (make-typed-array 's32 0 20 20)))
(pass-if-equal "#2s32(…)"
(tprint testa 8 "UTF-8"))
(pass-if-equal "#2s32((…) …)"
(tprint (make-typed-array 's32 0 20 20) 12 "UTF-8"))
(pass-if-equal "#2s32(# …)"
(tprint testa 10 "UTF-8"))
(pass-if-equal "#2s32((0 …) …)"
(tprint (make-typed-array 's32 0 20 20) 14 "UTF-8"))
(pass-if-equal "#2s32((…) …)"
(tprint testa 12 "UTF-8"))
(pass-if-equal "#2s32((0 …) …)"
(tprint testa 14 "UTF-8")))
;; check that bounds are printed correctly
(pass-if-equal "#2@-1@0((foo foo foo foo …) …)"
(tprint (make-array 'foo '(-1 3) 5) 30 "UTF-8"))
(pass-if-equal "#3@-1:5@0:0@0:5(() () () # #)"
(tprint (make-array 'foo '(-1 3) 0 5) 30 "UTF-8"))
;; nested objects including arrays
(pass-if-equal "#2((#(9 9) #(9 9)) (#(9 9) #(9 9)))"
(tprint (make-typed-array #t (make-typed-array #t 9 2) 2 2) 40 "UTF-8"))

View file

@ -1,25 +1,57 @@
;;;; sort.test --- tests Guile's sort functions -*- scheme -*-
;;;; Copyright (C) 2003, 2006, 2007, 2009, 2011 Free Software Foundation, Inc.
;;;;
;;;; Copyright (C) 2003, 2006, 2007, 2009, 2011, 2017
;;;; Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(use-modules (test-suite lib))
(use-modules (test-suite lib)
(ice-9 arrays))
(set! *random-state* (seed->random-state 2017))
; Randomly shuffle u in place, using Fisher-Yates algorithm.
(define (array-shuffle! v)
(unless (= 1 (array-rank v)) (throw 'bad-rank (array-rank v)))
(let* ((dims (car (array-shape v)))
(lo (car dims)))
(let loop ((i (cadr dims)))
(if (> i lo)
(let* ((j (+ lo (random (- (1+ i) lo))))
(t (array-ref v j)))
(array-set! v (array-ref v i) j)
(array-set! v t i)
(loop (- i 1)))
v))))
(define* (test-sort! v #:optional (sort sort))
(array-index-map! v (lambda (i) i))
(let ((before (array-copy v)))
(array-shuffle! v)
(let ((after (array-copy v)))
(and
(equal? before (sort v <))
(equal? after v)))))
(define* (test-sort-inplace! v #:optional (sort! sort!))
(array-index-map! v (lambda (i) i))
(let ((before (array-copy v)))
(array-shuffle! v)
(and (equal? before (sort! v <))
(equal? before v)
(sorted? v <))))
(define (randomize-vector! v n)
(array-index-map! v (lambda (i) (random n)))
v)
(with-test-prefix "sort"
@ -32,70 +64,72 @@
(sort '(1 2) (lambda (x y z) z)))
(pass-if "sort of vector"
(let* ((v (randomize-vector! (make-vector 1000) 1000))
(w (vector-copy v)))
(and (sorted? (sort v <) <)
(equal? w v))))
(test-sort! (make-vector 100)))
(pass-if "sort of typed array"
(let* ((v (randomize-vector! (make-typed-array 'f64 *unspecified* 99) 99))
(w (make-typed-array 'f64 *unspecified* 99)))
(array-copy! v w)
(and (sorted? (sort v <) <)
(equal? w v))))
(pass-if "sort of typed vector"
(test-sort! (make-f64vector 100))))
(pass-if "sort! of vector"
(let ((v (randomize-vector! (make-vector 1000) 1000)))
(sorted? (sort! v <) <)))
(pass-if "sort! of typed array"
(let ((v (randomize-vector! (make-typed-array 'f64 *unspecified* 99) 99)))
(sorted? (sort! v <) <)))
(with-test-prefix "sort!"
(pass-if "sort! of non-contigous vector"
(let* ((a (make-array 0 1000 3))
(v (make-shared-array a (lambda (i) (list i 0)) 1000)))
(randomize-vector! v 1000)
(sorted? (sort! v <) <)))
(pass-if "sort of empty vector"
(test-sort-inplace! (vector)))
(pass-if "sort of vector"
(test-sort-inplace! (make-vector 100)))
(pass-if "sort of empty typed vector"
(test-sort-inplace! (f64vector)))
(pass-if "sort! of typed vector"
(test-sort-inplace! (make-f64vector 100)))
(pass-if "sort! of non-contigous array"
(let* ((a (make-array 0 100 3))
(v (make-shared-array a (lambda (i) (list i 0)) 100)))
(test-sort-inplace! v)))
(pass-if "sort! of non-contigous typed array"
(let* ((a (make-typed-array 'f64 0 99 3))
(v (make-shared-array a (lambda (i) (list i 0)) 99)))
(randomize-vector! v 99)
(sorted? (sort! v <) <)))
(test-sort-inplace! v)))
(pass-if "sort! of negative-increment vector"
(let* ((a (make-array 0 1000 3))
(v (make-shared-array a (lambda (i) (list (- 999 i) 0)) 1000)))
(randomize-vector! v 1000)
(sorted? (sort! v <) <)))
(pass-if "sort! of negative-increment array"
(let* ((a (make-array 0 100 3))
(v (make-shared-array a (lambda (i) (list (- 99 i) 0)) 100)))
(test-sort-inplace! v)))
(pass-if "sort! of non-zero base index array"
(test-sort-inplace! (make-array 0 '(-99 0))))
(pass-if "sort! of non-zero base index typed array"
(test-sort-inplace! (make-typed-array 'f64 0 '(-99 0))))
(pass-if "sort! of negative-increment typed array"
(let* ((a (make-typed-array 'f64 0 99 3))
(v (make-shared-array a (lambda (i) (list (- 98 i) 0)) 99)))
(randomize-vector! v 99)
(sorted? (sort! v <) <)))
(test-sort-inplace! v))))
(with-test-prefix "stable-sort!"
(pass-if "stable-sort!"
(let ((v (randomize-vector! (make-vector 1000) 1000)))
(sorted? (stable-sort! v <) <)))
(let ((v (make-vector 100)))
(test-sort-inplace! v stable-sort!)))
(pass-if "stable-sort! of non-contigous vector"
(let* ((a (make-array 0 1000 3))
(v (make-shared-array a (lambda (i) (list i 0)) 1000)))
(randomize-vector! v 1000)
(sorted? (stable-sort! v <) <)))
(pass-if "stable-sort! of non-contigous array"
(let* ((a (make-array 0 100 3))
(v (make-shared-array a (lambda (i) (list i 0)) 100)))
(test-sort-inplace! v stable-sort!)))
(pass-if "stable-sort! of negative-increment vector"
(let* ((a (make-array 0 1000 3))
(v (make-shared-array a (lambda (i) (list (- 999 i) 0)) 1000)))
(randomize-vector! v 1000)
(sorted? (stable-sort! v <) <))))
(pass-if "stable-sort! of negative-increment array"
(let* ((a (make-array 0 100 3))
(v (make-shared-array a (lambda (i) (list (- 99 i) 0)) 100)))
(test-sort-inplace! v stable-sort!)))
(pass-if "stable-sort! of non-zero base index array"
(test-sort-inplace! (make-array 0 '(-99 0)) stable-sort!)))
;;;
;;; stable-sort
;;;
(with-test-prefix "stable-sort"
@ -108,3 +142,18 @@
;; behavior (integer underflow) leading to crashes.
(pass-if "empty vector"
(equal? '#() (stable-sort '#() <))))
(with-test-prefix "mutable/immutable arguments"
(with-test-prefix/c&e "immutable arguments"
(pass-if "sort! of empty vector"
(equal? #() (sort! (vector) <)))
(pass-if "sort of immutable vector"
(equal? #(0 1) (sort #(1 0) <))))
(pass-if-exception "sort! of mutable vector (compile)"
exception:wrong-type-arg
(compile '(sort! #(0) <) #:to 'value #:env (current-module))))