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
|
#include <iostream>
const uint32_t arraySize = 8;
bool validate(const bool (&array)[arraySize])
{
uint8_t blockCntr = 0;
for(int32_t idx = 0; idx < arraySize; idx++)
{
if((array[idx] == true) && (array[(idx + 1) % arraySize] == false))
{
++blockCntr;
}
}
if(blockCntr == 1)
{
return true;
}
return false;
}
int main(int argc, char * argv[])
{
bool testData[][arraySize] =
{
{0, 0, 0, 0, 0, 0, 0, 0},//invalid
{1, 1, 1, 1, 1, 1, 1, 1},//invalid
{0, 1, 0, 1, 0, 1, 0, 1},//invalid
{1, 1, 0, 1, 1, 1, 0, 1},//invalid
{0, 0, 0, 0, 1, 1, 1, 0},//valid
{1, 0, 0, 0, 0, 0, 0, 0},//valid
{0, 0, 0, 0, 0, 0, 0, 1},//valid
{1, 0, 0, 0, 0, 0, 0, 1},//valid
{1, 1, 1, 0, 1, 1, 1, 1}//valid
};
uint8_t testDataSize = sizeof(testData) / sizeof(testData[0]);
std::cout << std::boolalpha;
for(int32_t idx = 0; idx < testDataSize; idx++)
{
std::cout << "test case " << idx + 1 << ": "
<< validate(testData[idx])
<< std::endl;
}
return 0;
}
|