From 5b3bad3ce5e768d012a8b80bbd17ecae1e34ab87 Mon Sep 17 00:00:00 2001 From: Sven Scharmentke Date: Mon, 15 Jul 2019 08:44:21 +0200 Subject: [PATCH] Implemented a test for std::hash. --- test/cxxtest/general.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/cxxtest/general.h b/test/cxxtest/general.h index 7dbef05..b1f136c 100644 --- a/test/cxxtest/general.h +++ b/test/cxxtest/general.h @@ -16,7 +16,7 @@ BETTER_ENUM(Channel, short, Red, Green, Blue) BETTER_ENUM(Depth, short, HighColor = 40, TrueColor = 20) BETTER_ENUM(Compression, short, None, Huffman, Default = Huffman) - +BETTER_ENUMS_DECLARE_STD_HASH(Channel) namespace test { @@ -158,9 +158,17 @@ static_assert_1(same_string(Depth::_names()[0], "HighColor")); #endif // #ifdef _ENUM_HAVE_CONSTEXPR - - // Run-time testing. +class HashTests : public CxxTest::TestSuite { + public: + void test_same_values() + { + TS_ASSERT_EQUALS(std::hash().operator()(Channel::Red), std::hash().operator()(0)); + TS_ASSERT_EQUALS(std::hash().operator()(Channel::Green), std::hash().operator()(1)); + TS_ASSERT_EQUALS(std::hash().operator()(Channel::Blue), std::hash().operator()(2)); + } +}; + class EnumTests : public CxxTest::TestSuite { public: void test_constant_values()