Skip to content

Instantly share code, notes, and snippets.

@henteko
Created December 15, 2012 02:43
Show Gist options
  • Save henteko/4290874 to your computer and use it in GitHub Desktop.
Save henteko/4290874 to your computer and use it in GitHub Desktop.
C++ TestSample.
#include<sstream>
#include<iostream>
#include<vector>
#include<list>
#include<string>
using namespace std;
class TestSample {
public:
int wordlen(string word) {
int result = 0;
result = word.size();
return result;
}
public:
void run_test(int Case) {
if((Case == -1) || (Case == 0)) test_case_0();
if((Case == -1) || (Case == 1)) test_case_1();
if((Case == -1) || (Case == 2)) test_case_2();
if((Case == -1) || (Case == 3)) test_case_3();
}
private:
template <typename T> string print_array(const vector<T> &V) {
ostringstream os; os << "{ ";
for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) {
os << '\"' << *iter << "\",";
}
os << " }"; return os.str();
}
void verify_case(int Case, const int Expected, const int Received) {
cerr << "Test Case #" << Case << "...";
if (Expected == Received) cerr << "PASSED" << endl;
else {
cerr << "FAILED" << endl;
cerr << "\tExpected: " << Expected << endl;
cerr << "\tReceived: " << Received << endl;
}
}
void test_case_0() {
int Arg0 = 4;
string Arg1 = "test";
verify_case(0, Arg0, wordlen(Arg1));
}
void test_case_1() {
int Arg0 = 5;
string Arg1 = "test1";
verify_case(1, Arg0, wordlen(Arg1));
}
void test_case_2() {
int Arg0 = 10;
string Arg1 = "testhogefo";
verify_case(2, Arg0, wordlen(Arg1));
}
void test_case_3() {
int Arg0 = 1;
string Arg1 = "t";
verify_case(3, Arg0, wordlen(Arg1));
}
};
int main() {
TestSample ___test;
___test.run_test(-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment