DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
testMathExceptions.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: testMathExceptions.hpp
5// Author: crdrisko
6// Date: 10/27/2020-07:31:00
7// Description: Provides ~100% unit test coverage over all exceptions specifically relating to the math library
8
9#ifndef DRYCHEM_COMMON_UTILITIES_LIBS_MATH_TESTS_TESTUTILITIES_TESTMATHEXCEPTIONS_HPP
10#define DRYCHEM_COMMON_UTILITIES_LIBS_MATH_TESTS_TESTUTILITIES_TESTMATHEXCEPTIONS_HPP
11
12#include <sstream>
13
15#include <common-utils/math.hpp>
16#include <gtest/gtest.h>
17
18GTEST_TEST(testMathExceptions, inputSizeMismatchIsAFatalExceptionAndCanTerminateWhenHandled)
19{
20 std::stringstream deathRegex;
21
22 deathRegex << "Common-Utilities Fatal Error: ";
23
24#if GTEST_USES_POSIX_RE
25 deathRegex << "[(]testMathExceptions.hpp: *[0-9]*[)]\n\t";
26#elif GTEST_USES_SIMPLE_RE
27 deathRegex << "\\(testMathExceptions.hpp: \\d*\\)\n\t";
28#endif
29
30 deathRegex << "Input sizes for x and y containers must be the same.\n";
31
32 DryChem::InputSizeMismatch exception1 {"Common-Utilities", __FILE__, __LINE__};
33
34 ASSERT_DEATH(
35 {
36 try
37 {
38 throw exception1;
39 }
40 catch (const DryChem::InputSizeMismatch& except)
41 {
42 except.handleErrorWithMessage();
43 }
44 },
45 deathRegex.str());
46}
47
48GTEST_TEST(testMathExceptions, derivedExceptionsCanBeCaughtByBaseFatalException)
49{
50 std::stringstream deathRegex;
51
52 deathRegex << "Common-Utilities Fatal Error: ";
53
54#if GTEST_USES_POSIX_RE
55 deathRegex << "[(]testMathExceptions.hpp: *[0-9]*[)]\n\t";
56#elif GTEST_USES_SIMPLE_RE
57 deathRegex << "\\(testMathExceptions.hpp: \\d*\\)\n\t";
58#endif
59
60 deathRegex << "Input sizes for x and y containers must be the same.\n";
61
62 ASSERT_DEATH(
63 {
64 try
65 {
66 throw DryChem::InputSizeMismatch("Common-Utilities", __FILE__, __LINE__);
67 }
68 catch (const DryChem::FatalException& except)
69 {
70 except.handleErrorWithMessage();
71 }
72 },
73 deathRegex.str());
74}
75
76#endif
GTEST_TEST(testMathExceptions, inputSizeMismatchIsAFatalExceptionAndCanTerminateWhenHandled)
Definition testMathExceptions.hpp:18