IndexOutOfBoundsEvaluatorTest.cpp 1.8 KB

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