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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
* Copyright (C) 2010 Regents of the University of Michigan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <getopt.h>
#include "Generic.h"
#include <stdio.h>
#include "PackedVector.h"
#include "UnitTest.h"
#include <assert.h>
#include <stdlib.h>
class PackedArrayTest : public UnitTest
{
public:
PackedArrayTest(const char *title) : UnitTest(title) {;}
void testBool();
void test2Bit();
void test4Bit();
void testResize();
void test() {
testBool();
test2Bit();
test4Bit();
testResize();
}
};
void PackedArrayTest::testBool(void)
{
PackedVectorBool_t testVector;
testVector.resize(11);
testVector.set(0,0);
testVector.set(1,1);
testVector.set(2,0);
testVector.set(3,1);
testVector.set(4,1);
testVector.set(5,0);
testVector.set(6,1);
testVector.set(7,0);
testVector.set(8,0);
testVector.set(9,0);
testVector.set(10,1);
check(m_failures, ++m_testNum, "Access 1 bit element 0", 0U, testVector[0]);
check(m_failures, ++m_testNum, "Access 1 bit element 1", 1U, testVector[1]);
check(m_failures, ++m_testNum, "Access 1 bit element 2", 0U, testVector[2]);
check(m_failures, ++m_testNum, "Access 1 bit element 3", 1U, testVector[3]);
check(m_failures, ++m_testNum, "Access 1 bit element 4", 1U, testVector[4]);
check(m_failures, ++m_testNum, "Access 1 bit element 5", 0U, testVector[5]);
check(m_failures, ++m_testNum, "Access 1 bit element 6", 1U, testVector[6]);
check(m_failures, ++m_testNum, "Access 1 bit element 7", 0U, testVector[7]);
check(m_failures, ++m_testNum, "Access 1 bit element 8", 0U, testVector[8]);
check(m_failures, ++m_testNum, "Access 1 bit element 9", 0U, testVector[9]);
check(m_failures, ++m_testNum, "Access 1 bit element 10", 1U, testVector[10]);
}
void PackedArrayTest::test2Bit(void)
{
PackedVector2Bit_t testVector;
testVector.resize(11);
testVector.set(0,0);
testVector.set(1,1);
testVector.set(2,2);
testVector.set(3,3);
testVector.set(4,3);
testVector.set(5,2);
testVector.set(6,1);
testVector.set(7,0);
testVector.set(8,2);
testVector.set(9,1);
testVector.set(10,3);
check(m_failures, ++m_testNum, "Access 2 bit element 0", 0U, testVector[0]);
check(m_failures, ++m_testNum, "Access 2 bit element 1", 1U, testVector[1]);
check(m_failures, ++m_testNum, "Access 2 bit element 2", 2U, testVector[2]);
check(m_failures, ++m_testNum, "Access 2 bit element 3", 3U, testVector[3]);
check(m_failures, ++m_testNum, "Access 2 bit element 4", 3U, testVector[4]);
check(m_failures, ++m_testNum, "Access 2 bit element 5", 2U, testVector[5]);
check(m_failures, ++m_testNum, "Access 2 bit element 6", 1U, testVector[6]);
check(m_failures, ++m_testNum, "Access 2 bit element 7", 0U, testVector[7]);
check(m_failures, ++m_testNum, "Access 2 bit element 8", 2U, testVector[8]);
check(m_failures, ++m_testNum, "Access 2 bit element 9", 1U, testVector[9]);
check(m_failures, ++m_testNum, "Access 2 bit element 10", 3U, testVector[10]);
}
void PackedArrayTest::test4Bit(void)
{
PackedVector4Bit_t testVector;
testVector.resize(11);
testVector.set(0,0);
testVector.set(1,1);
testVector.set(2,2);
testVector.set(3,3);
testVector.set(4,4);
testVector.set(5,5);
testVector.set(6,6);
testVector.set(7,7);
testVector.set(8,8);
testVector.set(9,9);
testVector.set(10,10);
check(m_failures, ++m_testNum, "Access 4 bit element 0", 0U, testVector[0]);
check(m_failures, ++m_testNum, "Access 4 bit element 1", 1U, testVector[1]);
check(m_failures, ++m_testNum, "Access 4 bit element 2", 2U, testVector[2]);
check(m_failures, ++m_testNum, "Access 4 bit element 3", 3U, testVector[3]);
check(m_failures, ++m_testNum, "Access 4 bit element 4", 4U, testVector[4]);
check(m_failures, ++m_testNum, "Access 4 bit element 5", 5U, testVector[5]);
check(m_failures, ++m_testNum, "Access 4 bit element 6", 6U, testVector[6]);
check(m_failures, ++m_testNum, "Access 4 bit element 7", 7U, testVector[7]);
check(m_failures, ++m_testNum, "Access 4 bit element 8", 8U, testVector[8]);
check(m_failures, ++m_testNum, "Access 4 bit element 9", 9U, testVector[9]);
check(m_failures, ++m_testNum, "Access 4 bit element 10", 10U, testVector[10]);
}
void PackedArrayTest::testResize(void)
{
PackedVector4Bit_t testVector;
testVector.resize(0);
check(m_failures, ++m_testNum, "New size is 0", 0U, testVector.size());
testVector.push_back(0);
testVector.push_back(1);
testVector.push_back(2);
testVector.push_back(3);
testVector.push_back(4);
testVector.push_back(5);
testVector.push_back(6);
testVector.push_back(7);
testVector.push_back(8);
testVector.push_back(9);
testVector.push_back(10);
check(m_failures, ++m_testNum, "New size is 11", 11U, testVector.size());
check(m_failures, ++m_testNum, "Access 4 bit element 0", 0U, testVector[0]);
check(m_failures, ++m_testNum, "Access 4 bit element 1", 1U, testVector[1]);
check(m_failures, ++m_testNum, "Access 4 bit element 2", 2U, testVector[2]);
check(m_failures, ++m_testNum, "Access 4 bit element 3", 3U, testVector[3]);
check(m_failures, ++m_testNum, "Access 4 bit element 4", 4U, testVector[4]);
check(m_failures, ++m_testNum, "Access 4 bit element 5", 5U, testVector[5]);
check(m_failures, ++m_testNum, "Access 4 bit element 6", 6U, testVector[6]);
check(m_failures, ++m_testNum, "Access 4 bit element 7", 7U, testVector[7]);
check(m_failures, ++m_testNum, "Access 4 bit element 8", 8U, testVector[8]);
check(m_failures, ++m_testNum, "Access 4 bit element 9", 9U, testVector[9]);
check(m_failures, ++m_testNum, "Access 4 bit element 10", 10U, testVector[10]);
}
int main(int argc, char **argv)
{
PackedArrayTest test("PackedArrayTest");
#if 0
bool showAllCasesFlag = false;
int opt;
while(( opt = getopt(argc, (char **) argv, "v")) != -1) {
switch(opt) {
case 'v':
showAllCasesFlag = true;
break;
default:
std::cerr << "usage: testSW [-v]" << std::endl;
exit(1);
}
}
#endif
test.test();
std::cout << test;
exit(test.getFailureCount());
}
|