Repository: DGtal-team/DGtal (language: python)

Issue:
Adapt the point size in QGLviewer
Adapt the scale for point size for the point visualisation as suggested by Martial.



Discussion / hints:
It is done in the last pull request...

OK


Fix patch:
diff --git a/.travis.yml b/.travis.yml
index c52676dcd0..b608bc3154 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,7 @@ dist: xenial
 # Reducing the depth when cloning using git
 # https://docs.travis-ci.com/user/customizing-the-build/#git-clone-depth
 git:
-  depth: 3
+  depth: 10
 
 compiler:
   - gcc
diff --git a/.travis/build_all.sh b/.travis/build_all.sh
index 660e5815f5..179e8b2b04 100755
--- a/.travis/build_all.sh
+++ b/.travis/build_all.sh
@@ -5,7 +5,8 @@ $SCRIPT_BEGIN
 "$SRC_DIR/.travis/install_eigen.sh"
 
 # Build options
-BTYPE="$BTYPE -DBUILD_EXAMPLES=false -DBUILD_TESTING=true"
+BTYPE="$BTYPE -DBUILD_EXAMPLES=false -DBUILD_TESTING=true\
+             -DDGTAL_RANDOMIZED_TESTING_THRESHOLD=33 -DDGTAL_RANDOMIZED_TESTING_WHITELIST=$(../.travis/create_whitelist.sh)"
 BTYPE="$BTYPE -DCMAKE_BUILD_TYPE=Debug -DWITH_MAGICK=true -DWITH_GMP=true\
               -DWITH_FFTW3=true -DWARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Debug \
               -DWITH_HDF5=true -DWITH_CAIRO=true -DWITH_QGLVIEWER=true \
diff --git a/.travis/build_dgtal_doc.sh b/.travis/build_dgtal_doc.sh
index 3ffa00bcde..676e389c18 100755
--- a/.travis/build_dgtal_doc.sh
+++ b/.travis/build_dgtal_doc.sh
@@ -4,7 +4,7 @@ $SCRIPT_BEGIN
 # OS dependent deps
 source "$SRC_DIR/.travis/install_eigen.sh"
 
-BTYPE="$BTYPE -DBUILD_EXAMPLES=true -DBUILD_TESTING=false"
+BTYPE="$BTYPE -DBUILD_EXAMPLES=false -DBUILD_TESTING=false"
 BTYPE="$BTYPE -DCMAKE_BUILD_TYPE=Debug -DWITH_MAGICK=true -DWITH_GMP=true\
                      -DWITH_FFTW3=true -DWARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Debug \
                      -DWITH_HDF5=true -DWITH_CAIRO=true -DWITH_QGLVIEWER=true -DWITH_EIGEN=true\
diff --git a/.travis/create_whitelist.sh b/.travis/create_whitelist.sh
new file mode 100755
index 0000000000..281c2bffc5
--- /dev/null
+++ b/.travis/create_whitelist.sh
@@ -0,0 +1,7 @@
+#!/bin/zsh
+
+foreach i (`git diff --name-only HEAD HEAD~5 | grep cpp`)
+ echo -e "$WL$i:r:t\c"
+ WL=";"
+end
+ 
diff --git a/.travis/getAndCheckDGtalTools.sh b/.travis/getAndCheckDGtalTools.sh
index 0b8916b385..eea9b0f1c2 100755
--- a/.travis/getAndCheckDGtalTools.sh
+++ b/.travis/getAndCheckDGtalTools.sh
@@ -7,7 +7,7 @@ cd "$SRC_DIR/.."
 git clone --depth 1 git://github.com/DGtal-team/DGtalTools.git
 cd DGtalTools
 mkdir build ; cd build
-cmake .. $BTYPE -G Ninja
+cmake .. $BTYPE -DDGTALTOOLS_RANDOMIZED_BUILD_THRESHOLD=25  -DDGTALTOOLS_RANDOMIZED_BUILD_WHITELIST="$(cat ../cmake/whiteListBuildTools.txt)"  -G Ninja
   #inplace
 ninja
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dfb766fa2a..97183fba96 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -88,16 +88,40 @@ include(OSDependentSettings)
 # -----------------------------------------------------------------------------
 include(CheckDGtalDependencies)
 
+include(CheckDGtalOptionalDependencies)
+
+
 # -----------------------------------------------------------------------------
