reflex2q3/ReflexToQ3/test/catch-parser.cpp

53 lines
1.4 KiB
C++
Raw Normal View History

#include "oopless-parser.hpp"
#include "catch.hpp"
#include <iostream>
#include <algorithm>
#include <iterator>
#include <sstream>
using namespace std;
vector<string> readin(const string &filename, const int ln = 0) {
ifstream fin;
fin.open(filename);
if (!fin.good()) {
cerr << "error: can not open file with test cases." << endl;
}
vector<string> output;
string data;
while (getline(fin, data)) {
output.push_back(data);
}
return output;
}
bool test_parseface(const string &filename, const int &cnt_indices) {
vector<string> test = readin(filename);
stringstream ss;
copy(test.begin(), test.end(), ostream_iterator<string>(ss, "\n"));
vector<TFace> x = parse_face<stringstream>(ss);
bool is_ok = true;
for (struct TFace face : x) {
if (face.m_Indices.size() != cnt_indices) {
is_ok = false;
break;
}
}
return is_ok;
}
TEST_CASE ( "face parsing case: faces with 3 indices " ) {
bool k = test_parseface("cases-faces/parser-face-3indices.txt", 3);
REQUIRE (k == true);
}
TEST_CASE ("face parsing case: faces with 4 indices ") {
bool k = test_parseface("cases-faces/parser-face-4indices.txt", 4);
REQUIRE (k == true);
}
TEST_CASE ("face parsing case: faces with 5 indices ") {
bool k = test_parseface("cases-faces/parser-face-5indices.txt", 5);
REQUIRE (k == true);
}