1 #include "../misc/levenshtein.h" 2 #include "../misc/multiarray.h" 4 #include "../conversion/stringbuilder.h" 5 #include "../conversion/stringconversion.h" 7 #include "../io/misc.h" 9 #include "../tests/testutils.h" 11 #include <cppunit/TestFixture.h> 12 #include <cppunit/extensions/HelperMacros.h> 23 using namespace CPPUNIT_NS;
30 CPPUNIT_TEST(testMultiArray);
31 CPPUNIT_TEST(testLevenshtein);
32 CPPUNIT_TEST(testTestUtilities);
33 CPPUNIT_TEST_SUITE_END();
43 void testMultiArray();
44 void testLevenshtein();
45 void testTestUtilities();
52 static_assert(decltype(makeMultiArray<char>(3))::dimensionCount() == 1,
"dimension count 1D");
53 static_assert(decltype(makeMultiArray<char>(3, 2))::dimensionCount() == 2,
"dimension count 2D");
54 static_assert(decltype(makeMultiArray<char>(3, 2, 3))::dimensionCount() == 3,
"dimension count 3D");
56 auto array1d(makeMultiArray<char>(3));
57 CPPUNIT_ASSERT_EQUAL(3_st, array1d.dimensionSize<0>());
58 CPPUNIT_ASSERT_EQUAL(3_st, array1d.totalSize());
62 CPPUNIT_ASSERT_EQUAL(
"abc"s,
string(array1d.data(), 3));
64 auto array2d(makeMultiArray<char>(3, 2));
65 CPPUNIT_ASSERT_EQUAL(3_st, array2d.dimensionSize<0>());
66 CPPUNIT_ASSERT_EQUAL(2_st, array2d.dimensionSize<1>());
67 CPPUNIT_ASSERT_EQUAL(6_st, array2d.totalSize());
68 const char *
const data(array2d.data());
69 array2d.at(0, 0) =
'a';
70 array2d.at(0, 1) =
'b';
71 array2d.at(1, 0) =
'c';
72 array2d.at(1, 1) =
'd';
73 array2d.at(2, 0) =
'e';
74 array2d.at(2, 1) =
'f';
75 CPPUNIT_ASSERT_EQUAL(
"abcdef"s,
string(data, 6));
77 auto array3d(makeMultiArray<char>(3, 2, 3));
78 CPPUNIT_ASSERT_EQUAL(3_st, array3d.dimensionSize<0>());
79 CPPUNIT_ASSERT_EQUAL(2_st, array3d.dimensionSize<1>());
80 CPPUNIT_ASSERT_EQUAL(3_st, array3d.dimensionSize<2>());
81 CPPUNIT_ASSERT_EQUAL(18_st, array3d.totalSize());
82 array3d.at(0, 0, 0) =
'a';
83 array3d.at(0, 0, 1) =
'b';
84 array3d.at(0, 0, 2) =
'c';
85 array3d.at(0, 1, 0) =
'd';
86 array3d.at(0, 1, 1) =
'e';
87 array3d.at(0, 1, 2) =
'f';
88 array3d.at(1, 0, 0) =
'g';
89 array3d.at(1, 0, 1) =
'h';
90 array3d.at(1, 0, 2) =
'i';
91 array3d.at(1, 1, 0) =
'j';
92 array3d.at(1, 1, 1) =
'k';
93 array3d.at(1, 1, 2) =
'l';
94 array3d.at(2, 0, 0) =
'm';
95 array3d.at(2, 0, 1) =
'n';
96 array3d.at(2, 0, 2) =
'o';
97 array3d.at(2, 1, 0) =
'p';
98 array3d.at(2, 1, 1) =
'q';
99 array3d.at(2, 1, 2) =
'r';
100 CPPUNIT_ASSERT_EQUAL(
"abcdefghijklmnopqr"s,
string(array3d.data(), 18));
102 auto stackMultiArray(makeFixedSizeMultiArray<char, 9>(3, 3));
103 CPPUNIT_ASSERT_EQUAL(3_st, stackMultiArray.dimensionSize<0>());
104 CPPUNIT_ASSERT_EQUAL(3_st, stackMultiArray.dimensionSize<1>());
105 CPPUNIT_ASSERT_EQUAL(9_st, stackMultiArray.totalSize());
106 stackMultiArray.at(0, 0) =
'a';
107 stackMultiArray.at(0, 1) =
'b';
108 stackMultiArray.at(0, 2) =
'c';
109 stackMultiArray.at(1, 0) =
'd';
110 stackMultiArray.at(1, 1) =
'e';
111 stackMultiArray.at(1, 2) =
'f';
112 stackMultiArray.at(2, 0) =
'g';
113 stackMultiArray.at(2, 1) =
'h';
114 stackMultiArray.at(2, 2) =
'i';
115 CPPUNIT_ASSERT_EQUAL(
"abcdefghi"s,
string(stackMultiArray.data(), 9));
145 const auto workingCopyPathForNestedTestFile =
workingCopyPath(
"subdir/nested-testfile.txt");
146 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"creation of subdirectories in working dir",
"some file\n"s,
readFile(workingCopyPathForNestedTestFile));
148 const auto workingCopyPathUnderDifferentNameForNestedTestFile =
workingCopyPathAs(
"subdir/nested-testfile.txt",
"subdir2/foo.txt");
149 const auto splittedPath = splitString<vector<string>>(workingCopyPathUnderDifferentNameForNestedTestFile,
"/", EmptyPartsTreat::Omit);
150 CPPUNIT_ASSERT_GREATEREQUAL(2_st, splittedPath.size());
151 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"different subdir",
"subdir2"s, splittedPath[splittedPath.size() - 2]);
152 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"different file name",
"foo.txt"s, splittedPath[splittedPath.size() - 1]);
153 CPPUNIT_ASSERT_EQUAL_MESSAGE(
154 "creation of subdirectories in working dir",
"some file\n"s,
readFile(workingCopyPathUnderDifferentNameForNestedTestFile));
158 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"printing hex numbers",
"0x10"s, ss.str());
CPPUNIT_TEST_SUITE_REGISTRATION(MiscTests)
#define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString)
Asserts whether the specified string matches the specified regex.
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::workingCopyPath().
CPP_UTILITIES_EXPORT std::string readFile(const std::string &path, std::string::size_type maxSize=std::string::npos)
Reads all contents of the specified file in a single call.
Contains utility classes helping to read and write streams.
Contains classes and functions utilizing creating of test applications.
CPP_UTILITIES_EXPORT std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPathAs().
Contains several functions providing conversions between different data types.
AsHexNumber< T > asHexNumber(const T &value)
Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or sim...
CPP_UTILITIES_EXPORT std::size_t computeDamerauLevenshteinDistance(const char *str1, std::size_t size1, const char *str2, std::size_t size2)
Contains various utilities such as computing Damerau–Levenshtein distance and N-dimensional arrays.
void testTestUtilities()
Tests helper from TestUtilities namespace which aren't used in other tests anyways.
The MiscTests class tests misc functions and classes (mainly of files contained by the misc directory...