-# Check Optional Dependencies
+# Randomized build 1/2.
 # -----------------------------------------------------------------------------
-include(CheckDGtalOptionalDependencies)
+SET(DGTAL_RANDOMIZED_TESTING_THRESHOLD "100" CACHE INTERNAL "Threshold for the random selection of unit tests to build.")
+SET(DGTAL_RANDOMIZED_TESTING_WHITELIST "" CACHE INTERNAL "List of whitelisted unit-test/examples to build.")
 
 # -----------------------------------------------------------------------------
-# Debug, Cpack and Ctest settings
+# Unit-testing, Cpack and Ctest settings
 # -----------------------------------------------------------------------------
 include(CpackCtest)
 
+#------------------------------------------------------------------------------
+# Examples
+#------------------------------------------------------------------------------
+include(BuildExamples)
+
+# -----------------------------------------------------------------------------
+# Randomized build 2/2.
+# -----------------------------------------------------------------------------
+if (BUILD_EXAMPLES OR BUILD_TESTING)
+ message(STATUS "Randomized examples/testing")
+ if (DGTAL_RANDOMIZED_TESTING_THRESHOLD EQUAL "100")
+  message(STATUS "All examples or unit-tests will be compiled (cmake variable DGTAL_RANDOMIZED_TESTING_THRESHOLD)")
+ else()
+  message(STATUS "Only ~${DGTAL_RANDOMIZED_TESTING_THRESHOLD}% of the (randomly selected) examples/tests will be  compiled/run")
+  message(STATUS "  (you can adjust this with the cmake variable DGTAL_RANDOMIZED_TESTING_THRESHOLD)")
+  message(STATUS " Whitelist: ${DGTAL_RANDOMIZED_TESTING_WHITELIST}")
+endif()
+message(STATUS "-------------------------------------------------------------------------------")
+endif()
+
 # -----------------------------------------------------------------------------
 # Code coverage
 # -----------------------------------------------------------------------------
@@ -108,11 +132,6 @@ include(CheckCoverage)
 # -----------------------------------------------------------------------------
 include(GeneratorSpecific)
 
-#------------------------------------------------------------------------------
-# Examples
-#------------------------------------------------------------------------------
-include(BuildExamples)
-
 # -----------------------------------------------------------------------------
 # Install settings
 # -----------------------------------------------------------------------------
