00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <getopt.h>
00019 #include "Generic.h"
00020 #include <stdio.h>
00021 #include "PackedVector.h"
00022 #include "UnitTest.h"
00023
00024 #include <assert.h>
00025 #include <stdlib.h>
00026
00027 class PackedArrayTest : public UnitTest
00028 {
00029 public:
00030 PackedArrayTest(const char *title) : UnitTest(title) {;}
00031 void testBool();
00032 void test2Bit();
00033 void test4Bit();
00034 void testResize();
00035
00036 void test() {
00037 testBool();
00038 test2Bit();
00039 test4Bit();
00040 testResize();
00041 }
00042 };
00043
00044 void PackedArrayTest::testBool(void)
00045 {
00046 PackedVectorBool_t testVector;
00047
00048 testVector.resize(11);
00049 testVector.set(0,0);
00050 testVector.set(1,1);
00051 testVector.set(2,0);
00052 testVector.set(3,1);
00053 testVector.set(4,1);
00054 testVector.set(5,0);
00055 testVector.set(6,1);
00056 testVector.set(7,0);
00057 testVector.set(8,0);
00058 testVector.set(9,0);
00059 testVector.set(10,1);
00060 check(m_failures, ++m_testNum, "Access 1 bit element 0", 0U, testVector[0]);
00061 check(m_failures, ++m_testNum, "Access 1 bit element 1", 1U, testVector[1]);
00062 check(m_failures, ++m_testNum, "Access 1 bit element 2", 0U, testVector[2]);
00063 check(m_failures, ++m_testNum, "Access 1 bit element 3", 1U, testVector[3]);
00064 check(m_failures, ++m_testNum, "Access 1 bit element 4", 1U, testVector[4]);
00065 check(m_failures, ++m_testNum, "Access 1 bit element 5", 0U, testVector[5]);
00066 check(m_failures, ++m_testNum, "Access 1 bit element 6", 1U, testVector[6]);
00067 check(m_failures, ++m_testNum, "Access 1 bit element 7", 0U, testVector[7]);
00068 check(m_failures, ++m_testNum, "Access 1 bit element 8", 0U, testVector[8]);
00069 check(m_failures, ++m_testNum, "Access 1 bit element 9", 0U, testVector[9]);
00070 check(m_failures, ++m_testNum, "Access 1 bit element 10", 1U, testVector[10]);
00071 }
00072
00073 void PackedArrayTest::test2Bit(void)
00074 {
00075 PackedVector2Bit_t testVector;
00076
00077 testVector.resize(11);
00078 testVector.set(0,0);
00079 testVector.set(1,1);
00080 testVector.set(2,2);
00081 testVector.set(3,3);
00082 testVector.set(4,3);
00083 testVector.set(5,2);
00084 testVector.set(6,1);
00085 testVector.set(7,0);
00086 testVector.set(8,2);
00087 testVector.set(9,1);
00088 testVector.set(10,3);
00089 check(m_failures, ++m_testNum, "Access 2 bit element 0", 0U, testVector[0]);
00090 check(m_failures, ++m_testNum, "Access 2 bit element 1", 1U, testVector[1]);
00091 check(m_failures, ++m_testNum, "Access 2 bit element 2", 2U, testVector[2]);
00092 check(m_failures, ++m_testNum, "Access 2 bit element 3", 3U, testVector[3]);
00093 check(m_failures, ++m_testNum, "Access 2 bit element 4", 3U, testVector[4]);
00094 check(m_failures, ++m_testNum, "Access 2 bit element 5", 2U, testVector[5]);
00095 check(m_failures, ++m_testNum, "Access 2 bit element 6", 1U, testVector[6]);
00096 check(m_failures, ++m_testNum, "Access 2 bit element 7", 0U, testVector[7]);
00097 check(m_failures, ++m_testNum, "Access 2 bit element 8", 2U, testVector[8]);
00098 check(m_failures, ++m_testNum, "Access 2 bit element 9", 1U, testVector[9]);
00099 check(m_failures, ++m_testNum, "Access 2 bit element 10", 3U, testVector[10]);
00100 }
00101
00102 void PackedArrayTest::test4Bit(void)
00103 {
00104 PackedVector4Bit_t testVector;
00105
00106 testVector.resize(11);
00107 testVector.set(0,0);
00108 testVector.set(1,1);
00109 testVector.set(2,2);
00110 testVector.set(3,3);
00111 testVector.set(4,4);
00112 testVector.set(5,5);
00113 testVector.set(6,6);
00114 testVector.set(7,7);
00115 testVector.set(8,8);
00116 testVector.set(9,9);
00117 testVector.set(10,10);
00118
00119 check(m_failures, ++m_testNum, "Access 4 bit element 0", 0U, testVector[0]);
00120 check(m_failures, ++m_testNum, "Access 4 bit element 1", 1U, testVector[1]);
00121 check(m_failures, ++m_testNum, "Access 4 bit element 2", 2U, testVector[2]);
00122 check(m_failures, ++m_testNum, "Access 4 bit element 3", 3U, testVector[3]);
00123 check(m_failures, ++m_testNum, "Access 4 bit element 4", 4U, testVector[4]);
00124 check(m_failures, ++m_testNum, "Access 4 bit element 5", 5U, testVector[5]);
00125 check(m_failures, ++m_testNum, "Access 4 bit element 6", 6U, testVector[6]);
00126 check(m_failures, ++m_testNum, "Access 4 bit element 7", 7U, testVector[7]);
00127 check(m_failures, ++m_testNum, "Access 4 bit element 8", 8U, testVector[8]);
00128 check(m_failures, ++m_testNum, "Access 4 bit element 9", 9U, testVector[9]);
00129 check(m_failures, ++m_testNum, "Access 4 bit element 10", 10U, testVector[10]);
00130 }
00131
00132 void PackedArrayTest::testResize(void)
00133 {
00134 PackedVector4Bit_t testVector;
00135
00136 testVector.resize(0);
00137 check(m_failures, ++m_testNum, "New size is 0", 0U, testVector.size());
00138
00139 testVector.push_back(0);
00140 testVector.push_back(1);
00141 testVector.push_back(2);
00142 testVector.push_back(3);
00143 testVector.push_back(4);
00144 testVector.push_back(5);
00145 testVector.push_back(6);
00146 testVector.push_back(7);
00147 testVector.push_back(8);
00148 testVector.push_back(9);
00149 testVector.push_back(10);
00150
00151 check(m_failures, ++m_testNum, "New size is 11", 11U, testVector.size());
00152
00153 check(m_failures, ++m_testNum, "Access 4 bit element 0", 0U, testVector[0]);
00154 check(m_failures, ++m_testNum, "Access 4 bit element 1", 1U, testVector[1]);
00155 check(m_failures, ++m_testNum, "Access 4 bit element 2", 2U, testVector[2]);
00156 check(m_failures, ++m_testNum, "Access 4 bit element 3", 3U, testVector[3]);
00157 check(m_failures, ++m_testNum, "Access 4 bit element 4", 4U, testVector[4]);
00158 check(m_failures, ++m_testNum, "Access 4 bit element 5", 5U, testVector[5]);
00159 check(m_failures, ++m_testNum, "Access 4 bit element 6", 6U, testVector[6]);
00160 check(m_failures, ++m_testNum, "Access 4 bit element 7", 7U, testVector[7]);
00161 check(m_failures, ++m_testNum, "Access 4 bit element 8", 8U, testVector[8]);
00162 check(m_failures, ++m_testNum, "Access 4 bit element 9", 9U, testVector[9]);
00163 check(m_failures, ++m_testNum, "Access 4 bit element 10", 10U, testVector[10]);
00164 }
00165
00166 int main(int argc, char **argv)
00167 {
00168 PackedArrayTest test("PackedArrayTest");
00169 #if 0
00170 bool showAllCasesFlag = false;
00171 int opt;
00172
00173 while(( opt = getopt(argc, (char **) argv, "v")) != -1) {
00174 switch(opt) {
00175 case 'v':
00176 showAllCasesFlag = true;
00177 break;
00178 default:
00179 std::cerr << "usage: testSW [-v]" << std::endl;
00180 exit(1);
00181 }
00182 }
00183
00184 #endif
00185
00186 test.test();
00187
00188 std::cout << test;
00189
00190 exit(test.getFailureCount());
00191 }