IndexOutOfBoundsEvaluatorTest.cpp 1.8 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-03-25
  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. public:
  21. IndexOutOfBoundsEvaluatorTest() = default;
  22. ~IndexOutOfBoundsEvaluatorTest() override = default;
  23. };
  24. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate)
  25. {
  26. EXPECT_THROW(
  27. {
  28. try
  29. {
  30. IndexOutOfBoundsEvaluator(3, 2).evaluate();
  31. }
  32. catch (const IndexOutOfBoundsException &_exception)
  33. {
  34. string actual = _exception.what();
  35. string expected = _exception.getName() + " thrown - provided index is out of bounds!";
  36. ASSERT_STREQ(expected.c_str(), actual.c_str());
  37. throw;
  38. }
  39. },
  40. IndexOutOfBoundsException);
  41. }
  42. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate_dedicated_message)
  43. {
  44. EXPECT_THROW(
  45. {
  46. try
  47. {
  48. IndexOutOfBoundsEvaluator(3, 2, "index 3 is not in range of the containers size, which is 2!").evaluate();
  49. }
  50. catch (const IndexOutOfBoundsException &_exception)
  51. {
  52. string actual = _exception.what();
  53. string expected = _exception.getName() + " thrown - index 3 is not in range of the containers size, which is 2!";
  54. ASSERT_STREQ(expected.c_str(), actual.c_str());
  55. throw;
  56. }
  57. },
  58. IndexOutOfBoundsException);
  59. }
  60. }