IndexOutOfBoundsEvaluatorTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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-22
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <string>
  12. using ls::std::core::IndexOutOfBoundsEvaluator;
  13. using ls::std::core::IndexOutOfBoundsException;
  14. using std::string;
  15. using testing::Test;
  16. namespace
  17. {
  18. class IndexOutOfBoundsEvaluatorTest : public Test
  19. {
  20. protected:
  21. IndexOutOfBoundsEvaluatorTest() = default;
  22. ~IndexOutOfBoundsEvaluatorTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate)
  29. {
  30. EXPECT_THROW(
  31. {
  32. try
  33. {
  34. IndexOutOfBoundsEvaluator(3, 2).evaluate();
  35. }
  36. catch (const IndexOutOfBoundsException &_exception)
  37. {
  38. string actual = _exception.what();
  39. string expected = _exception.getName() + " thrown - provided index is out of bounds!";
  40. ASSERT_STREQ(expected.c_str(), actual.c_str());
  41. throw;
  42. }
  43. },
  44. IndexOutOfBoundsException);
  45. }
  46. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate_dedicated_message)
  47. {
  48. EXPECT_THROW(
  49. {
  50. try
  51. {
  52. IndexOutOfBoundsEvaluator(3, 2, "index 3 is not in range of the containers size, which is 2!").evaluate();
  53. }
  54. catch (const IndexOutOfBoundsException &_exception)
  55. {
  56. string actual = _exception.what();
  57. string expected = _exception.getName() + " thrown - index 3 is not in range of the containers size, which is 2!";
  58. ASSERT_STREQ(expected.c_str(), actual.c_str());
  59. throw;
  60. }
  61. },
  62. IndexOutOfBoundsException);
  63. }
  64. }