1
+ /* *
2
+ * @file string_reversal_unit.cpp
3
+ * @author Edwin Gendron
4
+ * @date 2021-06-28
5
+ */
6
+
7
+ #include < gtest/gtest.h>
8
+
9
+ #include < string_reversal.hpp>
10
+
11
+ using namespace string_reversal ;
12
+
13
+ /* *
14
+ * @pre empty string
15
+ * @post program terminated
16
+ */
17
+ TEST (StringReversalUnit, ReverseStringEmptyStringExceptionThrown) {
18
+ auto empty_string = std::string{};
19
+ ASSERT_DEATH (ReverseString (empty_string), " " );
20
+ }
21
+
22
+ /* *
23
+ * @pre string of size 1
24
+ * @post string remains the same
25
+ */
26
+ TEST (StringReversalUnit, ReverseStringStringSizeOneExceptionThrown) {
27
+ auto test_string = std::string{" a" };
28
+ auto temp_test_string = std::string{test_string};
29
+ ReverseString (test_string);
30
+ ASSERT_EQ (temp_test_string, test_string);
31
+ }
32
+
33
+ /* *
34
+ * @pre string of size 100005, 5 chars too large.
35
+ * @post program terminated
36
+ */
37
+ TEST (StringReversalUnit, ReverseStringStringSizeTooLargeExceptionThrown) {
38
+ auto test_string = std::string (100005 , ' a' );
39
+ ASSERT_DEATH (ReverseString (test_string), " " );
40
+ }
41
+
42
+ /* *
43
+ * @pre string to reverse within the specified size and larger than 1 char
44
+ * @post string is reversed
45
+ */
46
+ TEST (StringReversalUnit, ReverseStringStringSizeAcceptableAndGreaterThanOneReversedStringReturned) {
47
+ auto test_string = std::string{" abcdefghijklmnopqrstuvwxyz" };
48
+ const auto expected_reversed_result =
49
+ std::string{" zyxwvutsrqponmlkjihgfedcba" };
50
+ ReverseString (test_string);
51
+ ASSERT_EQ (test_string, expected_reversed_result);
52
+ }
0 commit comments