crc32c_ut.cpp 962 B

12345678910111213141516171819202122232425262728293031
  1. #include "crc32c.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. Y_UNIT_TEST_SUITE(TestCrc32c) {
  4. Y_UNIT_TEST(TestCalc) {
  5. UNIT_ASSERT_VALUES_EQUAL(Crc32c("abc", 3), ui32(910901175));
  6. }
  7. Y_UNIT_TEST(TestUnaligned) {
  8. const TString str(1000, 'a');
  9. for (size_t substrLen = 0; substrLen <= str.length(); ++substrLen) {
  10. const ui32 crc = Crc32c(str.data(), substrLen);
  11. for (size_t offset = 1; offset + substrLen <= str.length(); ++offset) {
  12. UNIT_ASSERT_VALUES_EQUAL(Crc32c(str.data() + offset, substrLen), crc);
  13. }
  14. }
  15. }
  16. Y_UNIT_TEST(TestExtend) {
  17. UNIT_ASSERT_VALUES_EQUAL(Crc32cExtend(1, "abc", 3), ui32(2466950601));
  18. }
  19. Y_UNIT_TEST(TestCombine) {
  20. ui32 aSum = Crc32c("abc", 3);
  21. ui32 bSum = Crc32c("de", 2);
  22. ui32 abSum = Crc32c("abcde", 5);
  23. UNIT_ASSERT_VALUES_EQUAL(Crc32cCombine(aSum, bSum, 2), abSum);
  24. }
  25. }