IndexOutOfBoundsEvaluatorTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. 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 actual = _exception.what();
  37. string expected = _exception.getName() + " thrown - provided index is out of bounds!";
  38. ASSERT_STREQ(expected.c_str(), actual.c_str());
  39. throw;
  40. }
  41. },
  42. IndexOutOfBoundsException);
  43. }
  44. TEST_F(IndexOutOfBoundsEvaluatorTest, evaluate_dedicated_message)
  45. {
  46. EXPECT_THROW(
  47. {
  48. try
  49. {
  50. IndexOutOfBoundsEvaluator(3, 2, "index 3 is not in range of the containers size, which is 2!").evaluate();
  51. }
  52. catch (const IndexOutOfBoundsException &_exception)
  53. {
  54. string actual = _exception.what();
  55. string expected = _exception.getName() + " thrown - index 3 is not in range of the containers size, which is 2!";
  56. ASSERT_STREQ(expected.c_str(), actual.c_str());
  57. throw;
  58. }
  59. },
  60. IndexOutOfBoundsException);
  61. }
  62. }