Fast generic function dispatch without calling `compile' at runtime
[bpt/guile.git] / test-suite / tests / bitvectors.test
CommitLineData
0142d376
AW
1;;;; bitvectors.test --- tests guile's bitvectors -*- scheme -*-
2;;;;
fb7dd001 3;;;; Copyright 2010, 2011, 2013, 2014 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))
fb7dd001
AW
25 (pass-if (array? #*1010101010))
26 (pass-if (eq? (array-type #*1010101010) 'b)))
0142d376
AW
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)))
0142d376
AW
39 (pass-if (equal? #*10010 (list->bitvector '(#t #f #f #t #f)))))
40
41(with-test-prefix "ref and set"
fb7dd001 42 (with-test-prefix "as bitvector"
0142d376
AW
43 (let ((bv (list->bitvector '(#f #f #t #f #t))))
44 (pass-if (eqv? (bitvector-ref bv 0) #f))
45 (pass-if (eqv? (bitvector-ref bv 2) #t))
46 (bitvector-set! bv 0 #t)
47 (pass-if (eqv? (bitvector-ref bv 0) #t))))
48
fb7dd001 49 (with-test-prefix "as array"
0142d376 50 (let ((bv (list->bitvector '(#f #f #t #f #t))))
fb7dd001
AW
51 (pass-if (eqv? (array-ref bv 0) #f))
52 (pass-if (eqv? (array-ref bv 2) #t))
53 (array-set! bv #t 0)
54 (pass-if (eqv? (array-ref bv 0) #t)))))
0142d376 55
39c5363b
AW
56(with-test-prefix "bit-set*!"
57 (pass-if "#t"
58 (let ((v (bitvector #t #t #f #f)))
59 (bit-set*! v #*1010 #t)
60 (equal? v #*1110)))
61 (pass-if "#f"
62 (let ((v (bitvector #t #t #f #f)))
63 (bit-set*! v #*1010 #f)
64 (equal? v #*0100)))
65 (pass-if "#t, shorter"
66 (let ((v (bitvector #t #t #f #f)))
67 (bit-set*! v #*101 #t)
68 (equal? v #*1110)))
69 (pass-if "#f, shorter"
70 (let ((v (bitvector #t #t #f #f)))
71 (bit-set*! v #*101 #f)
72 (equal? v #*0100))))
d40b0538
AW
73
74(with-test-prefix "bit-count*"
75 (pass-if-equal 3 (bit-count* #*01110111 #*11001101 #t))
76 (pass-if-equal 2 (bit-count* #*01110111 #u32(7 0 4) #f)))