From ec390bfc5896a7f764230be8c76e08a155b08b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sun, 4 Jan 2015 12:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90bitmap=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/BitmapTest.cpp | 94 +++++++++++++++++++++++++++++++++++++ TinySTL/Test/BitmapTest.h | 26 ++++++++++ 2 files changed, 120 insertions(+) create mode 100644 TinySTL/Test/BitmapTest.cpp create mode 100644 TinySTL/Test/BitmapTest.h diff --git a/TinySTL/Test/BitmapTest.cpp b/TinySTL/Test/BitmapTest.cpp new file mode 100644 index 0000000..9755eba --- /dev/null +++ b/TinySTL/Test/BitmapTest.cpp @@ -0,0 +1,94 @@ +#include "BitmapTest.h" + +namespace TinySTL{ + namespace BitmapTest{ + void testCase1(){ + bitmap<1> bt1; + assert(bt1.size() == 8); + + bitmap<7> bt2; + assert(bt2.size() == 8); + + bitmap<127> bt3; + assert(bt3.size() == 128); + } + void testCase2(){ + bitmap<8> bt1, bt2; + bt1.set(); + cout << bt1 << endl; + bt1.reset(); + cout << bt1 << endl; + + bt2.set(0); bt2.set(2); bt2.set(4); + cout << bt2 << endl; + bt2.reset(0); bt2.reset(2); bt2.reset(4); + cout << bt2 << endl; + } + void testCase3(){ + bitmap<8> bt; + bt.flip(); + cout << bt << endl; + + bt.flip(0); + cout << bt << endl; + } + void testCase4(){ + bitmap<8> bt; + bt.set(); + assert(bt.count() == 8); + + bt.flip(); + assert(bt.count() == 0); + + bt.set(0); + assert(bt.count() == 1); + } + void testCase5(){ + bitmap<8> bt; + assert(!bt.test(0)); + + bt.set(0); + assert(bt.test(0)); + } + void testCase6(){ + bitmap<8> bt; + assert(!bt.any()); + assert(bt.none()); + assert(!bt.all()); + + bt.set(0); + assert(bt.any()); + assert(!bt.none()); + assert(!bt.all()); + + bt.set(); + assert(bt.any()); + assert(!bt.none()); + assert(bt.all()); + + bt.reset(); + assert(!bt.any()); + assert(bt.none()); + assert(!bt.all()); + } + void testCase7(){ + bitmap<8> bt; + bt.set(0); bt.set(2); bt.set(4); bt.set(6); + assert(bt.to_string() == TinySTL::string("10101010")); + } + } +} + +using namespace TinySTL::BitmapTest; +int main(){ + //testCase1(); + //testCase2(); + //testCase3(); + //testCase4(); + //testCase5(); + //testCase6(); + //testCase7(); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/TinySTL/Test/BitmapTest.h b/TinySTL/Test/BitmapTest.h new file mode 100644 index 0000000..43d4340 --- /dev/null +++ b/TinySTL/Test/BitmapTest.h @@ -0,0 +1,26 @@ +#ifndef _BITMAP_TEST_H_ +#define _BITMAP_TEST_H_ + +#include "TestUtil.h" + +#include "../Bitmap.h" + +#include +#include + +namespace TinySTL{ + namespace BitmapTest{ + using std::cout; + using std::endl; + + void testCase1(); + void testCase2(); + void testCase3(); + void testCase4(); + void testCase5(); + void testCase6(); + void testCase7(); + } +} + +#endif \ No newline at end of file