I've been tasked to write tests for some C++ code. I made a very simple function that reverses a string. I've wrote tests in C#, but never C++. What do C++ tests look like?
Here's my code: main takes a command line argument, sends it to reverse to reverse the string and returns it.
include <iostream>
#include <cstring>
using namespace std;
char * reverse(char *s)
{
int len = strlen(s);
char *head = s;
char *tail = &s[len-1];
while (head < tail)
swap(*head++, *tail--);
//cout << s <<endl;
return s;
}
int main(int argc, char *argv[])
{
char *s;
for (int i=1; i < argc; i++)
{
s = reverse(argv[i]);
cout << s<<endl;
}
}
So, would a test, look something like?:
bool test()
{
char *s = "haha3";
char *new_s = reverse(s);
if (new_s == "3ahah")
return true;
return false;
}
Is there a better way to do this? Syntax wise? Better looking code for testing C++ functions?