Author | Jamozed <[email protected]> |
Date | 2021-01-26 01:06:02 |
Commit | e4b2536eeaceed6b73e5898afa2bce4413931e67 |
Parent | 8e42725bb6f8be78e274ee39b58f8baa56969588 |
misc: Add circular shift unit tests
Diffstat
M | CMakeLists.txt | | | 1 | + |
A | src/test_misc.c | | | 67 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 68 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e7cf41d..b9436d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,4 +16,5 @@ LINK_LIBRARIES(lib) ADD_EXECUTABLE(test_endian ${PROJECT_SOURCE_DIR}/src/test_endian.c) ADD_EXECUTABLE(test_error ${PROJECT_SOURCE_DIR}/src/test_error.c) +ADD_EXECUTABLE(test_misc ${PROJECT_SOURCE_DIR}/src/test_misc.c) ADD_EXECUTABLE(test_optget ${PROJECT_SOURCE_DIR}/src/test_optget.c) diff --git a/src/test_misc.c b/src/test_misc.c new file mode 100644 index 0000000..4825aa3 --- /dev/null +++ b/src/test_misc.c @@ -0,0 +1,67 @@ +// test_misc.c +// Misc unit test for OMKOV lib +// Copyright (C) 2021, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Public Domain Licence, version 1.0 + +Permission is hereby granted to deal with this software and its associated +documentation files without restriction. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#include "lib/misc.h" +#include "unit.h" + +#include <stdint.h> +#include <stdio.h> + +int main(void) { + { + ASSERT("G00T00 ROL8 1", + ROL8(0xF0u, 1) == 0xE1u); + ASSERT("G00T01 ROL8 7", + ROL8(0xF0u, 7) == 0x78u); + ASSERT("G00T02 ROL16 1", + ROL16(0xF000u, 1) == 0xE001u); + ASSERT("G00T03 ROL16 15", + ROL16(0xF000u, 15) == 0x7800u); + ASSERT("G00T04 ROL32 1", + ROL32(0xF0000000uL, 1) == 0xE0000001uL); + ASSERT("G00T05 ROL32 31", + ROL32(0xF0000000uL, 31) == 0x78000000uL); + ASSERT("G00T06 ROL64 1", + ROL64(0xF000000000000000uLL, 1) == 0xE000000000000001uLL); + ASSERT("G00T07 ROL64 63", + ROL64(0xF000000000000000uLL, 63) == 0x7800000000000000uLL); + } + + { + ASSERT("G01T00 ROR8 1", + ROR8(0x0Fu, 1) == 0x87u); + ASSERT("G01T01 ROR8 7", + ROR8(0x0Fu, 7) == 0x1Eu); + ASSERT("G01T02 ROR16 1", + ROR16(0x000Fu, 1) == 0x8007u); + ASSERT("G01T03 ROR16 15", + ROR16(0x000Fu, 15) == 0x001Eu); + ASSERT("G01T04 ROR32 1", + ROR32(0x0000000FuL, 1) == 0x80000007uL); + ASSERT("G01T05 ROR32 31", + ROR32(0x0000000FuL, 31) == 0x0000001EuL); + ASSERT("G01T06 ROR64 1", + ROR64(0x000000000000000FuLL, 1) == 0x8000000000000007uLL); + ASSERT("G01T07 ROR64 63", + ROR64(0x000000000000000FuLL, 63) == 0x000000000000001EuLL); + } + + printf("%d of %d tests passed\n", testspassed, testsrun); + return testsfailed; +}