dyn_bitset_unit_tests3.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. // -----------------------------------------------------------
  2. // Copyright (c) 2001 Jeremy Siek
  3. // Copyright (c) 2003-2006 Gennaro Prota
  4. // Copyright (c) 2014 Ahmed Charles
  5. // Copyright (c) 2014 Riccardo Marcangelo
  6. //
  7. // Distributed under the Boost Software License, Version 1.0.
  8. // (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // -----------------------------------------------------------
  12. #include <assert.h>
  13. #include "bitset_test.hpp"
  14. #include <boost/dynamic_bitset/dynamic_bitset.hpp>
  15. #include <boost/limits.hpp>
  16. #include <boost/config.hpp>
  17. template <typename Block>
  18. void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
  19. {
  20. // a bunch of typedefs which will be handy later on
  21. typedef boost::dynamic_bitset<Block> bitset_type;
  22. typedef bitset_test<bitset_type> Tests;
  23. // typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1
  24. std::string long_string = get_long_string();
  25. std::size_t ul_width = std::numeric_limits<unsigned long>::digits;
  26. //=====================================================================
  27. // Test b.empty()
  28. {
  29. bitset_type b;
  30. Tests::empty(b);
  31. }
  32. {
  33. bitset_type b(1, 1ul);
  34. Tests::empty(b);
  35. }
  36. {
  37. bitset_type b(bitset_type::bits_per_block
  38. + bitset_type::bits_per_block/2, 15ul);
  39. Tests::empty(b);
  40. }
  41. //=====================================================================
  42. // Test b.to_long()
  43. {
  44. boost::dynamic_bitset<Block> b;
  45. Tests::to_ulong(b);
  46. }
  47. {
  48. boost::dynamic_bitset<Block> b(std::string("1"));
  49. Tests::to_ulong(b);
  50. }
  51. {
  52. boost::dynamic_bitset<Block> b(bitset_type::bits_per_block,
  53. static_cast<unsigned long>(-1));
  54. Tests::to_ulong(b);
  55. }
  56. {
  57. std::string str(ul_width - 1, '1');
  58. boost::dynamic_bitset<Block> b(str);
  59. Tests::to_ulong(b);
  60. }
  61. {
  62. std::string ul_str(ul_width, '1');
  63. boost::dynamic_bitset<Block> b(ul_str);
  64. Tests::to_ulong(b);
  65. }
  66. { // case overflow
  67. boost::dynamic_bitset<Block> b(long_string);
  68. Tests::to_ulong(b);
  69. }
  70. //=====================================================================
  71. // Test to_string(b, str)
  72. {
  73. boost::dynamic_bitset<Block> b;
  74. Tests::to_string(b);
  75. }
  76. {
  77. boost::dynamic_bitset<Block> b(std::string("0"));
  78. Tests::to_string(b);
  79. }
  80. {
  81. boost::dynamic_bitset<Block> b(long_string);
  82. Tests::to_string(b);
  83. }
  84. //=====================================================================
  85. // Test b.count()
  86. {
  87. boost::dynamic_bitset<Block> b;
  88. Tests::count(b);
  89. }
  90. {
  91. boost::dynamic_bitset<Block> b(std::string("0"));
  92. Tests::count(b);
  93. }
  94. {
  95. boost::dynamic_bitset<Block> b(std::string("1"));
  96. Tests::count(b);
  97. }
  98. {
  99. boost::dynamic_bitset<Block> b(8, 255ul);
  100. Tests::count(b);
  101. }
  102. {
  103. boost::dynamic_bitset<Block> b(long_string);
  104. Tests::count(b);
  105. }
  106. //=====================================================================
  107. // Test b.size()
  108. {
  109. boost::dynamic_bitset<Block> b;
  110. Tests::size(b);
  111. }
  112. {
  113. boost::dynamic_bitset<Block> b(std::string("0"));
  114. Tests::size(b);
  115. }
  116. {
  117. boost::dynamic_bitset<Block> b(long_string);
  118. Tests::size(b);
  119. }
  120. //=====================================================================
  121. // Test b.capacity()
  122. {
  123. boost::dynamic_bitset<Block> b;
  124. Tests::capacity_test_one(b);
  125. }
  126. {
  127. boost::dynamic_bitset<Block> b(100);
  128. Tests::capacity_test_two(b);
  129. }
  130. //=====================================================================
  131. // Test b.reserve()
  132. {
  133. boost::dynamic_bitset<Block> b;
  134. Tests::reserve_test_one(b);
  135. }
  136. {
  137. boost::dynamic_bitset<Block> b(100);
  138. Tests::reserve_test_two(b);
  139. }
  140. //=====================================================================
  141. // Test b.shrink_to_fit()
  142. {
  143. boost::dynamic_bitset<Block> b;
  144. Tests::shrink_to_fit_test_one(b);
  145. }
  146. {
  147. boost::dynamic_bitset<Block> b(100);
  148. Tests::shrink_to_fit_test_two(b);
  149. }
  150. //=====================================================================
  151. // Test b.all()
  152. {
  153. boost::dynamic_bitset<Block> b;
  154. Tests::all(b);
  155. Tests::all(~b);
  156. Tests::all(b.set());
  157. Tests::all(b.reset());
  158. }
  159. {
  160. boost::dynamic_bitset<Block> b(std::string("0"));
  161. Tests::all(b);
  162. Tests::all(~b);
  163. Tests::all(b.set());
  164. Tests::all(b.reset());
  165. }
  166. {
  167. boost::dynamic_bitset<Block> b(long_string);
  168. Tests::all(b);
  169. Tests::all(~b);
  170. Tests::all(b.set());
  171. Tests::all(b.reset());
  172. }
  173. //=====================================================================
  174. // Test b.any()
  175. {
  176. boost::dynamic_bitset<Block> b;
  177. Tests::any(b);
  178. Tests::any(~b);
  179. Tests::any(b.set());
  180. Tests::any(b.reset());
  181. }
  182. {
  183. boost::dynamic_bitset<Block> b(std::string("0"));
  184. Tests::any(b);
  185. Tests::any(~b);
  186. Tests::any(b.set());
  187. Tests::any(b.reset());
  188. }
  189. {
  190. boost::dynamic_bitset<Block> b(long_string);
  191. Tests::any(b);
  192. Tests::any(~b);
  193. Tests::any(b.set());
  194. Tests::any(b.reset());
  195. }
  196. //=====================================================================
  197. // Test b.none()
  198. {
  199. boost::dynamic_bitset<Block> b;
  200. Tests::none(b);
  201. Tests::none(~b);
  202. Tests::none(b.set());
  203. Tests::none(b.reset());
  204. }
  205. {
  206. boost::dynamic_bitset<Block> b(std::string("0"));
  207. Tests::none(b);
  208. Tests::none(~b);
  209. Tests::none(b.set());
  210. Tests::none(b.reset());
  211. }
  212. {
  213. boost::dynamic_bitset<Block> b(long_string);
  214. Tests::none(b);
  215. Tests::none(~b);
  216. Tests::none(b.set());
  217. Tests::none(b.reset());
  218. }
  219. //=====================================================================
  220. // Test a.is_subset_of(b)
  221. {
  222. boost::dynamic_bitset<Block> a, b;
  223. Tests::subset(a, b);
  224. }
  225. {
  226. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  227. Tests::subset(a, b);
  228. }
  229. {
  230. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  231. Tests::subset(a, b);
  232. }
  233. {
  234. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  235. Tests::subset(a, b);
  236. }
  237. {
  238. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  239. a[long_string.size()/2].flip();
  240. Tests::subset(a, b);
  241. }
  242. {
  243. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  244. b[long_string.size()/2].flip();
  245. Tests::subset(a, b);
  246. }
  247. //=====================================================================
  248. // Test a.is_proper_subset_of(b)
  249. {
  250. boost::dynamic_bitset<Block> a, b;
  251. Tests::proper_subset(a, b);
  252. }
  253. {
  254. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  255. Tests::proper_subset(a, b);
  256. }
  257. {
  258. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  259. Tests::proper_subset(a, b);
  260. }
  261. {
  262. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  263. Tests::proper_subset(a, b);
  264. }
  265. {
  266. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  267. a[long_string.size()/2].flip();
  268. Tests::proper_subset(a, b);
  269. }
  270. {
  271. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  272. b[long_string.size()/2].flip();
  273. Tests::proper_subset(a, b);
  274. }
  275. //=====================================================================
  276. // Test intersects
  277. {
  278. bitset_type a; // empty
  279. bitset_type b;
  280. Tests::intersects(a, b);
  281. }
  282. {
  283. bitset_type a;
  284. bitset_type b(5, 8ul);
  285. Tests::intersects(a, b);
  286. }
  287. {
  288. bitset_type a(8, 0ul);
  289. bitset_type b(15, 0ul);
  290. b[9] = 1;
  291. Tests::intersects(a, b);
  292. }
  293. {
  294. bitset_type a(15, 0ul);
  295. bitset_type b(22, 0ul);
  296. a[14] = b[14] = 1;
  297. Tests::intersects(a, b);
  298. }
  299. //=====================================================================
  300. // Test find_first
  301. {
  302. // empty bitset
  303. bitset_type b;
  304. Tests::find_first(b);
  305. }
  306. {
  307. // bitset of size 1
  308. bitset_type b(1, 1ul);
  309. Tests::find_first(b);
  310. }
  311. {
  312. // all-0s bitset
  313. bitset_type b(4 * bitset_type::bits_per_block, 0ul);
  314. Tests::find_first(b);
  315. }
  316. {
  317. // first bit on
  318. bitset_type b(1, 1ul);
  319. Tests::find_first(b);
  320. }
  321. {
  322. // last bit on
  323. bitset_type b(4 * bitset_type::bits_per_block - 1, 0ul);
  324. b.set(b.size() - 1);
  325. Tests::find_first(b);
  326. }
  327. //=====================================================================
  328. // Test find_next
  329. {
  330. // empty bitset
  331. bitset_type b;
  332. // check
  333. Tests::find_next(b, 0);
  334. Tests::find_next(b, 1);
  335. Tests::find_next(b, 200);
  336. Tests::find_next(b, b.npos);
  337. }
  338. {
  339. // bitset of size 1 (find_next can never find)
  340. bitset_type b(1, 1ul);
  341. // check
  342. Tests::find_next(b, 0);
  343. Tests::find_next(b, 1);
  344. Tests::find_next(b, 200);
  345. Tests::find_next(b, b.npos);
  346. }
  347. {
  348. // all-1s bitset
  349. bitset_type b(16 * bitset_type::bits_per_block);
  350. b.set();
  351. // check
  352. const typename bitset_type::size_type larger_than_size = 5 + b.size();
  353. for(typename bitset_type::size_type i = 0; i <= larger_than_size; ++i) {
  354. Tests::find_next(b, i);
  355. }
  356. Tests::find_next(b, b.npos);
  357. }
  358. {
  359. // a bitset with 1s at block boundary only
  360. const int num_blocks = 32;
  361. const int block_width = bitset_type::bits_per_block;
  362. bitset_type b(num_blocks * block_width);
  363. typename bitset_type::size_type i = block_width - 1;
  364. for ( ; i < b.size(); i += block_width) {
  365. b.set(i);
  366. typename bitset_type::size_type first_in_block = i - (block_width - 1);
  367. b.set(first_in_block);
  368. }
  369. // check
  370. const typename bitset_type::size_type larger_than_size = 5 + b.size();
  371. for (i = 0; i <= larger_than_size; ++i) {
  372. Tests::find_next(b, i);
  373. }
  374. Tests::find_next(b, b.npos);
  375. }
  376. {
  377. // bitset with alternate 1s and 0s
  378. const typename bitset_type::size_type sz = 1000;
  379. bitset_type b(sz);
  380. typename bitset_type::size_type i = 0;
  381. for ( ; i < sz; ++i) {
  382. b[i] = (i%2 == 0);
  383. }
  384. // check
  385. const typename bitset_type::size_type larger_than_size = 5 + b.size();
  386. for (i = 0; i <= larger_than_size; ++i) {
  387. Tests::find_next(b, i);
  388. }
  389. Tests::find_next(b, b.npos);
  390. }
  391. //=====================================================================
  392. // Test operator==
  393. {
  394. boost::dynamic_bitset<Block> a, b;
  395. Tests::operator_equal(a, b);
  396. }
  397. {
  398. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  399. Tests::operator_equal(a, b);
  400. }
  401. {
  402. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  403. Tests::operator_equal(a, b);
  404. }
  405. {
  406. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  407. Tests::operator_equal(a, b);
  408. }
  409. {
  410. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  411. a[long_string.size()/2].flip();
  412. Tests::operator_equal(a, b);
  413. }
  414. {
  415. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  416. b[long_string.size()/2].flip();
  417. Tests::operator_equal(a, b);
  418. }
  419. //=====================================================================
  420. // Test operator!=
  421. {
  422. boost::dynamic_bitset<Block> a, b;
  423. Tests::operator_not_equal(a, b);
  424. }
  425. {
  426. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  427. Tests::operator_not_equal(a, b);
  428. }
  429. {
  430. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  431. Tests::operator_not_equal(a, b);
  432. }
  433. {
  434. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  435. Tests::operator_not_equal(a, b);
  436. }
  437. {
  438. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  439. a[long_string.size()/2].flip();
  440. Tests::operator_not_equal(a, b);
  441. }
  442. {
  443. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  444. b[long_string.size()/2].flip();
  445. Tests::operator_not_equal(a, b);
  446. }
  447. //=====================================================================
  448. // Test operator<
  449. {
  450. boost::dynamic_bitset<Block> a, b;
  451. Tests::operator_less_than(a, b);
  452. }
  453. {
  454. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  455. Tests::operator_less_than(a, b);
  456. }
  457. {
  458. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  459. Tests::operator_less_than(a, b);
  460. }
  461. {
  462. boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("11"));
  463. Tests::operator_less_than(a, b);
  464. }
  465. {
  466. boost::dynamic_bitset<Block> a(std::string("101")), b(std::string("11"));
  467. Tests::operator_less_than(a, b);
  468. }
  469. {
  470. boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("111"));
  471. Tests::operator_less_than(a, b);
  472. }
  473. {
  474. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  475. Tests::operator_less_than(a, b);
  476. }
  477. {
  478. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  479. a[long_string.size()/2].flip();
  480. Tests::operator_less_than(a, b);
  481. }
  482. {
  483. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  484. b[long_string.size()/2].flip();
  485. Tests::operator_less_than(a, b);
  486. }
  487. // check for consistency with ulong behaviour when the sizes are equal
  488. {
  489. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
  490. assert(a < b);
  491. }
  492. {
  493. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
  494. assert(!(a < b));
  495. }
  496. {
  497. boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
  498. assert(!(a < b));
  499. }
  500. // when the sizes are not equal lexicographic compare does not necessarily correspond to ulong behavior
  501. {
  502. boost::dynamic_bitset<Block> a(4, 4ul), b(3, 5ul);
  503. assert(a < b);
  504. }
  505. {
  506. boost::dynamic_bitset<Block> a(3, 4ul), b(4, 5ul);
  507. assert(!(a < b));
  508. }
  509. {
  510. boost::dynamic_bitset<Block> a(4, 4ul), b(3, 4ul);
  511. assert(a < b);
  512. }
  513. {
  514. boost::dynamic_bitset<Block> a(3, 4ul), b(4, 4ul);
  515. assert(!(a < b));
  516. }
  517. {
  518. boost::dynamic_bitset<Block> a(4, 5ul), b(3, 4ul);
  519. assert(a < b);
  520. }
  521. {
  522. boost::dynamic_bitset<Block> a(3, 5ul), b(4, 4ul);
  523. assert(!(a < b));
  524. }
  525. //=====================================================================
  526. // Test operator<=
  527. {
  528. boost::dynamic_bitset<Block> a, b;
  529. Tests::operator_less_than_eq(a, b);
  530. }
  531. {
  532. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  533. Tests::operator_less_than_eq(a, b);
  534. }
  535. {
  536. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  537. Tests::operator_less_than_eq(a, b);
  538. }
  539. {
  540. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  541. Tests::operator_less_than_eq(a, b);
  542. }
  543. {
  544. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  545. a[long_string.size()/2].flip();
  546. Tests::operator_less_than_eq(a, b);
  547. }
  548. {
  549. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  550. b[long_string.size()/2].flip();
  551. Tests::operator_less_than_eq(a, b);
  552. }
  553. // check for consistency with ulong behaviour
  554. {
  555. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
  556. assert(a <= b);
  557. }
  558. {
  559. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
  560. assert(a <= b);
  561. }
  562. {
  563. boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
  564. assert(!(a <= b));
  565. }
  566. //=====================================================================
  567. // Test operator>
  568. {
  569. boost::dynamic_bitset<Block> a, b;
  570. Tests::operator_greater_than(a, b);
  571. }
  572. {
  573. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  574. Tests::operator_greater_than(a, b);
  575. }
  576. {
  577. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  578. Tests::operator_greater_than(a, b);
  579. }
  580. {
  581. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  582. Tests::operator_greater_than(a, b);
  583. }
  584. {
  585. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  586. a[long_string.size()/2].flip();
  587. Tests::operator_greater_than(a, b);
  588. }
  589. {
  590. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  591. b[long_string.size()/2].flip();
  592. Tests::operator_greater_than(a, b);
  593. }
  594. // check for consistency with ulong behaviour
  595. {
  596. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
  597. assert(!(a > b));
  598. }
  599. {
  600. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
  601. assert(!(a > b));
  602. }
  603. {
  604. boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
  605. assert(a > b);
  606. }
  607. //=====================================================================
  608. // Test operator<=
  609. {
  610. boost::dynamic_bitset<Block> a, b;
  611. Tests::operator_greater_than_eq(a, b);
  612. }
  613. {
  614. boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
  615. Tests::operator_greater_than_eq(a, b);
  616. }
  617. {
  618. boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
  619. Tests::operator_greater_than_eq(a, b);
  620. }
  621. {
  622. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  623. Tests::operator_greater_than_eq(a, b);
  624. }
  625. {
  626. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  627. a[long_string.size()/2].flip();
  628. Tests::operator_greater_than_eq(a, b);
  629. }
  630. {
  631. boost::dynamic_bitset<Block> a(long_string), b(long_string);
  632. b[long_string.size()/2].flip();
  633. Tests::operator_greater_than_eq(a, b);
  634. }
  635. // check for consistency with ulong behaviour
  636. {
  637. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
  638. assert(!(a >= b));
  639. }
  640. {
  641. boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
  642. assert(a >= b);
  643. }
  644. {
  645. boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
  646. assert(a >= b);
  647. }
  648. //=====================================================================
  649. // Test b.test(pos)
  650. { // case pos >= b.size()
  651. boost::dynamic_bitset<Block> b;
  652. Tests::test_bit(b, 0);
  653. }
  654. { // case pos < b.size()
  655. boost::dynamic_bitset<Block> b(std::string("0"));
  656. Tests::test_bit(b, 0);
  657. }
  658. { // case pos == b.size() / 2
  659. boost::dynamic_bitset<Block> b(long_string);
  660. Tests::test_bit(b, long_string.size()/2);
  661. }
  662. //=====================================================================
  663. // Test b.test_set(pos)
  664. { // case pos >= b.size()
  665. boost::dynamic_bitset<Block> b;
  666. Tests::test_set_bit(b, 0, true);
  667. Tests::test_set_bit(b, 0, false);
  668. }
  669. { // case pos < b.size()
  670. boost::dynamic_bitset<Block> b(std::string("0"));
  671. Tests::test_set_bit(b, 0, true);
  672. Tests::test_set_bit(b, 0, false);
  673. }
  674. { // case pos == b.size() / 2
  675. boost::dynamic_bitset<Block> b(long_string);
  676. Tests::test_set_bit(b, long_string.size() / 2, true);
  677. Tests::test_set_bit(b, long_string.size() / 2, false);
  678. }
  679. //=====================================================================
  680. // Test b << pos
  681. { // case pos == 0
  682. std::size_t pos = 0;
  683. boost::dynamic_bitset<Block> b(std::string("1010"));
  684. Tests::operator_shift_left(b, pos);
  685. }
  686. { // case pos == size()/2
  687. std::size_t pos = long_string.size() / 2;
  688. boost::dynamic_bitset<Block> b(long_string);
  689. Tests::operator_shift_left(b, pos);
  690. }
  691. { // case pos >= n
  692. std::size_t pos = long_string.size();
  693. boost::dynamic_bitset<Block> b(long_string);
  694. Tests::operator_shift_left(b, pos);
  695. }
  696. //=====================================================================
  697. // Test b >> pos
  698. { // case pos == 0
  699. std::size_t pos = 0;
  700. boost::dynamic_bitset<Block> b(std::string("1010"));
  701. Tests::operator_shift_right(b, pos);
  702. }
  703. { // case pos == size()/2
  704. std::size_t pos = long_string.size() / 2;
  705. boost::dynamic_bitset<Block> b(long_string);
  706. Tests::operator_shift_right(b, pos);
  707. }
  708. { // case pos >= n
  709. std::size_t pos = long_string.size();
  710. boost::dynamic_bitset<Block> b(long_string);
  711. Tests::operator_shift_right(b, pos);
  712. }
  713. //=====================================================================
  714. // Test a & b
  715. {
  716. boost::dynamic_bitset<Block> lhs, rhs;
  717. Tests::operator_and(lhs, rhs);
  718. }
  719. {
  720. boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
  721. Tests::operator_and(lhs, rhs);
  722. }
  723. {
  724. boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
  725. Tests::operator_and(lhs, rhs);
  726. }
  727. {
  728. boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
  729. Tests::operator_and(lhs, rhs);
  730. }
  731. //=====================================================================
  732. // Test a | b
  733. {
  734. boost::dynamic_bitset<Block> lhs, rhs;
  735. Tests::operator_or(lhs, rhs);
  736. }
  737. {
  738. boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
  739. Tests::operator_or(lhs, rhs);
  740. }
  741. {
  742. boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
  743. Tests::operator_or(lhs, rhs);
  744. }
  745. {
  746. boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
  747. Tests::operator_or(lhs, rhs);
  748. }
  749. //=====================================================================
  750. // Test a^b
  751. {
  752. boost::dynamic_bitset<Block> lhs, rhs;
  753. Tests::operator_xor(lhs, rhs);
  754. }
  755. {
  756. boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
  757. Tests::operator_xor(lhs, rhs);
  758. }
  759. {
  760. boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
  761. Tests::operator_xor(lhs, rhs);
  762. }
  763. {
  764. boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
  765. Tests::operator_xor(lhs, rhs);
  766. }
  767. //=====================================================================
  768. // Test a-b
  769. {
  770. boost::dynamic_bitset<Block> lhs, rhs;
  771. Tests::operator_sub(lhs, rhs);
  772. }
  773. {
  774. boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
  775. Tests::operator_sub(lhs, rhs);
  776. }
  777. {
  778. boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
  779. Tests::operator_sub(lhs, rhs);
  780. }
  781. {
  782. boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
  783. Tests::operator_sub(lhs, rhs);
  784. }
  785. }
  786. int
  787. main()
  788. {
  789. run_test_cases<unsigned char>();
  790. run_test_cases<unsigned short>();
  791. run_test_cases<unsigned int>();
  792. run_test_cases<unsigned long>();
  793. # ifdef BOOST_HAS_LONG_LONG
  794. run_test_cases< ::boost::ulong_long_type>();
  795. # endif
  796. return boost::report_errors();
  797. }