Skip to content

Commit

Permalink
Merge pull request #1019 from dcoeurjo/catch
Browse files Browse the repository at this point in the history
C++ unit test framework with Catch
  • Loading branch information
JacquesOlivierLachaud committed Sep 7, 2015
2 parents fda77b3 + b60e93b commit f504b24
Show file tree
Hide file tree
Showing 9 changed files with 9,624 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

## New Features / Critical Changes

- *Configuration*
- *Configuration/General*
- Continuous integration enabled on both linux and macosx
systems. Furthermore, the nightly build documentation is
automatically deployed. (David Coeurjolly,
[#955](https://github.com/DGtal-team/DGtal/pull/955))
- New unit test framework based on
[catch](https://github.com/philsquared/Catch). Catch allows to
design quick and efficient unit tests with nice trace
outputs. (David Coeurjolly,
[#1019](https://github.com/DGtal-team/DGtal/pull/1019)


## Changes

Expand Down
3 changes: 2 additions & 1 deletion src/DGtal/kernel/PointVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,9 @@ namespace DGtal
* a unitary vector on double.
*
* @return a unitary vector with double as coordiante type.
* @advanced the point container is forced to boost::array<double,dim>
*/
PointVector<dim, double, Container> getNormalized() const;
PointVector<dim, double, boost::array<double,dim> > getNormalized() const;


// ------------------------- Standard vectors ------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/DGtal/kernel/PointVector.ih
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ DGtal::PointVector<dim, TComponent, TContainer>::normInfinity() const

template<DGtal::Dimension dim, typename TComponent, typename TContainer>
inline
typename DGtal::PointVector<dim, double, TContainer>
typename DGtal::PointVector<dim, double, boost::array<double,dim> >
DGtal::PointVector<dim, TComponent, TContainer>::getNormalized() const
{
PointVector<dim,double,Container> normalized =(*this);
PointVector<dim,double,boost::array<double,dim> > normalized =(*this);
normalized /= normalized.norm();
return normalized;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/DGtalCatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @file DGtalCatch.h
* @author David COEURJOLLY <David Coeurjolly <[email protected]>>
* @date 28 Aug. 2015
* @brief Header file to enable catch unit test framework in DGtal.
**/

#pragma once
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
2 changes: 1 addition & 1 deletion tests/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SET(DGTAL_TESTS_SRC
testCloneAndAliases
testClone2
testOwningOrAliasingPtr
)
testCatch)

FOREACH(FILE ${DGTAL_TESTS_SRC})
add_executable(${FILE} ${FILE})
Expand Down
57 changes: 57 additions & 0 deletions tests/base/testCatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**/

/**
* @file testCatch
* @ingroup Tests
* @author David Coeurjolly (\c [email protected] )
*
*
* @date 2015/08/06
*
* This file is part of the DGtal library
*/

/**
* Description of testCatch' <p>
* Aim: simple test of \ref Catch unit test framework
*/

#include "DGtalCatch.h"

TEST_CASE( "Point Vector Unit tests" )
{

int a = 5;
int b = 3+2;
int c = a+1;

SECTION("Comparisons")
{
REQUIRE( (a == b) );
a=6;
REQUIRE( (a == c) );
}

SECTION("No side-effects on global variables in section scopes")
{
REQUIRE( (a == 5) );
}

}


/** @ingroup Tests **/
Loading

0 comments on commit f504b24

Please sign in to comment.