Mercurial > gnulib
annotate tests/test-bitset.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | e562c3b5b9c4 |
children | 5d9b82ca550a |
rev | line source |
---|---|
39974
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
1 /* Test of bitset. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
39980
diff
changeset
|
2 Copyright (C) 2018-2019 Free Software Foundation, Inc. |
39974
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
3 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
7 (at your option) any later version. |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
8 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
13 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
16 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
17 #include <config.h> |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
18 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
19 #include "bitset.h" |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
20 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
21 #include "macros.h" |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
22 |
39980
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
23 #define RANDOM(n) (rand () % (n)) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
24 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
25 static |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
26 void assert_bitset_equal (bitset bs1, bitset bs2) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
27 { |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
28 debug_bitset (bs1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
29 debug_bitset (bs2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
30 ASSERT (bitset_size (bs1) == bitset_size (bs2)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
31 for (bitset_bindex i = 0; i < bitset_size (bs1); ++i) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
32 ASSERT (bitset_test (bs1, i) == bitset_test (bs2, i)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
33 } |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
34 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
35 void bitset_random (bitset bs) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
36 { |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
37 for (bitset_bindex i = 0; i < bitset_size (bs); ++i) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
38 bitset_set (bs, RANDOM (2)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
39 } |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
40 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
41 void compare (enum bitset_attr a, enum bitset_attr b) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
42 { |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
43 const int nbits = RANDOM (256); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
44 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
45 bitset asrc0 = bitset_create (nbits, a); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
46 bitset_random (asrc0); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
47 bitset asrc1 = bitset_create (nbits, a); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
48 bitset_random (asrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
49 bitset asrc2 = bitset_create (nbits, a); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
50 bitset_random (asrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
51 bitset asrc3 = bitset_create (nbits, a); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
52 bitset_random (asrc3); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
53 bitset adst = bitset_create (nbits, a); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
54 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
55 bitset bsrc0 = bitset_create (nbits, b); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
56 bitset_copy (bsrc0, asrc0); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
57 bitset bsrc1 = bitset_create (nbits, b); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
58 bitset_copy (bsrc1, asrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
59 bitset bsrc2 = bitset_create (nbits, b); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
60 bitset_copy (bsrc2, asrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
61 bitset bsrc3 = bitset_create (nbits, b); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
62 bitset_copy (bsrc3, asrc3); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
63 bitset bdst = bitset_create (nbits, b); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
64 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
65 bitset_not (adst, asrc0); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
66 bitset_not (bdst, bsrc0); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
67 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
68 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
69 bitset_and (adst, asrc0, asrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
70 bitset_and (bdst, bsrc0, bsrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
71 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
72 ASSERT (bitset_and_cmp (adst, asrc0, asrc1) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
73 == bitset_and_cmp (bdst, bsrc0, bsrc1)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
74 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
75 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
76 bitset_andn (adst, asrc0, asrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
77 bitset_andn (bdst, bsrc0, bsrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
78 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
79 ASSERT (bitset_andn_cmp (adst, asrc0, asrc1) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
80 == bitset_andn_cmp (bdst, bsrc0, bsrc1)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
81 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
82 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
83 bitset_or (adst, asrc0, asrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
84 bitset_or (bdst, bsrc0, bsrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
85 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
86 ASSERT (bitset_or_cmp (adst, asrc0, asrc1) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
87 == bitset_or_cmp (bdst, bsrc0, bsrc1)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
88 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
89 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
90 bitset_xor (adst, asrc0, asrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
91 bitset_xor (bdst, bsrc0, bsrc1); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
92 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
93 ASSERT (bitset_xor_cmp (adst, asrc0, asrc1) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
94 == bitset_xor_cmp (bdst, bsrc0, bsrc1)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
95 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
96 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
97 bitset_and_or (adst, asrc0, asrc1, asrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
98 bitset_and_or (bdst, bsrc0, bsrc1, bsrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
99 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
100 ASSERT (bitset_and_or_cmp (adst, asrc0, asrc1, asrc2) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
101 == bitset_and_or_cmp (bdst, bsrc0, bsrc1, bsrc2)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
102 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
103 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
104 bitset_andn_or (adst, asrc0, asrc1, asrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
105 bitset_andn_or (bdst, bsrc0, bsrc1, bsrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
106 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
107 ASSERT (bitset_andn_or_cmp (adst, asrc0, asrc1, asrc2) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
108 == bitset_andn_or_cmp (bdst, bsrc0, bsrc1, bsrc2)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
109 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
110 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
111 bitset_or_and (adst, asrc0, asrc1, asrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
112 bitset_or_and (bdst, bsrc0, bsrc1, bsrc2); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
113 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
114 ASSERT (bitset_or_and_cmp (adst, asrc0, asrc1, asrc2) |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
115 == bitset_or_and_cmp (bdst, bsrc0, bsrc1, bsrc2)); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
116 assert_bitset_equal (adst, bdst); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
117 } |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
118 |
39974
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
119 void check_attributes (enum bitset_attr attr) |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
120 { |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
121 enum { nbits = 32 }; |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
122 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
123 bitset bs0 = bitset_create (nbits, attr); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
124 ASSERT (bitset_size (bs0) == 32); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
125 ASSERT (bitset_count (bs0) == 0); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
126 ASSERT (bitset_empty_p (bs0)); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
127 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
128 bitset bs1 = bitset_create (nbits, attr); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
129 bitset_set (bs1, 1); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
130 bitset_set (bs1, 3); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
131 bitset_set (bs1, 5); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
132 ASSERT (bitset_count (bs1) == 3); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
133 ASSERT (!bitset_empty_p (bs1)); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
134 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
135 bitset bs2 = bitset_create (nbits, attr); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
136 bitset_set (bs2, 0); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
137 bitset_set (bs2, 2); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
138 bitset_set (bs2, 4); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
139 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
140 /* disjoint_p */ |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
141 ASSERT (bitset_disjoint_p (bs1, bs2)); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
142 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
143 /* and */ |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
144 bitset bs = bitset_create (nbits, attr); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
145 bitset_and (bs, bs1, bs2); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
146 ASSERT (bitset_count (bs) == 0); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
147 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
148 /* or */ |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
149 bitset_or (bs, bs1, bs2); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
150 ASSERT (bitset_count (bs) == 6); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
151 } |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
152 |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
153 int main (void) |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
154 { |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
155 check_attributes (BITSET_FIXED); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
156 check_attributes (BITSET_VARIABLE); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
157 check_attributes (BITSET_DENSE); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
158 check_attributes (BITSET_SPARSE); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
159 check_attributes (BITSET_FRUGAL); |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
160 check_attributes (BITSET_GREEDY); |
39980
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
161 |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
162 compare (BITSET_FIXED, BITSET_FIXED); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
163 compare (BITSET_FIXED, BITSET_VARIABLE); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
164 compare (BITSET_FIXED, BITSET_DENSE); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
165 compare (BITSET_FIXED, BITSET_SPARSE); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
166 compare (BITSET_FIXED, BITSET_FRUGAL); |
e562c3b5b9c4
bitset: check the operations
Akim Demaille <akim.demaille@gmail.com>
parents:
39974
diff
changeset
|
167 compare (BITSET_FIXED, BITSET_GREEDY); |
39974
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
168 return 0; |
29a9f5317b0a
bitset: add tests and doc
Akim Demaille <akim.demaille@gmail.com>
parents:
diff
changeset
|
169 } |