Skip to content
Snippets Groups Projects
Commit 159c4f3e authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add tests

parent 33016bd8
No related branches found
No related tags found
No related merge requests found
......@@ -44,5 +44,6 @@ SET (${PROJECT_NAME}_HEADERS
PKG_CONFIG_APPEND_LIBS("hpp-statistics")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests)
SETUP_PROJECT_FINALIZE()
# Copyright 2012, 2013, 2014 CNRS-LAAS
#
# Author: Mathieu Geisert
#
# This file is part of hpp-core
# hpp-model-urdf 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.
#
# hpp-core 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 Lesser Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with hpp-core If not, see <http://www.gnu.org/licenses/>.
# ADD_TESTCASE(NAME)
# ------------------------
#
# Define a test named `NAME'.
#
# This macro will create a binary from `NAME.cc', link it against
# Boost and add it to the test suite.
#
MACRO(ADD_TESTCASE NAME GENERATED)
IF (${GENERATED} STREQUAL TRUE)
ADD_EXECUTABLE(${NAME} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.cc)
ELSE()
ADD_EXECUTABLE(${NAME} ${NAME}.cc)
ENDIF()
ADD_TEST(${NAME} ${RUNTIME_OUTPUT_DIRECTORY}/${NAME})
# Link against Boost and project library.
TARGET_LINK_LIBRARIES(${NAME}
${PROJECT_NAME}
)
ENDMACRO(ADD_TESTCASE)
ADD_TESTCASE (test-successstatistics FALSE)
// Copyright (c) 2014, LAAS-CNRS
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-statistics.
// hpp-statistics 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.
//
// hpp-statistics 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 Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-statistics. If not, see <http://www.gnu.org/licenses/>.
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include "hpp/statistics/success-bin.hh"
HPP_DEFINE_REASON_FAILURE (REASON_TEST, "Fake reason for testing purpose");
int main ()
{
/* initialize random seed: */
srand (time(NULL));
using namespace hpp::statistics;
SuccessStatistics ss;
unsigned int counter[3];
counter[0]=0; counter[1]=0; counter[2]=0;
for (int i = 0; i < 100; i++) {
unsigned int nb = rand() % 3;
counter[nb]++;
switch (nb) {
case 0:
ss.addSuccess ();
break;
case 1:
ss.addFailure ();
break;
case 2:
ss.addFailure (REASON_TEST);
break;
}
}
if ( ss.nbSuccess () != counter[0]
|| ss.nbFailure (SuccessBin::REASON_UNKNOWN) != counter[1]
|| ss.nbFailure (REASON_TEST) != counter[2]) {
std::cout << ss;
std::cout << "Real frequencies are: ( " << counter[0] << ", " << counter[1]
<< ", " << counter [2] << ")" << std::endl;
return EXIT_FAILURE;
}
if (ss.nbFailure () != counter[1] + counter[2])
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment