Added CRC1 (AKA Parity)

Modified test suit names
This commit is contained in:
John Wellbelove 2023-12-08 09:03:17 +00:00
parent 9161413337
commit eba9c5797d
2 changed files with 18 additions and 6 deletions

View File

@ -47,14 +47,14 @@ namespace etl
enum
{
Odd_Parity = 1,
Even_Parity = 0
odd_parity = 1,
even_parity = 0
};
//*********************************
value_type initial() const
{
return Even_Parity;
return even_parity;
}
//*********************************
@ -76,8 +76,8 @@ namespace etl
enum
{
Odd_Parity = crc1_policy::Odd_Parity,
Even_Parity = crc1_policy::Even_Parity
odd_parity = crc1_policy::odd_parity,
even_parity = crc1_policy::even_parity
};
//*************************************************************************

View File

@ -37,6 +37,8 @@ SOFTWARE.
namespace
{
//***************************************************************************
// Calculate parity the simple way.
//***************************************************************************
template <typename TIterator>
int calculate_parity(TIterator b, TIterator e)
@ -49,7 +51,7 @@ namespace
++b;
}
return ((count &= 1) == 0) ? etl::crc1::Even_Parity : etl::crc1::Odd_Parity;
return ((count &= 1) == 0) ? etl::crc1::even_parity : etl::crc1::odd_parity;
}
SUITE(test_crc1)
@ -123,6 +125,16 @@ namespace
uint8_t crc3 = etl::crc1(data3.rbegin(), data3.rend());
CHECK_EQUAL(int(crc1), int(crc3));
}
//*************************************************************************
TEST(test_crc1_constants)
{
std::vector<uint8_t> data_odd{ etl::b00000001, etl::b00000111, etl::b01010001, etl::b10000100 };
std::vector<uint8_t> data_even{ etl::b00000001, etl::b01000111, etl::b01010001, etl::b10000100 };
CHECK_EQUAL(etl::crc1::odd_parity, etl::crc1(data_odd.begin(), data_odd.end()));
CHECK_EQUAL(etl::crc1::even_parity, etl::crc1(data_even.begin(), data_even.end()));
}
};
}