10
10
#include < functional>
11
11
#include < ranges>
12
12
#include < tuple>
13
+ #include < algorithm>
13
14
14
15
#include < gtest/gtest.h>
15
16
@@ -596,7 +597,7 @@ TEST(OptionalTest, RangeTest) {
596
597
}
597
598
}
598
599
599
- TEST (ViewMaybeTest, Constructors ) {
600
+ TEST (OptionalTest, RangeConstructors ) {
600
601
std::ranges::single_view<std::optional<int >> s;
601
602
std::ranges::single_view<std::optional<int >> s2{s};
602
603
std::ranges::single_view<std::optional<int >> s3{std::optional<int >{}};
@@ -610,7 +611,7 @@ TEST(ViewMaybeTest, Constructors) {
610
611
std::ignore = n3;
611
612
}
612
613
613
- TEST (ViewMaybeTest , ConceptCheckRef) {
614
+ TEST (OptionalTest , ConceptCheckRef) {
614
615
static_assert (std::ranges::range<beman::optional26::optional<int &>>);
615
616
static_assert (std::ranges::view<beman::optional26::optional<int &>>);
616
617
static_assert (std::ranges::input_range<beman::optional26::optional<int &>>);
@@ -646,7 +647,7 @@ TEST(ViewMaybeTest, ConceptCheckRef) {
646
647
static_assert (std::ranges::random_access_range<beman::optional26::optional<ref>>);
647
648
}
648
649
649
- TEST (ViewMaybeTest , BreathingTest) {
650
+ TEST (OptionalTest , BreathingTest) {
650
651
beman::optional26::optional<int > m;
651
652
beman::optional26::optional<int > m1{1 };
652
653
@@ -664,7 +665,7 @@ TEST(ViewMaybeTest, BreathingTest) {
664
665
ASSERT_EQ (*std::begin (d0), 1.0 );
665
666
}
666
667
667
- TEST (ViewMaybeTest , BreathingTestRef) {
668
+ TEST (OptionalTest , BreathingTestRef) {
668
669
beman::optional26::optional<int &> m;
669
670
670
671
int one = 1 ;
@@ -683,7 +684,7 @@ TEST(ViewMaybeTest, BreathingTestRef) {
683
684
ASSERT_EQ (*std::begin (d0), 1.0 );
684
685
}
685
686
686
- TEST (ViewMaybe , CompTest) {
687
+ TEST (OptionalTest , CompTest) {
687
688
beman::optional26::optional<int > m;
688
689
beman::optional26::optional<int > m0{0 };
689
690
beman::optional26::optional<int > m1{1 };
@@ -703,7 +704,7 @@ TEST(ViewMaybe, CompTest) {
703
704
ASSERT_TRUE (m1 <= m1a);
704
705
}
705
706
706
- TEST (ViewMaybe , CompTestRef) {
707
+ TEST (OptionalTest , CompTestRef) {
707
708
beman::optional26::optional<int &> m;
708
709
int zero = 0 ;
709
710
int one = 1 ;
@@ -743,7 +744,7 @@ inline constexpr auto yield_if = []<class T>(bool b, T x) {
743
744
return b ? beman::optional26::optional<T>{std::move (x)} : beman::optional26::nullopt ;
744
745
};
745
746
746
- TEST (ViewMaybeTest , PythTripleTest) {
747
+ TEST (OptionalTest , PythTripleTest) {
747
748
using std::views::iota;
748
749
auto triples = and_then (iota (1 ), [](int z) {
749
750
return and_then (iota (1 , z + 1 ), [=](int x) {
@@ -757,7 +758,7 @@ TEST(ViewMaybeTest, PythTripleTest) {
757
758
758
759
using namespace beman ;
759
760
760
- TEST (ViewMaybeTest , ValueBase) {
761
+ TEST (OptionalTest , ValueBase) {
761
762
int i = 7 ;
762
763
beman::optional26::optional<int > v1{};
763
764
@@ -769,7 +770,7 @@ TEST(ViewMaybeTest, ValueBase) {
769
770
ASSERT_EQ (i, 7 );
770
771
}
771
772
772
- TEST (ViewMaybeTest , RefWrapper) {
773
+ TEST (OptionalTest , RefWrapper) {
773
774
int i = 7 ;
774
775
775
776
beman::optional26::optional<int > v2{std::ref (i)};
@@ -778,7 +779,7 @@ TEST(ViewMaybeTest, RefWrapper) {
778
779
ASSERT_EQ (i, 7 );
779
780
}
780
781
781
- TEST (ViewMaybeTest , ValueNonDefaultConstruct) {
782
+ TEST (OptionalTest , ValueNonDefaultConstruct) {
782
783
using beman::optional26::tests::int_ctor;
783
784
int_ctor i = 7 ;
784
785
beman::optional26::optional<int_ctor> v1{};
@@ -787,7 +788,7 @@ TEST(ViewMaybeTest, ValueNonDefaultConstruct) {
787
788
std::ignore = v2;
788
789
}
789
790
790
- TEST (ViewMaybeTest , RefBase) {
791
+ TEST (OptionalTest , RefBase) {
791
792
int i = 7 ;
792
793
beman::optional26::optional<int &> v1{};
793
794
// ASSERT_TRUE(v1.size() == 0);
@@ -820,3 +821,25 @@ TEST(ViewMaybeTest, RefBase) {
820
821
}
821
822
ASSERT_EQ (s, 9 );
822
823
}
824
+
825
+ TEST (OptionalTest, HashTest) {
826
+ beman::optional26::optional<int > o1 = beman::optional26::nullopt ;
827
+ beman::optional26::optional<int > o2 = beman::optional26::nullopt ;
828
+ beman::optional26::optional<int > o3 = 42 ;
829
+ beman::optional26::optional<int > o4 = 42 ;
830
+
831
+ auto h1 = std::hash<beman::optional26::optional<int >>{}(o1);
832
+ auto h2 = std::hash<beman::optional26::optional<int >>{}(o2);
833
+ auto h3 = std::hash<beman::optional26::optional<int >>{}(o3);
834
+ auto h4 = std::hash<beman::optional26::optional<int >>{}(o4);
835
+
836
+ EXPECT_EQ (h1, h2);
837
+ EXPECT_EQ (h3, h4);
838
+ EXPECT_NE (h1, h3);
839
+
840
+ for (int i : std::views::iota (0 , 1000 )) {
841
+ auto h1 = std::hash<beman::optional26::optional<int >>{}(i);
842
+ auto h2 = std::hash<int >{}(i);
843
+ EXPECT_EQ (h1, h2);
844
+ }
845
+ }
0 commit comments