Commit | Line | Data |
---|---|---|
0142d376 AW |
1 | ;;;; bitvectors.test --- tests guile's bitvectors -*- scheme -*- |
2 | ;;;; | |
118ff892 | 3 | ;;;; Copyright 2010, 2011, 2013 Free Software Foundation, Inc. |
0142d376 AW |
4 | ;;;; |
5 | ;;;; This library is free software; you can redistribute it and/or | |
6 | ;;;; modify it under the terms of the GNU Lesser General Public | |
7 | ;;;; License as published by the Free Software Foundation; either | |
8 | ;;;; version 3 of the License, or (at your option) any later version. | |
9 | ;;;; | |
10 | ;;;; This library is distributed in the hope that it will be useful, | |
11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | ;;;; Lesser General Public License for more details. | |
14 | ;;;; | |
15 | ;;;; You should have received a copy of the GNU Lesser General Public | |
16 | ;;;; License along with this library; if not, write to the Free Software | |
17 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | ||
19 | (define-module (test-suite test-bitvectors) | |
20 | #:use-module (test-suite lib)) | |
21 | ||
22 | ||
23 | (with-test-prefix "predicates" | |
24 | (pass-if (bitvector? #*1010101010)) | |
0142d376 AW |
25 | (pass-if (uniform-vector? #*1010101010)) |
26 | (pass-if (array? #*1010101010))) | |
27 | ||
28 | ||
29 | (with-test-prefix "equality" | |
30 | (pass-if (equal? #*1010101 #*1010101)) | |
31 | (pass-if (array-equal? #*1010101 #*1010101)) | |
32 | ||
33 | (pass-if (not (equal? #*10101010 #*1010101))) | |
34 | (pass-if (not (array-equal? #*10101010 #*1010101)))) | |
35 | ||
36 | (with-test-prefix "lists" | |
37 | (pass-if (equal? (bitvector->list #*10010) '(#t #f #f #t #f))) | |
38 | (pass-if (equal? (array->list #*10010) '(#t #f #f #t #f))) | |
39 | (pass-if (equal? (uniform-vector->list #*10010) '(#t #f #f #t #f))) | |
40 | (pass-if (equal? #*10010 (list->bitvector '(#t #f #f #t #f))))) | |
41 | ||
42 | (with-test-prefix "ref and set" | |
43 | (with-test-prefix "bv" | |
44 | (let ((bv (list->bitvector '(#f #f #t #f #t)))) | |
45 | (pass-if (eqv? (bitvector-ref bv 0) #f)) | |
46 | (pass-if (eqv? (bitvector-ref bv 2) #t)) | |
47 | (bitvector-set! bv 0 #t) | |
48 | (pass-if (eqv? (bitvector-ref bv 0) #t)))) | |
49 | ||
50 | (with-test-prefix "uv" | |
51 | (let ((bv (list->bitvector '(#f #f #t #f #t)))) | |
52 | (pass-if (eqv? (uniform-vector-ref bv 0) #f)) | |
53 | (pass-if (eqv? (uniform-vector-ref bv 2) #t)) | |
54 | (uniform-vector-set! bv 0 #t) | |
55 | (pass-if (eqv? (uniform-vector-ref bv 0) #t))))) | |
56 | ||
39c5363b AW |
57 | (with-test-prefix "bit-set*!" |
58 | (pass-if "#t" | |
59 | (let ((v (bitvector #t #t #f #f))) | |
60 | (bit-set*! v #*1010 #t) | |
61 | (equal? v #*1110))) | |
62 | (pass-if "#f" | |
63 | (let ((v (bitvector #t #t #f #f))) | |
64 | (bit-set*! v #*1010 #f) | |
65 | (equal? v #*0100))) | |
66 | (pass-if "#t, shorter" | |
67 | (let ((v (bitvector #t #t #f #f))) | |
68 | (bit-set*! v #*101 #t) | |
69 | (equal? v #*1110))) | |
70 | (pass-if "#f, shorter" | |
71 | (let ((v (bitvector #t #t #f #f))) | |
72 | (bit-set*! v #*101 #f) | |
73 | (equal? v #*0100)))) |