diff --git a/Casting_2/test/Casting_2/CMakeLists.txt b/Casting_2/test/Casting_2/CMakeLists.txt new file mode 100644 index 00000000000..0e39af47ec3 --- /dev/null +++ b/Casting_2/test/Casting_2/CMakeLists.txt @@ -0,0 +1,29 @@ +# Created by the script cgal_create_cmake_script +# This is the CMake script for compiling a CGAL application. + + +project( Casting_2_test ) + +cmake_minimum_required(VERSION 2.8.10) + +find_package(CGAL QUIET COMPONENTS Core ) + +if ( CGAL_FOUND ) + + include( ${CGAL_USE_FILE} ) + + include( CGAL_CreateSingleSourceCGALProgram ) + + include_directories (BEFORE "../../include") + + if (CMAKE_COMPILER_IS_GNUCXX) + add_definitions(-std=c++11) + endif() + +create_single_source_cgal_program( "test_single_mold_translational_casting.cpp" ) + +else() + + message(STATUS "This program requires the CGAL library, and will not be compiled.") + +endif() diff --git a/Casting_2/test/Casting_2/cgal_test_with_cmake b/Casting_2/test/Casting_2/cgal_test_with_cmake new file mode 100755 index 00000000000..f89576f0cdb --- /dev/null +++ b/Casting_2/test/Casting_2/cgal_test_with_cmake @@ -0,0 +1,113 @@ +#! /bin/sh + +# This is a script for the CGAL test suite. Such a script must obey +# the following rules: +# +# - the name of the script is cgal_test_with_cmake +# - for every target two one line messages are written to the file 'error.txt' +# the first one indicates if the compilation was successful +# the second one indicates if the execution was successful +# if one of the two was not successful, the line should start with 'ERROR:' +# - running the script should not require any user interaction +# - the script should clean up object files and executables + + ERRORFILE=error.txt + DO_RUN=y + if [ -z "${MAKE_CMD}" ]; then + MAKE_CMD=make + fi + NEED_CLEAN= + +#---------------------------------------------------------------------# +# configure +#---------------------------------------------------------------------# + +configure() +{ + echo "Configuring... " + + if eval 'cmake "$CMAKE_GENERATOR" -DRUNNING_CGAL_AUTO_TEST=TRUE \ + -DCGAL_DIR="$CGAL_DIR" \ + .' ; then + + echo " successful configuration" >> $ERRORFILE + else + echo " ERROR: configuration" >> $ERRORFILE + fi +} + +#---------------------------------------------------------------------# +# compile_and_run +#---------------------------------------------------------------------# + +compile_and_run() +{ + echo "Compiling $1 ... " + SUCCESS="y" + + if eval '${MAKE_CMD} VERBOSE=ON -fMakefile $1' ; then + echo " successful compilation of $1" >> $ERRORFILE + else + echo " ERROR: compilation of $1" >> $ERRORFILE + SUCCESS="" + fi + + if [ -n "$DO_RUN" ] ; then + if [ -n "${SUCCESS}" ] ; then + OUTPUTFILE=ProgramOutput.$1.$PLATFORM + rm -f $OUTPUTFILE + COMMAND="./$1" + if [ -f $1.cmd ] ; then + COMMAND="$COMMAND `cat $1.cmd`" + fi + if [ -f $1.cin ] ; then + COMMAND="cat $1.cin | $COMMAND" + fi + echo "Executing $1 ... " + echo + ulimit -t 3600 2> /dev/null + if eval $COMMAND > $OUTPUTFILE 2>&1 ; then + echo " successful execution of $1" >> $ERRORFILE + else + echo " ERROR: execution of $1" >> $ERRORFILE + fi + else + echo " ERROR: not executed $1" >> $ERRORFILE + fi + fi +} + +#---------------------------------------------------------------------# +# remove the previous error file +#---------------------------------------------------------------------# + +rm -f $ERRORFILE +touch $ERRORFILE + +#---------------------------------------------------------------------# +# configure, compile and run the tests +#---------------------------------------------------------------------# + +configure + +if [ $# -ne 0 ] ; then + for file in $* ; do + compile_and_run $file + done +else + echo "Run all tests." +if ${MAKE_CMD} -f Makefile help | grep -E "test_single_mold_translational_casting$" > /dev/null; then + compile_and_run test_single_mold_translational_casting + NEED_CLEAN=y +fi +fi + +# +# The clean target generated by CMake under cygwin +# always fails for some reason +# +if [ -n "${NEED_CLEAN}" ]; then + if ! ( uname | grep -q "CYGWIN" ) ; then + ${MAKE_CMD} -fMakefile clean + fi +fi diff --git a/Casting_2/test/Casting_2/data/test01.txt b/Casting_2/test/Casting_2/data/test01.txt new file mode 100644 index 00000000000..f46664e34c8 --- /dev/null +++ b/Casting_2/test/Casting_2/data/test01.txt @@ -0,0 +1,7 @@ +4 +0 0 1 0 1 1 0 1 +4 +0 0 -1 0 -1 +1 1 0 1 0 +2 0 1 0 1 +3 -1 0 -1 0 diff --git a/Casting_2/test/Casting_2/test_single_mold_translational_casting.cmd b/Casting_2/test/Casting_2/test_single_mold_translational_casting.cmd new file mode 100644 index 00000000000..e8f30c0cf64 --- /dev/null +++ b/Casting_2/test/Casting_2/test_single_mold_translational_casting.cmd @@ -0,0 +1,15 @@ +./data/test01.txt +# ./data/test02.txt +# ./data/test03.txt +# ./data/test04.txt +# ./data/test05.txt +# ./data/test06.txt +# ./data/test07.txt +# ./data/test08.txt +# ./data/test09.txt +# ./data/test10.txt +# ./data/test11.txt +# ./data/test12.txt +# ./data/test13.txt +# ./data/test14.txt +# ./data/test15.txt diff --git a/Casting_2/test/Casting_2/test_single_mold_translational_casting.cpp b/Casting_2/test/Casting_2/test_single_mold_translational_casting.cpp new file mode 100644 index 00000000000..11c33dfe2af --- /dev/null +++ b/Casting_2/test/Casting_2/test_single_mold_translational_casting.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; +typedef CGAL::Polygon_2 Polygon_2; +typedef Kernel::Direction_2 Direction_2; +typedef Kernel::Point_2 Point_2; + +typedef std::pair Direction_range; +typedef std::pair Top_edge; + +struct Top_edge_comparer { + bool operator()(const Top_edge& a, const Top_edge& b) + { + auto facet_a = a.first; + const auto& d1_a = a.second.first; + const auto& d2_a = a.second.second; + auto facet_b = b.first; + const auto& d1_b = b.second.first; + const auto& d2_b = b.second.second; + + if (a.first < b.first) return true; + if (a.first > b.first) return false; + if (a.second.first < b.second.first) return true; + if (a.second.first > b.second.first) return false; + return a.second.second < b.second.second; + } +}; + +bool test_one_file(std::ifstream& inp) +{ + Polygon_2 pgn; + inp >> pgn; + // std::cout << pgn << std::endl; + + std::vector top_edges; + CGAL::single_mold_translational_casting_2(pgn, std::back_inserter(top_edges)); + + size_t exp_num_top_edges; + inp >> exp_num_top_edges; + // std::cout << "Exp. no. of top facets: " << exp_num_top_edges << std::endl; + std::vector exp_top_edges(exp_num_top_edges); + for (auto& top_edge : exp_top_edges) { + size_t facet; + Direction_2 d1, d2; + inp >> facet >> d1 >> d2; + // std::cout << facet << " " << d1 << " " << d2 << std::endl; + top_edge = std::make_pair(facet, std::make_pair(d1, d2)); + } + + std::sort(top_edges.begin(), top_edges.end(), Top_edge_comparer()); + std::sort(exp_top_edges.begin(), exp_top_edges.end(), Top_edge_comparer()); + + if (top_edges.size() != exp_top_edges.size()) { + std::cerr << "Number of facets: " + << "obtain: " << top_edges.size() + << ", expected: " << exp_top_edges.size() + << std::endl; + return false; + } + auto exp_it = exp_top_edges.begin(); + size_t i(0); + for (auto it = top_edges.begin(); it != top_edges.end(); ++it, ++exp_it) { + auto facet = it->first; + const auto& d1 = it->second.first; + const auto& d2 = it->second.second; + auto exp_facet = exp_it->first; + const auto& exp_d1 = exp_it->second.first; + const auto& exp_d2 = exp_it->second.second; + if ((facet != exp_facet) || (d1 != exp_d1) || (d2 != exp_d2)) { + std::cerr << "Top edge[" << i++ << "]: " + << "obtained: " << facet << " " << d1 << " " << d2 + << ", expected: " << exp_facet << " " << exp_d1 << " " << exp_d2 + << std::endl; + return false; + } + } + return true; +} + +int main(int argc, char* argv[]) +{ + if (argc < 2) { + std::cerr << "Missing input file" << std::endl; + return -1; + } + + int success = 0; + for (size_t i = 1; i < argc; ++i) { + std::string str(argv[i]); + if (str.empty()) continue; + + auto itr = str.end(); + --itr; + while (itr != str.begin()) { + auto tmp = itr; + --tmp; + if (*itr == 't') break; + str.erase(itr); + itr = tmp; + } + if (str.size() <= 1) continue; + std::ifstream inp(str.c_str()); + if (!inp.is_open()) { + std::cerr << "Failed to open " << str << std::endl; + return -1; + } + if (! test_one_file(inp)) { + std::cout << str << ": ERROR" << std::endl; + ++success; + } + else std::cout << str << ": succeeded" << std::endl; + inp.close(); + } + + return success; +}