bitvector work
[bpt/guile.git] / test-suite / tests / bitvectors.test
1 ;;;; bitvectors.test --- tests guile's bitvectors -*- scheme -*-
2 ;;;;
3 ;;;; Copyright 2010 Free Software Foundation, Inc.
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))
25 (pass-if (generalized-vector? #*1010101010))
26 (pass-if (uniform-vector? #*1010101010))
27 (pass-if (array? #*1010101010)))
28
29
30 (with-test-prefix "equality"
31 (pass-if (equal? #*1010101 #*1010101))
32 (pass-if (array-equal? #*1010101 #*1010101))
33
34 (pass-if (not (equal? #*10101010 #*1010101)))
35 (pass-if (not (array-equal? #*10101010 #*1010101))))
36
37 (with-test-prefix "lists"
38 (pass-if (equal? (bitvector->list #*10010) '(#t #f #f #t #f)))
39 (pass-if (equal? (array->list #*10010) '(#t #f #f #t #f)))
40 (pass-if (equal? (uniform-vector->list #*10010) '(#t #f #f #t #f)))
41 (pass-if (equal? #*10010 (list->bitvector '(#t #f #f #t #f)))))
42
43 (with-test-prefix "ref and set"
44 (with-test-prefix "bv"
45 (let ((bv (list->bitvector '(#f #f #t #f #t))))
46 (pass-if (eqv? (bitvector-ref bv 0) #f))
47 (pass-if (eqv? (bitvector-ref bv 2) #t))
48 (bitvector-set! bv 0 #t)
49 (pass-if (eqv? (bitvector-ref bv 0) #t))))
50
51 (with-test-prefix "uv"
52 (let ((bv (list->bitvector '(#f #f #t #f #t))))
53 (pass-if (eqv? (uniform-vector-ref bv 0) #f))
54 (pass-if (eqv? (uniform-vector-ref bv 2) #t))
55 (uniform-vector-set! bv 0 #t)
56 (pass-if (eqv? (uniform-vector-ref bv 0) #t)))))
57
58
59