1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include "BitmapTest.h"
#include "Bitmap.h"
CPPUNIT_TEST_SUITE_REGISTRATION (BitmapTest);
void BitmapTest::setUp()
{
// Put the bitmaps back in standard state
// (Need at least two as doing things like
// checking equality)
bitmap1.Zero();
bitmap2.Zero();
}
void BitmapTest::tearDown()
{
// Nothing to do
}
void BitmapTest::testEquals()
{
// They should be equals now - all zeros
CPPUNIT_ASSERT(bitmap1.Equals(bitmap2));
// Set one bit in each - the same bit
// They should still be equals!
bitmap1.SetBit(77);
bitmap2.SetBit(77);
CPPUNIT_ASSERT(bitmap1.Equals(bitmap2));
// Set a different bit
bitmap1.SetBit(22);
bitmap2.SetBit(123);
// Shouldn't be equals any more!
CPPUNIT_ASSERT(!bitmap1.Equals(bitmap2));
// The two bit maps should be cleaned out
// prior to next test (by next call to setUp)
bitmap1.Zero();
bitmap2.Zero();
CPPUNIT_ASSERT( bitmap1.Equals(bitmap2));
}
void BitmapTest::testSetBit()
{
// If set bit 0 in one, they should not be equal
bitmap1.SetBit(0);
CPPUNIT_ASSERT(!bitmap1.Equals(bitmap2));
// Just being pedantic - reverse roles in test
//CPPUNIT_ASSERT(!bitmap2.Equals(bitmap1));
bitmap1.Zero();
// But should be equal after it got cleared
CPPUNIT_ASSERT(bitmap1.Equals(bitmap2));
CPPUNIT_ASSERT(bitmap2.Equals(bitmap1));
// If set a non-existent bit it isn't supposed
// to change anything
bitmap1.SetBit(-1);
bitmap2.SetBit(513);
CPPUNIT_ASSERT(bitmap2.Equals(bitmap1));
}
void BitmapTest::testSetBitAndCount()
{
// Set some bits and check that count equals number of bits set
int bits1[] = { 0, 3, 17, 21, 33, 54, 68, 77, 91, 103, 211, 304 };
int bits2[] = { 0, 31, 32, 33, 63, 64, 65, 300, 400, 500, 511 };
int count1 = sizeof(bits1)/sizeof(int);
int count2 = sizeof(bits2)/sizeof(int);
for(int i=0;i<count1;i++)
bitmap1.SetBit(bits1[i]);
for(int i=0;i<count2;i++)
bitmap2.SetBit(bits2[i]);
CPPUNIT_ASSERT_EQUAL(count1, bitmap1.Count());
// Deliberate error to get a failed test
count1--;
CPPUNIT_ASSERT_EQUAL(count1, bitmap2.Count());
// Fixed to make it run
CPPUNIT_ASSERT_EQUAL(count2, bitmap2.Count());
}
void BitmapTest::testClearSetAsAndFlip(){
//Clear bit . Result same
bitmap1.ClearBit(-1);
bitmap2.ClearBit(513);
CPPUNIT_ASSERT( bitmap1.Equals(bitmap2));
//Set different value of bit, shouldn't be equal anymore!
bitmap1.SetBit(7);
bitmap2.SetBit(8);
CPPUNIT_ASSERT( !bitmap1.Equals(bitmap2));
// //Clear Bit
bitmap1.Zero();
bitmap2.Zero();
// //Clear Bit and result same
bitmap1.ClearBit(7);
bitmap1.ClearBit(-512);
CPPUNIT_ASSERT( bitmap1.Equals(bitmap2));
}
void BitmapTest::testInvert(){
//bitmap1.SetBit(200);
//bitmap2.SetBit(250);
}
|