Add test for all relational operators to boost::none

This commit is contained in:
Alexander Grund
2024-08-16 11:13:45 +02:00
parent e1a3501a78
commit 5fa59b9a35

View File

@ -1,4 +1,5 @@
// Copyright (C) 2014 Andrzej Krzemienski.
// Copyright (C) 2024 Alexander Grund
//
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@ -36,6 +37,45 @@ void test_equal_to_none_of_noncomparable_T()
BOOST_TEST(boost::none == o);
}
void test_comparison_to_none()
{
using boost::none;
boost::optional<SemiRegular> i = SemiRegular();
// the default ordering of optional<size_t> is{ boost::none, 0, 1, 2, ... }
// Hence boost::none < i for any engaged i
// and all others operators ( ==, !=, <, <=, >, >= ) follow
BOOST_TEST(!(i == none));
BOOST_TEST(i != none);
BOOST_TEST(!(i < none));
BOOST_TEST(!(i <= none));
BOOST_TEST(i > none);
BOOST_TEST(i >= none);
// Comparison is symmetric
BOOST_TEST(!(none == i));
BOOST_TEST(none != i);
BOOST_TEST(none < i);
BOOST_TEST(none <= i);
BOOST_TEST(!(none > i));
BOOST_TEST(!(none >= i));
// An un-engaged optional is always equal to none
boost::optional<SemiRegular> o;
BOOST_TEST(o == none);
BOOST_TEST(!(o != none));
BOOST_TEST(!(o < none));
BOOST_TEST(o <= none);
BOOST_TEST(!(o > none));
BOOST_TEST(o >= none);
// Comparison is symmetric
BOOST_TEST(none == o);
BOOST_TEST(!(none != o));
BOOST_TEST(!(none < o));
BOOST_TEST(none <= o);
BOOST_TEST(!(none > o));
BOOST_TEST(none >= o);
}
int main()
{
test_equal_to_none_of_noncomparable_T();