mirror of https://github.com/CGAL/cgal
First test
This commit is contained in:
parent
88f275c2a0
commit
aaa14948a9
|
|
@ -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()
|
||||
|
|
@ -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 <target>
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/find_single_mold_translational_casting_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
typedef CGAL::Polygon_2<Kernel> Polygon_2;
|
||||
typedef Kernel::Direction_2 Direction_2;
|
||||
typedef Kernel::Point_2 Point_2;
|
||||
|
||||
typedef std::pair<Direction_2, Direction_2> Direction_range;
|
||||
typedef std::pair<size_t, Direction_range> 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_edge> 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<Top_edge> 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;
|
||||
}
|
||||
Loading…
Reference in New Issue