28 #include "../../binary.h"
29 #include "../../bitset.h"
36 unsigned long value = 23;
38 std::string s = bits.to_string();
39 std::cout << bits << std::endl;
40 assert(s == std::string(
"00010111"));
44 std::cout << bits << std::endl;
46 assert(s == std::string(
"01011100"));
49 std::cout << bits << std::endl;
51 assert(s == std::string(
"00101110"));
53 s = (bits << 3).to_string();
54 assert(s == std::string(
"01110000"));
56 s = (bits >> 2).to_string();
57 assert(s == std::string(
"00001011"));
60 unsigned long v1 = 14, v2 = 679;
61 Bitset bits1(15, v1), bits2(15, v2);
63 assert((bits1 & bits2).to_ulong() == (v1 & v2));
64 assert((bits1 | bits2).to_ulong() == (v1 | v2));
65 assert((bits1 ^ bits2).to_ulong() == (v1 ^ v2));
67 assert((bits < bits1) == (value < v1));
68 assert((bits1 < bits2) == (v1 < v2));
69 assert((bits2 < bits1) == (v2 < v1));
71 using namespace std::rel_ops;
73 assert((bits1 > bits2) == (v1 > v2));
74 assert((bits1 >= bits2) == (v1 >= v2));
75 assert((bits1 <= bits2) == (v1 <= v2));
76 assert((bits1 != bits2) == (v1 != v2));
84 std::cout << bits2.size() <<
": " << bits2 << std::endl;
85 assert(bits2.to_ulong() == 0x02a512);
89 std::cout << std::endl;
91 Bitset child(4, 0, &parent);
93 std::cout <<
"parent: " << parent << std::endl;
94 std::cout <<
"child: " << child << std::endl;
96 std::cout <<
"get more bits: 4" << std::endl;
97 child.get_more_bits(4);
99 std::cout <<
"parent: " << parent << std::endl;
100 std::cout <<
"child: " << child << std::endl;
102 assert(child.size() == 8);
103 assert(parent.size() == 4);
105 assert(child.to_ulong() == 0x10);
106 assert(parent.to_ulong() == 0xD);
110 std::cout << std::endl;
111 Bitset grandparent(8, 0xD1);
112 Bitset parent(8, 0x02, &grandparent);
113 Bitset child(4, 0, &parent);
115 std::cout <<
"grandparent: " << grandparent << std::endl;
116 std::cout <<
"parent: " << parent << std::endl;
117 std::cout <<
"child: " << child << std::endl;
119 std::cout <<
"get more bits: 4" << std::endl;
120 child.get_more_bits(4);
122 std::cout <<
"grandparent: " << grandparent << std::endl;
123 std::cout <<
"parent: " << parent << std::endl;
124 std::cout <<
"child: " << child << std::endl;
126 assert(child.size() == 8);
127 assert(parent.size() == 4);
128 assert(grandparent.size() == 8);
130 assert(child.to_ulong() == 0x20);
131 assert(parent.to_ulong() == 0x0);
132 assert(grandparent.to_ulong() == 0xD1);
136 std::cout << std::endl;
137 Bitset grandparent(8, 0xD1);
138 Bitset parent(&grandparent);
139 Bitset child(4, 0, &parent);
141 std::cout <<
"grandparent: " << grandparent << std::endl;
142 std::cout <<
"parent: " << parent << std::endl;
143 std::cout <<
"child: " << child << std::endl;
145 std::cout <<
"get more bits: 4" << std::endl;
146 child.get_more_bits(4);
148 std::cout <<
"grandparent: " << grandparent << std::endl;
149 std::cout <<
"parent: " << parent << std::endl;
150 std::cout <<
"child: " << child << std::endl;
152 assert(child.size() == 8);
153 assert(parent.size() == 0);
154 assert(grandparent.size() == 4);
156 assert(child.to_ulong() == 0x10);
157 assert(parent.to_ulong() == 0x0);
158 assert(grandparent.to_ulong() == 0xD);
161 std::cout <<
"all tests passed" << std::endl;