Add Test & Examples
Tests: - Add cc test - Add python test Examples: - Add examples/cpp - Add examples/data - Add examples/notebook - Add examples/python Signed-off-by: Corentin Le Molgat <corentinl@google.com>
This commit is contained in:
@@ -62,3 +62,10 @@ include(cpp)
|
||||
include(python)
|
||||
include(java)
|
||||
include(csharp)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(examples/cpp)
|
||||
add_subdirectory(examples/data)
|
||||
add_subdirectory(examples/python)
|
||||
add_subdirectory(examples/notebook)
|
||||
endif()
|
||||
|
||||
@@ -147,3 +147,24 @@ add_custom_target(bdist ALL
|
||||
COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_wheel
|
||||
)
|
||||
|
||||
# Test
|
||||
if(BUILD_TESTING)
|
||||
# Testing using a vitual environment
|
||||
set(VENV_EXECUTABLE ${PYTHON_EXECUTABLE} -m virtualenv)
|
||||
set(VENV_DIR ${CMAKE_BINARY_DIR}/venv)
|
||||
if(WIN32)
|
||||
set(VENV_BIN_DIR "${VENV_DIR}\\Scripts")
|
||||
else()
|
||||
set(VENV_BIN_DIR ${VENV_DIR}/bin)
|
||||
endif()
|
||||
# make a virtualenv to install our python package in it
|
||||
add_custom_command(TARGET bdist POST_BUILD
|
||||
COMMAND ${VENV_EXECUTABLE} -p ${PYTHON_EXECUTABLE} ${VENV_DIR}
|
||||
COMMAND ${VENV_BIN_DIR}/python setup.py install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test.py.in
|
||||
${VENV_DIR}/test.py
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
# run the tests within the virtualenv
|
||||
add_test(pytest_venv ${VENV_BIN_DIR}/python ${VENV_DIR}/test.py)
|
||||
endif()
|
||||
|
||||
@@ -1,57 +1,126 @@
|
||||
ADD_LIBRARY(${PROJECT_NAME}examples SHARED
|
||||
cvrptw_lib.cc
|
||||
parse_dimacs_assignment.cc
|
||||
fap_model_printer.cc
|
||||
fap_parser.cc
|
||||
fap_utilities.cc)
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME}examples ${PROJECT_NAME})
|
||||
if (NOT BUILD_CXX)
|
||||
return()
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS ${PROJECT_NAME}examples
|
||||
EXPORT ${PROJECT_NAME}_Exports
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
project(ortools_examples)
|
||||
|
||||
ADD_DEPENDENCIES(${PROJECT_NAME}examples ${PROJECT_NAME}Proto)
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH
|
||||
"@loader_path/../..;@loader_path/../lib;@loader_path")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../../:$ORIGIN/../lib:$ORIGIN/")
|
||||
endif()
|
||||
|
||||
FOREACH(EXECUTABLE
|
||||
costas_array
|
||||
cryptarithm
|
||||
cvrp_disjoint_tw
|
||||
cvrptw
|
||||
cvrptw_with_breaks
|
||||
cvrptw_with_refueling
|
||||
cvrptw_with_resources
|
||||
cvrptw_with_stop_times_and_resources
|
||||
dimacs_assignment
|
||||
dobble_ls
|
||||
flow_api
|
||||
frequency_assignment_problem
|
||||
golomb
|
||||
integer_programming
|
||||
jobshop
|
||||
jobshop_earlytardy
|
||||
jobshop_ls
|
||||
jobshop_sat
|
||||
linear_assignment_api
|
||||
linear_programming
|
||||
linear_solver_protocol_buffers
|
||||
ls_api
|
||||
magic_square
|
||||
model_util
|
||||
mps_driver
|
||||
multidim_knapsack
|
||||
network_routing
|
||||
nqueens
|
||||
pdptw
|
||||
rcpsp_sat
|
||||
shift_minimization_sat
|
||||
solve
|
||||
sports_scheduling
|
||||
strawberry_fields_with_column_generation
|
||||
tsp
|
||||
weighted_tardiness_sat)
|
||||
ADD_EXECUTABLE(${EXECUTABLE} ${EXECUTABLE}.cc)
|
||||
TARGET_LINK_LIBRARIES(${EXECUTABLE} ${PROJECT_NAME}examples ${PROJECT_NAME})
|
||||
INSTALL(TARGETS ${EXECUTABLE} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
ENDFOREACH()
|
||||
set(_SRCS
|
||||
cvrptw_lib.cc
|
||||
fap_model_printer.cc
|
||||
fap_parser.cc
|
||||
fap_utilities.cc
|
||||
parse_dimacs_assignment.cc
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
add_library(${PROJECT_NAME} STATIC ${_SRCS})
|
||||
else()
|
||||
add_library(${PROJECT_NAME} SHARED ${_SRCS})
|
||||
endif()
|
||||
|
||||
get_filename_component(PARENT_SOURCE_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
|
||||
get_filename_component(PARENT_SOURCE_DIR ${PARENT_SOURCE_DIR} DIRECTORY)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${PARENT_SOURCE_DIR})
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ortools::ortools)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
foreach(EXECUTABLE
|
||||
costas_array
|
||||
cryptarithm
|
||||
cvrp_disjoint_tw
|
||||
cvrptw
|
||||
cvrptw_with_breaks
|
||||
cvrptw_with_refueling
|
||||
cvrptw_with_resources
|
||||
cvrptw_with_stop_times_and_resources
|
||||
dimacs_assignment
|
||||
dobble_ls
|
||||
flow_api
|
||||
frequency_assignment_problem
|
||||
golomb
|
||||
integer_programming
|
||||
jobshop
|
||||
jobshop_earlytardy
|
||||
jobshop_ls
|
||||
jobshop_sat
|
||||
linear_assignment_api
|
||||
linear_programming
|
||||
linear_solver_protocol_buffers
|
||||
ls_api
|
||||
magic_square
|
||||
model_util
|
||||
mps_driver
|
||||
multidim_knapsack
|
||||
network_routing
|
||||
nqueens
|
||||
pdptw
|
||||
rcpsp_sat
|
||||
shift_minimization_sat
|
||||
solve
|
||||
sports_scheduling
|
||||
strawberry_fields_with_column_generation
|
||||
tsp
|
||||
weighted_tardiness_sat)
|
||||
add_executable(${EXECUTABLE} ${EXECUTABLE}.cc)
|
||||
target_link_libraries(${EXECUTABLE} ${PROJECT_NAME})
|
||||
install(TARGETS ${EXECUTABLE}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endforeach()
|
||||
|
||||
|
||||
foreach(TEST
|
||||
costas_array
|
||||
cryptarithm
|
||||
cvrp_disjoint_tw
|
||||
cvrptw
|
||||
#cvrptw_with_breaks # Too long
|
||||
#cvrptw_with_refueling # Too long
|
||||
cvrptw_with_resources
|
||||
cvrptw_with_stop_times_and_resources
|
||||
#dimacs_assignment
|
||||
#dobble_ls # Too long
|
||||
flow_api
|
||||
#frequency_assignment_problem
|
||||
golomb
|
||||
integer_programming
|
||||
#jobshop
|
||||
#jobshop_earlytardy
|
||||
#jobshop_ls
|
||||
#jobshop_sat
|
||||
linear_assignment_api
|
||||
linear_programming
|
||||
linear_solver_protocol_buffers
|
||||
ls_api
|
||||
magic_square
|
||||
#model_util
|
||||
mps_driver
|
||||
#multidim_knapsack
|
||||
#network_routing
|
||||
nqueens
|
||||
#pdptw
|
||||
#rcpsp_sat
|
||||
#shift_minimization_sat
|
||||
#solve
|
||||
#sports_scheduling # Too long
|
||||
#strawberry_fields_with_column_generation # Too long
|
||||
tsp
|
||||
#weighted_tardiness_sat
|
||||
)
|
||||
add_test(NAME cc_${TEST} COMMAND ${TEST})
|
||||
endforeach()
|
||||
|
||||
6
examples/data/CMakeLists.txt
Normal file
6
examples/data/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
if (NOT BUILD_PYTHON)
|
||||
return()
|
||||
endif()
|
||||
|
||||
install(DIRECTORY .
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/ortools/examples/data)
|
||||
7
examples/notebook/CMakeLists.txt
Normal file
7
examples/notebook/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
if (NOT BUILD_PYTHON)
|
||||
return()
|
||||
endif()
|
||||
|
||||
install(DIRECTORY .
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/ortools/examples/notebook
|
||||
FILES_MATCHING PATTERN "*.ipynb")
|
||||
20
examples/python/CMakeLists.txt
Normal file
20
examples/python/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
if (NOT BUILD_PYTHON)
|
||||
return()
|
||||
endif()
|
||||
|
||||
foreach(TEST
|
||||
hidato_table
|
||||
integer_programming
|
||||
knapsack
|
||||
linear_programming
|
||||
pyflow_example
|
||||
tsp
|
||||
)
|
||||
add_test(py${TEST}_venv ${VENV_BIN_DIR}/python ${CMAKE_CURRENT_SOURCE_DIR}/${TEST}.py)
|
||||
set_tests_properties(py${TEST}_venv PROPERTIES DEPENDS build_venv)
|
||||
endforeach()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(DIRECTORY .
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/ortools/examples/python
|
||||
FILES_MATCHING PATTERN "*.py")
|
||||
@@ -1,4 +1,5 @@
|
||||
from ortools.linear_solver import pywraplp
|
||||
from ortools.linear_solver import linear_solver_pb2
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
from ortools.sat import pywrapsat
|
||||
from ortools.graph import pywrapgraph
|
||||
|
||||
Reference in New Issue
Block a user