make bitSet more comnpatible with Java implementation.

This commit is contained in:
Marty Kraimer
2013-10-31 06:03:51 -04:00
parent db10bed951
commit 0f17bd23c7
5 changed files with 189 additions and 75 deletions

View File

@@ -6,6 +6,7 @@
*/
/* Author: Matej Sekoranja Date: 2010.10.18 */
#include <iostream>
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
@@ -96,12 +97,16 @@ void testOperators(FILE *fd) {
assert(b1 == b2);
// OR test
b1.set(65);
b1.set(106);
b2.set(65);
b2.set(106);
b2.set(105);
b1 |= b2;
std::string str; b1.toString(&str);
assert(str == "{1, 65, 105, 106}");
b1.clear();
b1 |= b2;
str.clear(); b1.toString(&str);
assert(str == "{1, 65, 105, 106}");
// AND test
b1.set(128);
@@ -112,15 +117,13 @@ void testOperators(FILE *fd) {
b1.set(128);
b1 ^= b2;
assert(b1.cardinality() == 1 && b1.get(128) == true);
// a AND (NOT b)
b2 -= b1;
str.clear(); b2.toString(&str);
assert(str == "{1, 105}");
b1.clear();
b2.clear();
b1.set(1);
b2 -= b1;
str.clear(); b2.toString(&str);
assert(b2.cardinality() == 1 && b2.get(105) == true);
b2.set(256);
b1 ^= b2;
assert(b1.cardinality() == 2 && b1.get(1) == true && b1.get(256) == true);
// assign
b1 = b2;