diff --git a/src/beman/optional26/tests/optional.t.cpp b/src/beman/optional26/tests/optional.t.cpp index 6f094ef..3a0ff3f 100644 --- a/src/beman/optional26/tests/optional.t.cpp +++ b/src/beman/optional26/tests/optional.t.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -596,22 +597,7 @@ TEST(OptionalTest, RangeTest) { } } -TEST(OptionalTest, HashTest) { - beman::optional26::optional o1 = beman::optional26::nullopt; - beman::optional26::optional o2 = beman::optional26::nullopt; - beman::optional26::optional o3 = 42; - beman::optional26::optional o4 = 42; - - auto h1 = std::hash>{}(o1); - auto h2 = std::hash>{}(o2); - auto h3 = std::hash>{}(o3); - auto h4 = std::hash>{}(o4); - - EXPECT_EQ(h1, h2); - EXPECT_EQ(h3, h4); -} - -TEST(ViewMaybeTest, Constructors) { +TEST(OptionalTest, RangeConstructors) { std::ranges::single_view> s; std::ranges::single_view> s2{s}; std::ranges::single_view> s3{std::optional{}}; @@ -625,7 +611,7 @@ TEST(ViewMaybeTest, Constructors) { std::ignore = n3; } -TEST(ViewMaybeTest, ConceptCheckRef) { +TEST(OptionalTest, ConceptCheckRef) { static_assert(std::ranges::range>); static_assert(std::ranges::view>); static_assert(std::ranges::input_range>); @@ -661,7 +647,7 @@ TEST(ViewMaybeTest, ConceptCheckRef) { static_assert(std::ranges::random_access_range>); } -TEST(ViewMaybeTest, BreathingTest) { +TEST(OptionalTest, BreathingTest) { beman::optional26::optional m; beman::optional26::optional m1{1}; @@ -679,7 +665,7 @@ TEST(ViewMaybeTest, BreathingTest) { ASSERT_EQ(*std::begin(d0), 1.0); } -TEST(ViewMaybeTest, BreathingTestRef) { +TEST(OptionalTest, BreathingTestRef) { beman::optional26::optional m; int one = 1; @@ -698,7 +684,7 @@ TEST(ViewMaybeTest, BreathingTestRef) { ASSERT_EQ(*std::begin(d0), 1.0); } -TEST(ViewMaybe, CompTest) { +TEST(OptionalTest, CompTest) { beman::optional26::optional m; beman::optional26::optional m0{0}; beman::optional26::optional m1{1}; @@ -718,7 +704,7 @@ TEST(ViewMaybe, CompTest) { ASSERT_TRUE(m1 <= m1a); } -TEST(ViewMaybe, CompTestRef) { +TEST(OptionalTest, CompTestRef) { beman::optional26::optional m; int zero = 0; int one = 1; @@ -758,7 +744,7 @@ inline constexpr auto yield_if = [](bool b, T x) { return b ? beman::optional26::optional{std::move(x)} : beman::optional26::nullopt; }; -TEST(ViewMaybeTest, PythTripleTest) { +TEST(OptionalTest, PythTripleTest) { using std::views::iota; auto triples = and_then(iota(1), [](int z) { return and_then(iota(1, z + 1), [=](int x) { @@ -772,7 +758,7 @@ TEST(ViewMaybeTest, PythTripleTest) { using namespace beman; -TEST(ViewMaybeTest, ValueBase) { +TEST(OptionalTest, ValueBase) { int i = 7; beman::optional26::optional v1{}; @@ -784,7 +770,7 @@ TEST(ViewMaybeTest, ValueBase) { ASSERT_EQ(i, 7); } -TEST(ViewMaybeTest, RefWrapper) { +TEST(OptionalTest, RefWrapper) { int i = 7; beman::optional26::optional v2{std::ref(i)}; @@ -793,7 +779,7 @@ TEST(ViewMaybeTest, RefWrapper) { ASSERT_EQ(i, 7); } -TEST(ViewMaybeTest, ValueNonDefaultConstruct) { +TEST(OptionalTest, ValueNonDefaultConstruct) { using beman::optional26::tests::int_ctor; int_ctor i = 7; beman::optional26::optional v1{}; @@ -802,7 +788,7 @@ TEST(ViewMaybeTest, ValueNonDefaultConstruct) { std::ignore = v2; } -TEST(ViewMaybeTest, RefBase) { +TEST(OptionalTest, RefBase) { int i = 7; beman::optional26::optional v1{}; // ASSERT_TRUE(v1.size() == 0); @@ -835,3 +821,25 @@ TEST(ViewMaybeTest, RefBase) { } ASSERT_EQ(s, 9); } + +TEST(OptionalTest, HashTest) { + beman::optional26::optional o1 = beman::optional26::nullopt; + beman::optional26::optional o2 = beman::optional26::nullopt; + beman::optional26::optional o3 = 42; + beman::optional26::optional o4 = 42; + + auto h1 = std::hash>{}(o1); + auto h2 = std::hash>{}(o2); + auto h3 = std::hash>{}(o3); + auto h4 = std::hash>{}(o4); + + EXPECT_EQ(h1, h2); + EXPECT_EQ(h3, h4); + EXPECT_NE(h1, h3); + + for(int i : std::views::iota(0, 1000)) { + auto h1 = std::hash>{}(i); + auto h2 = std::hash{}(i); + EXPECT_EQ(h1, h2); + } +}