mirror of
https://github.com/aicodix/code.git
synced 2026-04-28 09:43:11 +00:00
moved crc and xorshift from DSP to CODE repository
This commit is contained in:
commit
ee79ff2b2d
8 changed files with 292 additions and 0 deletions
1
tests/.gitignore
vendored
Normal file
1
tests/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*_test
|
||||
15
tests/Makefile
Normal file
15
tests/Makefile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
CXXFLAGS = -I.. -std=c++17 -W -Wall -Ofast -fno-exceptions -fno-rtti -march=native
|
||||
CXX = clang++ -stdlib=libc++
|
||||
#CXX = g++
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
tests := $(basename $(wildcard *_test.*))
|
||||
|
||||
test: $(tests)
|
||||
$(patsubst %,./%;,$(tests))
|
||||
|
||||
clean:
|
||||
rm -f *_test
|
||||
|
||||
37
tests/crc_test.cc
Normal file
37
tests/crc_test.cc
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Test for the Cyclic redundancy check
|
||||
|
||||
Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
#include "crc.hh"
|
||||
|
||||
int main()
|
||||
{
|
||||
if (1) {
|
||||
CODE::CRC<uint32_t> crc(0xEDB88320, 0xFFFFFFFF);
|
||||
for (uint8_t c: std::string("Hello World!")) crc(c);
|
||||
assert(~crc() == 0x1C291CA3);
|
||||
}
|
||||
if (1) {
|
||||
CODE::CRC<uint16_t> crc(0xA8F4);
|
||||
for (uint8_t c: std::string("Hello World!")) crc(c);
|
||||
assert(!crc(uint16_t(0x8FEF)));
|
||||
crc.reset(0x9B38);
|
||||
std::bitset<32> hw("00000010001001110111110100100100");
|
||||
for (size_t i = 0; i < hw.size(); ++i) crc(hw[i]);
|
||||
//std::cerr << "0x" << std::hex << crc() << std::endl;
|
||||
assert(crc() == 0x915D);
|
||||
}
|
||||
if (1) {
|
||||
CODE::CRC<uint8_t> crc(0x8C);
|
||||
for (uint8_t c: std::string("Hello World!")) crc(c);
|
||||
assert(!crc(uint8_t(0x9E)));
|
||||
}
|
||||
std::cerr << "Cyclic redundancy check test passed!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue