IndexOutOfBoundsEvaluatorTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-02-10
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <string>
  12. using namespace ls::std::core;
  13. using namespace ::std;
  14. namespace
  15. {
  16. class IndexOutOfBoundsEvaluatorTest : public ::testing::Test
  17. {
  18. protected:
  19. IndexOutOfBoundsEvaluatorTest() = default;
  20. ~IndexOutOfBoundsEvaluatorTest() override = default;
  21. void SetUp() override
  22. {}
  23. void TearDown() override
  24. {}
  25. };
  26. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate)
  27. {
  28. EXPECT_THROW(
  29. {
  30. try
  31. {
  32. IndexOutOfBoundsEvaluator(3, 2).evaluate();
  33. }
  34. catch (const IndexOutOfBoundsException &_exception)
  35. {
  36. string message = _exception.what();
  37. ASSERT_STREQ("IndexOutOfBoundsException thrown - provided index is out of bounds!", message.c_str());
  38. throw;
  39. }
  40. },
  41. IndexOutOfBoundsException);
  42. }
  43. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate_dedicated_message)
  44. {
  45. EXPECT_THROW(
  46. {
  47. try
  48. {
  49. IndexOutOfBoundsEvaluator(3, 2, "index 3 is not in range of the containers size, which is 2!").evaluate();
  50. }
  51. catch (const IndexOutOfBoundsException &_exception)
  52. {
  53. string message = _exception.what();
  54. ASSERT_STREQ("IndexOutOfBoundsException thrown - index 3 is not in range of the containers size, which is 2!", message.c_str());
  55. throw;
  56. }
  57. },
  58. IndexOutOfBoundsException);
  59. }
  60. }