From 29e1d40e8812f3206b5173497f630cb8cccafbf1 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 27 Apr 2022 20:15:10 +0800 Subject: [PATCH] Added std::out_of_range tests --- test/bitset_test.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/bitset_test.hpp b/test/bitset_test.hpp index feb2c2a..d53f595 100644 --- a/test/bitset_test.hpp +++ b/test/bitset_test.hpp @@ -1215,6 +1215,35 @@ struct bitset_test { } b.at(i).flip(); } + + // b.at(b.size()) + bool will_out_of_range = false; + for (i = 0; i <= b.size(); ++i) + { + if (i == b.size()) + { + will_out_of_range = true; + break; + } + b.at(i); + } + if (will_out_of_range) + { + try + { + b.at(b.size()); + BOOST_TEST(false); // It should have thrown an exception + } + catch (const std::out_of_range& ex) + { + // Good! + BOOST_TEST(!!ex.what()); + } + catch (...) + { + BOOST_TEST(false); // threw the wrong exception + } + } } // operator|