void ribi::foam::FacesFile::Test() noexcept { { static bool is_tested{false}; if (is_tested) return; is_tested = true; } const TestTimer test_timer(__func__,__FILE__,1.0); //Some initial data const Header header("some_name","some_location","some_object"); std::vector<FacesFileItem> items; for (int i=1; i!=4; ++i) { FacesFileItem item( std::vector<PointIndex>(i,PointIndex(i))); items.push_back(item); } //operator== { const FacesFile b(header,items); const FacesFile c(header,items); assert(header == header); assert(b == c); } //operator!= { const FacesFile b(header,items); const Header other_header("some_other_name","some_other_location","some_other_object"); assert(header != other_header); const FacesFile c(other_header,items); assert(b != c); } //operator!= { const FacesFile b(header,items); std::vector<FacesFileItem> other_items; for (int i=1; i!=3; ++i) { FacesFileItem item( std::vector<PointIndex>(i+1,PointIndex(i*i)) ); other_items.push_back(item); } const FacesFile c(header,other_items); assert(b != c); } //Stream conversion { const FacesFile b(header,items); std::stringstream s; s << b; FacesFile c; s >> c; if (b != c) { TRACE(b); TRACE(c); } assert(b == c); } //Read from testing file for (int test_index = 0; test_index!=5; ++test_index) { std::string filename_appendix; switch (test_index) { case 0: filename_appendix = "_1x1x1"; break; case 1: filename_appendix = "_1x1x2"; break; case 2: filename_appendix = "_1x2x2"; break; case 3: filename_appendix = "_2x2x2"; break; case 4: filename_appendix = "_3x4x5"; break; default: assert(!"Should never get here"); throw std::logic_error("foam::Files::CreateTestFiles: unknown test index"); } assert(!filename_appendix.empty()); const std::string filename_base { GetDefaultHeader().GetObject() }; const std::string filename = filename_base + filename_appendix; const std::string resources_path { ":/CppOpenFoam/files/" + filename }; { QFile f( resources_path.c_str() ); f.copy(filename.c_str()); } { if (!fileio::FileIo().IsRegularFile(filename)) { TRACE("ERROR"); TRACE(filename); } assert(fileio::FileIo().IsRegularFile(filename)); FacesFile b(filename); if (b.GetItems().empty()) { TRACE("ERROR"); } assert( (!b.GetItems().empty() || b.GetItems().empty()) && "If a mesh has no non-bhoundary cells, neighbour can be empty"); } } }
void ribi::foam::PointsFile::Test() noexcept { { static bool is_tested = false; if (is_tested) return; is_tested = true; } TRACE("Starting ribi::foam::PointsFile::Test"); //Some initial data const Header header("some_name","some_location","some_object"); std::vector<PointsFileItem> items; for (int i=1; i!=4; ++i) { PointsFileItem item( Coordinat3D( static_cast<double>(i) * 1.1, static_cast<double>(i) * 2.2, static_cast<double>(i) * 3.3 ) ); items.push_back(item); } //operator== { const PointsFile b(header,items); const PointsFile c(header,items); assert(header == header); assert(b == c); } //operator!= { const PointsFile b(header,items); const Header other_header("some_other_name","some_other_location","some_other_object"); assert(header != other_header); const PointsFile c(other_header,items); assert(b != c); } //operator!= { const PointsFile b(header,items); std::vector<PointsFileItem> other_items; for (int i=1; i!=3; ++i) { PointsFileItem item( Coordinat3D( static_cast<double>(i) * 4.4, static_cast<double>(i) * 5.5, static_cast<double>(i) * 6.6 ) ); other_items.push_back(item); } const PointsFile c(header,other_items); assert(b != c); } //Stream conversion { const PointsFile b(header,items); std::stringstream s; s << b; PointsFile c; s >> c; if (b != c) { TRACE(b); TRACE(c); } assert(b == c); } //Read from testing file for (int test_index = 0; test_index!=5; ++test_index) { std::string filename_appendix; switch (test_index) { case 0: filename_appendix = "_1x1x1"; break; case 1: filename_appendix = "_1x1x2"; break; case 2: filename_appendix = "_1x2x2"; break; case 3: filename_appendix = "_2x2x2"; break; case 4: filename_appendix = "_3x4x5"; break; default: assert(!"Should never get here"); throw std::logic_error("foam::Files::CreateTestFiles: unknown test index"); } assert(!filename_appendix.empty()); const std::string filename_base { GetDefaultHeader().GetObject() }; const std::string filename = filename_base + filename_appendix; const std::string resources_path { ":/CppOpenFoam/files/" + filename }; { QFile f( resources_path.c_str() ); f.copy(filename.c_str()); } { if (!fileio::IsRegularFile(filename)) { TRACE("ERROR"); TRACE(filename); } assert(fileio::IsRegularFile(filename)); PointsFile b(filename); if (b.GetItems().empty()) { TRACE("ERROR"); } assert(!b.GetItems().empty()); } } TRACE("Finished ribi::foam::Header::PointsFile successfully"); }