Skip to content

Commit

Permalink
Added CRC1 (AKA Parity)
Browse files Browse the repository at this point in the history
Modified test suit names
  • Loading branch information
John Wellbelove committed Dec 8, 2023
1 parent 9161413 commit eba9c57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/etl/crc1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//*********************************
Expand All @@ -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
};

//*************************************************************************
Expand Down
14 changes: 13 additions & 1 deletion test/test_crc1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ SOFTWARE.

namespace
{
//***************************************************************************
// Calculate parity the simple way.
//***************************************************************************
template <typename TIterator>
int calculate_parity(TIterator b, TIterator e)
Expand All @@ -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)
Expand Down Expand Up @@ -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()));
}
};
}

0 comments on commit eba9c57

Please sign in to comment.