From 11c218683eccb6cd5166aa8dcb8a051b421b0b40 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 22 Dec 2025 08:00:32 +0100 Subject: feat: Add more tests and Jamfile. Improve allocator_op and basic_hash APIs. Signed-off-by: Amlal El Mahrouss --- .gitignore | 1 + include/ocl/allocator_op.hpp | 1 + include/ocl/basic_hash.hpp | 25 +++++++++++++++++++++++-- test/.keep | 0 test/Jamfile | 17 +++++++++++++++++ test/allocator_op.test.cpp | 16 ++++++++++++++++ test/option.test.cpp | 2 +- 7 files changed, 59 insertions(+), 3 deletions(-) delete mode 100644 test/.keep create mode 100644 test/Jamfile create mode 100644 test/allocator_op.test.cpp diff --git a/.gitignore b/.gitignore index bf33267..66c93a7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.obj dist/* +bin/ docs/html docs/latex diff --git a/include/ocl/allocator_op.hpp b/include/ocl/allocator_op.hpp index dcdbdaa..f515586 100644 --- a/include/ocl/allocator_op.hpp +++ b/include/ocl/allocator_op.hpp @@ -48,6 +48,7 @@ namespace ocl } }; + /// \brief Allocator operations structure. Takes care of memory mgmt within a pool. template class allocator_op { diff --git a/include/ocl/basic_hash.hpp b/include/ocl/basic_hash.hpp index 6a39df2..00c3768 100644 --- a/include/ocl/basic_hash.hpp +++ b/include/ocl/basic_hash.hpp @@ -1,3 +1,9 @@ +/* + * File: basic_hash.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License + */ + #ifndef __OCL_CORE_BASIC_HASH #define __OCL_CORE_BASIC_HASH @@ -6,8 +12,9 @@ /// @brief OCL equivalence namespace. namespace ocl { + /// \brief Hash helper. template - struct basic_hash final + struct basic_hash { using result_type = typename T::result_type; using type = T; @@ -18,6 +25,20 @@ namespace ocl return type{}.hash(); } }; -} + + /// \brief For all boolean types, return false as they are not hashable + template <> + struct basic_hash + { + using result_type = bool; + using type = bool; + + // AMLALE: If it throws, we can't compute the hash correctly. + constexpr result_type hash() + { + return false; + } + }; +} // namespace ocl #endif \ No newline at end of file diff --git a/test/.keep b/test/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/Jamfile b/test/Jamfile new file mode 100644 index 0000000..853d246 --- /dev/null +++ b/test/Jamfile @@ -0,0 +1,17 @@ +# /* +# * File: Jamfile +# * Author: Amlal El Mahrouss, +# * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License +# */ + +project tests +: default-build debug +; + +exe option.test.o + : option.test.cpp + : gcc : -std=c++20 ; + +exe allocator_op.test.o + : allocator_op.test.cpp + : gcc : -std=c++20 ; \ No newline at end of file diff --git a/test/allocator_op.test.cpp b/test/allocator_op.test.cpp new file mode 100644 index 0000000..fa2a049 --- /dev/null +++ b/test/allocator_op.test.cpp @@ -0,0 +1,16 @@ +// File: allocator.test.cpp +// Purpose; Allocator test for OCL. +/// @brief This unit test checks if the test succeeds. +/// @author Amlal El Mahrouss + +#include + +#define BOOST_TEST_MODULE allocator_op +#include + +BOOST_AUTO_TEST_CASE( allocator_should_succeed ) +{ + auto ptr = ocl::allocator{}.construct_array<10>(); + int* arr = ptr.get(); + BOOST_TEST( arr != nullptr ); +} \ No newline at end of file diff --git a/test/option.test.cpp b/test/option.test.cpp index 098d0aa..211f044 100644 --- a/test/option.test.cpp +++ b/test/option.test.cpp @@ -1,6 +1,6 @@ // File: option.test.cpp // Purpose; Option test for OCL. -/// @brief This unit test checks if the unit test fails with the expected value. +/// @brief This unit test checks if the test fails with the expected value. /// @author Amlal El Mahrouss #include -- cgit v1.2.3