diff --git a/ChangeLog.md b/ChangeLog.md
index a890225570..7ab745f4a1 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -12,6 +12,10 @@
   - Fix purple color.  (Bertrand Kerautret and Phuc Ngo
     [#1579](https://github.com/DGtal-team/DGtal/pull/1579))
 
+- *Build*
+  - New cmake option (DGTAL_RANDOMIZED_TESTING_THRESHOLD) to set the
+    (approximated) % of unit-tests to build and run for randomized
+    testing (David Coeurjolly [#1588](https://github.com/DGtal-team/DGtal/pull/1588))
 
 ## Bug fixes
 
diff --git a/appveyor.yml b/appveyor.yml
index 6fb513e204..2390095420 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -67,7 +67,7 @@ before_build:
   - IF %CACHEOK%==FALSE qmake -t vclib QGLViewer.pro -spec win32-msvc2013 -o  qglviewer.vcxproj
   - IF %CACHEOK%==FALSE msbuild /m /p:Configuration=%CONFIGQGL% /p:Platform=%B_NAME% qglviewer.vcxproj
   - cd %APPVEYOR_BUILD_FOLDER%
-  - cmake -Wno-dev -G"%VS_GEN%" -DCMAKE_BUILD_TYPE=%CONFIG% -DWITH_QGLVIEWER:BOOL=ON -DQGLVIEWER_INCLUDE_DIR=%QGLDIR%\libQGLViewer -DQGLVIEWER_LIBRARIES=%QGLDIR%\libQGLViewer\QGLViewer\QGLViewer2.lib -DWITH_QT5:BOOL=ON -DBUILD_EXAMPLES:BOOL=ON -DBUILD_TESTING:BOOL=OFF -DBUILD_SHARED_LIBS:BOOL=FALSE   -DZLIB_LIBRARY=c:/zlib-install/lib/zlibd.lib -DZLIB_INCLUDE_DIR=c:/zlib-install/include/ -DBOOST_ROOT=%BOOST_ROOT% -DBOOST_LIBRARYDIR=%BOOST_LIBRARYDIR% .
+  - cmake -Wno-dev -G"%VS_GEN%" -DCMAKE_BUILD_TYPE=%CONFIG% -DDGTAL_RANDOMIZED_TESTING_THRESHOLD=33 -DWITH_QGLVIEWER:BOOL=ON -DQGLVIEWER_INCLUDE_DIR=%QGLDIR%\libQGLViewer -DQGLVIEWER_LIBRARIES=%QGLDIR%\libQGLViewer\QGLViewer\QGLViewer2.lib -DWITH_QT5:BOOL=ON -DBUILD_EXAMPLES:BOOL=ON -DBUILD_TESTING:BOOL=OFF -DBUILD_SHARED_LIBS:BOOL=FALSE   -DZLIB_LIBRARY=c:/zlib-install/lib/zlibd.lib -DZLIB_INCLUDE_DIR=c:/zlib-install/include/ -DBOOST_ROOT=%BOOST_ROOT% -DBOOST_LIBRARYDIR=%BOOST_LIBRARYDIR% .
 
   
 #  - cmake -Wno-dev -G"%VS_GEN%" -DCMAKE_BUILD_TYPE=%CONFIG% -DGDCM_BUILD_TESTING:BOOL=ON -DGDCM_BUILD_APPLICATIONS:BOOL=ON -DGDCM_BUILD_SHARED_LIBS:BOOL=ON -DGDCM_ALLOW_INSOURCE_BUILD:BOOL=ON -DBUILDNAME:STRING=%COMPUTERNAME%-%B_NAME% -DGDCM_WRAP_CSHARP:BOOL=ON -DGDCM_WRAP_JAVA:BOOL=ON -DGDCM_WRAP_PYTHON:BOOL=ON -DGDCM_USE_PVRG:BOOL=ON .
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 752570fdfa..61a6fadf91 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -16,6 +16,10 @@ link_directories (${PROJECT_BINARY_DIR})
 configure_file(${PROJECT_SOURCE_DIR}/examples/ConfigExamples.h.in 
   ${PROJECT_BINARY_DIR}/examples/ConfigExamples.h)
 
+# For DGtal_add_example function
+include(ExampleFunctions.cmake)
+
+
 #------Examples subdirectories ------
 
 add_subdirectory(images)
diff --git a/examples/ExampleFunctions.cmake b/examples/ExampleFunctions.cmake
new file mode 100644
index 0000000000..429e27b97e
--- /dev/null
+++ b/examples/ExampleFunctions.cmake
@@ -0,0 +1,11 @@
+# DGTAL_RANDOMIZED_TESTING_THRESHOLD must be a global variable between 0 and 99
+
+function(DGtal_add_example test_file) #optional_avoid_add_test
+  string(RANDOM LENGTH 2 ALPHABET "0123456789" _random)
+  if (${_random} LESS ${DGTAL_RANDOMIZED_TESTING_THRESHOLD}  OR ${test_file} IN_LIST DGTAL_RANDOMIZED_TESTING_WHITELIST)
+    add_executable(${test_file} ${test_file}.cpp)
+    target_link_libraries (${test_file} PRIVATE DGtal)
+    target_include_directories(${test_file} PRIVATE ${PROJECT_SOURCE_DIR}/examples/)
+    target_include_directories(${test_file} PRIVATE ${PROJECT_BINARY_DIR}/examples/)
+  endif()
+endfunction()
diff --git a/examples/arithmetic/CMakeLists.txt b/examples/arithmetic/CMakeLists.txt
index 90ae8bf2c3..f1bb0df6c3 100644
--- a/examples/arithmetic/CMakeLists.txt
+++ b/examples/arithmetic/CMakeLists.txt
@@ -7,8 +7,7 @@ set(DGTAL_EXAMPLES_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries ( ${FILE} DGtal)
+     DGtal_add_example(${FILE})
 endforeach()
 
 if ( WITH_GMP )
@@ -17,8 +16,7 @@ if ( WITH_GMP )
       extended-euclid
   )
   foreach(FILE ${DGTAL_EXAMPLES_GMP_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
-  endforeach()
+      DGtal_add_example(${FILE})
+ endforeach()
 
 endif()
diff --git a/examples/base/CMakeLists.txt b/examples/base/CMakeLists.txt
index 694ff67b20..eb655a0e3d 100644
--- a/examples/base/CMakeLists.txt
+++ b/examples/base/CMakeLists.txt
@@ -4,6 +4,5 @@ set(DGTAL_EXAMPLES_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
diff --git a/examples/dec/CMakeLists.txt b/examples/dec/CMakeLists.txt
index 9a55f14d6f..71e2f0d9d0 100644
--- a/examples/dec/CMakeLists.txt
+++ b/examples/dec/CMakeLists.txt
@@ -9,8 +9,7 @@ if (WITH_CAIRO AND WITH_EIGEN AND WITH_QGLVIEWER)
         )
 
     foreach(FILE ${DGTAL_EXAMPLES_SRC_DEC})
-        add_executable(${FILE} ${FILE}.cpp)
-        target_link_libraries (${FILE} DGtal)
+      DGtal_add_example(${FILE})
     endforeach()
 
 endif()
@@ -22,7 +21,6 @@ if (WITH_EIGEN)
         )
 
     foreach(FILE ${DGTAL_EXAMPLES_SRC2_DEC})
-        add_executable(${FILE} ${FILE}.cpp)
-        target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
     endforeach()
 endif()
diff --git a/examples/doc-examples/CMakeLists.txt b/examples/doc-examples/CMakeLists.txt
index 4c653d081e..a22ecd8a71 100644
--- a/examples/doc-examples/CMakeLists.txt
+++ b/examples/doc-examples/CMakeLists.txt
@@ -18,14 +18,12 @@ if( WITH_VISU3D_QGLVIEWER  )
      )
 
 foreach(FILE ${DGTAL_DOC_EX_SRC_QGL})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE}  DGtal)
+   DGtal_add_example(${FILE})
 endforeach()
 
 endif()
 
 
 foreach(FILE ${DGTAL_DOC_EX_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal )
+   DGtal_add_example(${FILE})
 endforeach()
diff --git a/examples/geometry/curves/CMakeLists.txt b/examples/geometry/curves/CMakeLists.txt
index 336ecc4898..97aba1773f 100644
--- a/examples/geometry/curves/CMakeLists.txt
+++ b/examples/geometry/curves/CMakeLists.txt
@@ -23,8 +23,7 @@ set(DGTAL_EXAMPLES_SRC
 
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
 endforeach()
 
 
@@ -34,8 +33,7 @@ if(MAGICK++_FOUND)
     freemanChainDisplay
     )
   foreach(FILE ${DGTALE_EXAMPLES_IO_Magick})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
   endforeach()
 endif()
 
@@ -52,8 +50,7 @@ if (  WITH_VISU3D_QGLVIEWER )
      )
 
   foreach(FILE ${DGTAL_EXAMPLES_QGL_SRC} )
-   add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+      DGtal_add_example(${FILE})
   endforeach()
 
 endif()
diff --git a/examples/geometry/curves/estimation/CMakeLists.txt b/examples/geometry/curves/estimation/CMakeLists.txt
index a21fa866a8..07d7fcf22f 100644
--- a/examples/geometry/curves/estimation/CMakeLists.txt
+++ b/examples/geometry/curves/estimation/CMakeLists.txt
@@ -7,6 +7,5 @@ set(DGTAL_EXAMPLES_SRC
 
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
diff --git a/examples/geometry/surfaces/CMakeLists.txt b/examples/geometry/surfaces/CMakeLists.txt
index 46f06d112d..98ffb18fab 100644
--- a/examples/geometry/surfaces/CMakeLists.txt
+++ b/examples/geometry/surfaces/CMakeLists.txt
@@ -8,8 +8,7 @@ set(DGTAL_EXAMPLES_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
 
 
@@ -25,8 +24,7 @@ if (  WITH_VISU3D_QGLVIEWER )
     exampleMaximalSegmentSliceEstimation
    )
   foreach(FILE ${DGTAL_EXAMPLES_QGL_SRC})
-   add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries ( ${FILE}  DGtal)
-  endforeach()
+      DGtal_add_example(${FILE})
+ endforeach()
 
 endif()
diff --git a/examples/geometry/tools/CMakeLists.txt b/examples/geometry/tools/CMakeLists.txt
index bfe4896226..4b5d7b5777 100644
--- a/examples/geometry/tools/CMakeLists.txt
+++ b/examples/geometry/tools/CMakeLists.txt
@@ -14,8 +14,7 @@ set(DGTAL_EXAMPLES_SRC
 
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+  DGtal_add_example(${FILE})
 endforeach()
 
 if ( WITH_GMP )
@@ -23,8 +22,7 @@ if ( WITH_GMP )
     checkLatticeBallQuickHull
   )
   foreach(FILE ${DGTAL_EXAMPLES_GMP_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+    DGtal_add_example(${FILE})
   endforeach()
 endif()
 
diff --git a/examples/geometry/tools/determinant/CMakeLists.txt b/examples/geometry/tools/determinant/CMakeLists.txt
index 6459fcdd1c..004ca13a9b 100644
--- a/examples/geometry/tools/determinant/CMakeLists.txt
+++ b/examples/geometry/tools/determinant/CMakeLists.txt
@@ -4,8 +4,7 @@ set(DGTAL_EXAMPLES_SRC
 
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
 
 
diff --git a/examples/geometry/volumes/CMakeLists.txt b/examples/geometry/volumes/CMakeLists.txt
index ba0a8c6e85..6bb7b975b0 100644
--- a/examples/geometry/volumes/CMakeLists.txt
+++ b/examples/geometry/volumes/CMakeLists.txt
@@ -5,7 +5,6 @@ set(DGTAL_EXAMPLES_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
 
diff --git a/examples/geometry/volumes/distance/CMakeLists.txt b/examples/geometry/volumes/distance/CMakeLists.txt
index c661e189fa..0ee9c079c4 100644
--- a/examples/geometry/volumes/distance/CMakeLists.txt
+++ b/examples/geometry/volumes/distance/CMakeLists.txt
@@ -7,8 +7,7 @@ set(DGTAL_EXAMPLES_SRC
 
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
 
 if (  WITH_VISU3D_QGLVIEWER )
@@ -17,8 +16,7 @@ if (  WITH_VISU3D_QGLVIEWER )
   exampleFMM3D
    )
   foreach(FILE ${DGTAL_EXAMPLES_QGL_SRC}) 
-   add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries ( ${FILE}  DGtal)   
+     DGtal_add_example(${FILE})
   endforeach()
 
 endif()
diff --git a/examples/graph/CMakeLists.txt b/examples/graph/CMakeLists.txt
index 165b3f7509..fa31efc13f 100644
--- a/examples/graph/CMakeLists.txt
+++ b/examples/graph/CMakeLists.txt
@@ -3,8 +3,7 @@ set(DGTAL_EXAMPLES_TOPO_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_TOPO_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE}  DGtal)
+     DGtal_add_example(${FILE})
 endforeach()
 
 
@@ -13,8 +12,7 @@ if ( WITH_VISU3D_QGLVIEWER )
      volDistanceTraversal
    )
    foreach(FILE ${DGTAL_EXAMPLES_QGL_SRC})
-     add_executable(${FILE} ${FILE}.cpp)
-     target_link_libraries (${FILE}  DGtal)
+     DGtal_add_example(${FILE})
    endforeach()
 endif()
 
diff --git a/examples/images/CMakeLists.txt b/examples/images/CMakeLists.txt
index 9ac6debb56..ddf7c7d200 100644
--- a/examples/images/CMakeLists.txt
+++ b/examples/images/CMakeLists.txt
@@ -4,9 +4,8 @@ set(QGLVIEWER_EXAMPLES_SRC
 
 if (  WITH_VISU3D_QGLVIEWER )
   foreach(FILE ${QGLVIEWER_EXAMPLES_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
-  endforeach()
+    DGtal_add_example(${FILE})
+ endforeach()
 endif()
 
 set(DGTAL_EXAMPLES_SRC
@@ -28,6 +27,5 @@ if( WITH_HDF5 )
 endif()
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal)
+   DGtal_add_example(${FILE})
 endforeach()
diff --git a/examples/io/CMakeLists.txt b/examples/io/CMakeLists.txt
index 8466c9b248..32920bd700 100644
--- a/examples/io/CMakeLists.txt
+++ b/examples/io/CMakeLists.txt
@@ -3,8 +3,7 @@ set(DGTAL_EXAMPLES_IO_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_IO_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal)
+   DGtal_add_example(${FILE})
 endforeach()
 
 
@@ -16,8 +15,7 @@ if (  WITH_VISU3D_QGLVIEWER )
     viewDualSurface
     )
   foreach(FILE ${DGTAL_EXAMPLES_QGL_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
   endforeach()
 
   add_subdirectory(viewers)
diff --git a/examples/io/boards/CMakeLists.txt b/examples/io/boards/CMakeLists.txt
index a0909e78eb..0e3a610ba2 100644
--- a/examples/io/boards/CMakeLists.txt
+++ b/examples/io/boards/CMakeLists.txt
@@ -29,8 +29,7 @@ endif()
 
 
 FOREACH(FILE ${DGTAL_TESTS_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal )
+     DGtal_add_example(${FILE})
 endforeach()
 
 
diff --git a/examples/io/viewers/CMakeLists.txt b/examples/io/viewers/CMakeLists.txt
index 38cb04bcdf..8b106b7209 100644
--- a/examples/io/viewers/CMakeLists.txt
+++ b/examples/io/viewers/CMakeLists.txt
@@ -22,14 +22,12 @@ set(DGTAL_TESTS_GMP_SRC
 )
 
 foreach(FILE ${DGTAL_TESTS_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
 endforeach()
 
 if(GMP_FOUND)
   foreach(FILE ${DGTAL_TESTS_GMP_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
   endforeach()
 endif()
 
diff --git a/examples/kernel/CMakeLists.txt b/examples/kernel/CMakeLists.txt
index 9186d85572..bec888bb12 100644
--- a/examples/kernel/CMakeLists.txt
+++ b/examples/kernel/CMakeLists.txt
@@ -9,6 +9,5 @@ if(WITH_OPENMP)
 endif()
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
diff --git a/examples/math/CMakeLists.txt b/examples/math/CMakeLists.txt
index 2dfbcf2880..a7c2c0375e 100644
--- a/examples/math/CMakeLists.txt
+++ b/examples/math/CMakeLists.txt
@@ -5,6 +5,5 @@ set(DGTAL_EXAMPLES_MATH_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_MATH_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
 endforeach()
diff --git a/examples/shapes/CMakeLists.txt b/examples/shapes/CMakeLists.txt
index 0910e3bf1e..803fe04e09 100644
--- a/examples/shapes/CMakeLists.txt
+++ b/examples/shapes/CMakeLists.txt
@@ -4,8 +4,7 @@ set(DGTAL_EXAMPLES_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+     DGtal_add_example(${FILE})
 endforeach()
 
 ### with QGLViewer
@@ -17,8 +16,7 @@ if (  WITH_VISU3D_QGLVIEWER )
      exampleSurfaceMesh
   )
   foreach(FILE ${DGTAL_SHAPES_EXAMPLES_QGL_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
   endforeach()
 
 endif()
@@ -30,8 +28,7 @@ if (WITH_EIGEN AND WITH_QGLVIEWER)
         )
 
     foreach(FILE ${DGTAL_EXAMPLES_SRC_DEC})
-        add_executable(${FILE} ${FILE}.cpp)
-        target_link_libraries (${FILE} DGtal )
-    endforeach()
+      DGtal_add_example(${FILE})
+   endforeach()
 
 endif()
diff --git a/examples/topology/CMakeLists.txt b/examples/topology/CMakeLists.txt
index 136f6b16b3..4ac2c83d62 100644
--- a/examples/topology/CMakeLists.txt
+++ b/examples/topology/CMakeLists.txt
@@ -17,8 +17,7 @@ set(DGTAL_EXAMPLES_TOPO_SRC
 )
 
 foreach(FILE ${DGTAL_EXAMPLES_TOPO_SRC})
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal)
+       DGtal_add_example(${FILE})
 endforeach()
 
 
@@ -39,8 +38,7 @@ if (  WITH_VISU3D_QGLVIEWER )
      digitalSurfaceSlice
    )
   foreach(FILE ${DGTAL_EXAMPLES_QGL_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries (${FILE} DGtal)
+     DGtal_add_example(${FILE})
   endforeach()
 
 endif()
diff --git a/examples/tutorial-examples/CMakeLists.txt b/examples/tutorial-examples/CMakeLists.txt
index c9521e821b..0bfc24b8fe 100644
--- a/examples/tutorial-examples/CMakeLists.txt
+++ b/examples/tutorial-examples/CMakeLists.txt
@@ -13,12 +13,10 @@ set(DGTAL_TUTO_EXAMPLES_SRC
 
 
 foreach(FILE ${DGTAL_TUTO_EXAMPLES_SRC})
-  if(MSVC)
-    set_source_files_properties( ${FILE} PROPERTIES COMPILE_FLAGS "/bigobj" )
-  endif()
-
-  add_executable(${FILE} ${FILE}.cpp)
-  target_link_libraries (${FILE} DGtal  )
+    DGtal_add_example(${FILE})
+   if(MSVC)
+     set_source_files_properties( ${FILE} PROPERTIES COMPILE_FLAGS "/bigobj" )
+   endif()
 endforeach()
 
 if (WITH_VISU3D_QGLVIEWER)
@@ -28,8 +26,7 @@ if (WITH_VISU3D_QGLVIEWER)
     polyhedralizer
   )
   foreach(FILE ${DGTAL_TUTO_EXAMPLES_QGL_SRC})
-    add_executable(${FILE} ${FILE}.cpp)
-    target_link_libraries ( ${FILE} DGtal)
+     DGtal_add_example(${FILE})
   endforeach()
 
 endif()


Test patch:
diff --git a/cmake/CpackCtest.cmake b/cmake/CpackCtest.cmake
index bf3f936e38..c91665e716 100644
--- a/cmake/CpackCtest.cmake
+++ b/cmake/CpackCtest.cmake
@@ -38,9 +38,9 @@ INCLUDE(CPack)
 # CTest/Debug options
 # -----------------------------------------------------------------------------
 if (BUILD_TESTING)
+  message(STATUS "Build test files ENABLED")
   ENABLE_TESTING()
   include(CTest)
-  message(STATUS "Build test files ENABLED")
   if (CMAKE_COMPILER_IS_GNUCXX)
     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -Wall -Wextra -pedantic -W -Wshadow -Wunused-variable  -Wunused-parameter -Wunused-function        -Wunused  -Wno-long-long -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage")
   endif()
diff --git a/tests/TestFunctions.cmake b/tests/TestFunctions.cmake
index db3de86677..e54d9b71f8 100644
--- a/tests/TestFunctions.cmake
+++ b/tests/TestFunctions.cmake
@@ -1,9 +1,14 @@
+# DGTAL_RANDOMIZED_TESTING_THRESHOLD must be a global variable between 0 and 99
+
 function(DGtal_add_test test_file) #optional_avoid_add_test
-  add_executable(${test_file} ${test_file}.cpp)
-  target_link_libraries (${test_file} PRIVATE DGtal Catch2::Catch2 DGtalCatch)
-  target_include_directories(${test_file} PRIVATE ${PROJECT_SOURCE_DIR}/tests/)
-  target_include_directories(${test_file} PRIVATE ${PROJECT_BINARY_DIR}/tests/)
-  if(NOT ${ARGC} GREATER 1)
-    add_test(${test_file} ${test_file})
+  string(RANDOM LENGTH 2 ALPHABET "0123456789" _random)
+   if (${_random} LESS ${DGTAL_RANDOMIZED_TESTING_THRESHOLD}  OR ${test_file} IN_LIST DGTAL_RANDOMIZED_TESTING_WHITELIST)
+   add_executable(${test_file} ${test_file}.cpp)
+    target_link_libraries (${test_file} PRIVATE DGtal Catch2::Catch2 DGtalCatch)
+    target_include_directories(${test_file} PRIVATE ${PROJECT_SOURCE_DIR}/tests/)
+    target_include_directories(${test_file} PRIVATE ${PROJECT_BINARY_DIR}/tests/)
+    if(NOT ${ARGC} GREATER 1)
+      add_test(${test_file} ${test_file})
+    endif()
   endif()
 endfunction()
diff --git a/tests/kernel/testLinearAlgebra.cpp b/tests/kernel/testLinearAlgebra.cpp
index 8961cebae4..2c12bc5cc2 100644
--- a/tests/kernel/testLinearAlgebra.cpp
+++ b/tests/kernel/testLinearAlgebra.cpp
@@ -70,7 +70,6 @@ bool testLinearAlgebra()
   
   return nbok == nb;
 }
-
 ///////////////////////////////////////////////////////////////////////////////
 // Standard services - public :