Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kthohr committed Aug 13, 2017
1 parent d87a925 commit b4b5d3e
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 5 deletions.
4 changes: 1 addition & 3 deletions include/determine_bounds_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ determine_bounds_type(const bool vals_bound, const int n_vals, const arma::vec&
} else if ( !std::isfinite(lower_bounds(i)) && std::isfinite(upper_bounds(i)) ) {
// upper bound only
ret_vec(i) = 3;
} else {
printf("determine_bounds_type: unknown error\n");
}
} // if both are infinite, this is covered by the base case
}
}
//
Expand Down
8 changes: 7 additions & 1 deletion tests/cov_setup
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ export CXXCOV=gcov
export LD_LIBRARY_PATH="$PWD":$LD_LIBRARY_PATH
cd tests

cd examples
./configure -b dev -c
make
./cov_check

cd ..
cd ../unit_tests
./configure -b dev -c
make
./cov_check

cd ../..
rm -rf ./include/armadillo*
cd tests
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/configure → tests/examples/configure
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ MCMC_SHLIB_NAME="mcmc"

if [[ "${MCMC_BUILD}" == "dev" ]]; then
echo "MCMC: dev version"
cd ..
cd ../..
MCMC_INCLUDE_PATH=${PWD}/include
MCMC_INSTALL_PATH=${PWD}
cd ${WDIR}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions tests/unit_tests/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# core compiling options
CC = @CC@
CXX = @CXX@
FC = @FC@

CXX_STD = -std=c++11
OPT_FLAGS = @MCMC_OPT_FLAGS@

ARMA_INCLUDE_PATH = @ARMA_INCLUDE_PATH@

# install location
INSTALL_PATH=@MCMC_INSTALL_PATH@

# source directories
SDIR = ./..
MCMC_DIR = $(SDIR)
MCMC_HEADER_DIR = @MCMC_INCLUDE_PATH@
MCMC_TEST_DIR = .

# general flags
CXXFLAGS = $(CXX_STD) -Wall $(OPT_FLAGS) -I$(ARMA_INCLUDE_PATH) -I$(MCMC_HEADER_DIR)
LIBS= -L@MCMC_INSTALL_PATH@ -l@MCMC_SHLIB_NAME@ @MCMC_BLAS_LAPACK@

# TraME Test Files
SOURCES_MCMC= $(MCMC_TEST_DIR)/determine_bounds_type.cpp $(MCMC_TEST_DIR)/log_jacobian.cpp $(MCMC_TEST_DIR)/rwmh.cpp $(MCMC_TEST_DIR)/transform_vals.cpp
OBJECTS_MCMC= $(SOURCES_MCMC:.cpp=.test)

all: $(OBJECTS_MCMC)

# core TraME files
$(MCMC_TEST_DIR)/%.test: $(MCMC_TEST_DIR)/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@ $(LIBS)

# cleanup and install
.PHONY: clean
clean:
@rm -rf *.so ./*.gcov ./*.gcno ./*.gcda ./*.dSYM ./*.test
92 changes: 92 additions & 0 deletions tests/unit_tests/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
## MCMC tests config script

while getopts b:c option
do
case "${option}"
in
b) MCMC_BUILD=${OPTARG};;
c) MCMC_COVERAGE="y";;
esac
done

if [ -z ${CC+x} ]; then
CC=gcc
fi
if [ -z ${CXX+x} ]; then
CXX=g++
fi
if [ -z ${FC+x} ]; then
FC=gfortran
fi

if [[ !(-z ${KEITH_DEV_SETTINGS+x}) ]]; then
CC=gcc-mp-7
CXX=g++-mp-7
FC=gfortran-mp-7
fi

WDIR=${PWD}

if [ -z ${ARMA_INCLUDE_PATH+x} ]; then
echo "MCMC: ARMA_INCLUDE_PATH not set"
if [ -f /usr/include/armadillo ]; then
ARMA_INCLUDE_PATH="/usr/include"
elif [ -f /usr/local/include/armadillo ]; then
ARMA_INCLUDE_PATH="/usr/local/include"
elif [ -f /opt/include/armadillo ]; then
ARMA_INCLUDE_PATH="/opt/include"
elif [ -f /opt/local/include/armadillo ]; then
ARMA_INCLUDE_PATH="/opt/local/include"
else
echo "MCMC tests: cannot find the armadillo library."
echo ""
exit 1
fi
fi

echo "MCMC tests: ARMA_INCLUDE_PATH set to ${ARMA_INCLUDE_PATH}"

# coverage build? used for codecov

if [[ "${MCMC_COVERAGE}" == "y" ]]; then
echo "MCMC tests: coverage build"
MCMC_OPT_FLAGS="-g -O0 -Wall --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
else
MCMC_OPT_FLAGS="-O3 -Wall"
fi

MCMC_SHLIB_NAME="mcmc"

# dev build

if [[ "${MCMC_BUILD}" == "dev" ]]; then
echo "MCMC: dev version"
cd ../..
MCMC_INCLUDE_PATH=${PWD}/include
MCMC_INSTALL_PATH=${PWD}
cd ${WDIR}
else
MCMC_INSTALL_PATH="/usr/local"
fi

# BLAS and LAPACK settings

if [[ $OSTYPE == darwin* ]] ; then
MCMC_BLAS_LAPACK="-framework Accelerate"
elif [[ $OSTYPE == *linux* ]] ; then
MCMC_BLAS_LAPACK="-lblas -llapack"
else
MCMC_BLAS_LAPACK="-lblas -llapack"
fi

sed -e "s|@CC@|${CC}|" \
-e "s|@CXX@|${CXX}|" \
-e "s|@FC@|${FC}|" \
-e "s|@ARMA_INCLUDE_PATH@|${ARMA_INCLUDE_PATH}|" \
-e "s|@MCMC_BLAS_LAPACK@|${MCMC_BLAS_LAPACK}|" \
-e "s|@MCMC_OPT_FLAGS@|${MCMC_OPT_FLAGS}|" \
-e "s|@MCMC_SHLIB_NAME@|${MCMC_SHLIB_NAME}|" \
-e "s|@MCMC_INCLUDE_PATH@|${MCMC_INCLUDE_PATH}|" \
-e "s|@MCMC_INSTALL_PATH@|${MCMC_INSTALL_PATH}|" \
Makefile.in > Makefile
16 changes: 16 additions & 0 deletions tests/unit_tests/cov_check
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

if [ -z ${CXXCOV+x} ]; then
CXXCOV=gcov
fi

if [[ !(-z ${KEITH_DEV_SETTINGS+x}) ]]; then
CXXCOV=gcov-mp-7
fi

for t in ./*.test; do
"$t"
done

for t in ./*.cpp; do
$CXXCOV "$t"
done
51 changes: 51 additions & 0 deletions tests/unit_tests/determine_bounds_type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*################################################################################
##
## Copyright (C) 2011-2017 Keith O'Hara
##
## This file is part of the MCMC C++ library.
##
## MCMC is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 of the License, or
## (at your option) any later version.
##
## MCMC 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.
##
################################################################################*/

/*
* unit test
*
* Keith O'Hara
* 08/12/2017
*
* This version:
* 08/12/2017
*/

#include "mcmc.hpp"

int main()
{
const bool vals_bound = true;
const int n_vals = 4;

arma::vec lb(n_vals);
lb(0) = 1;
lb(1) = 1;
lb(2) = -arma::datum::inf;
lb(3) = -arma::datum::inf;

arma::vec ub(n_vals);
ub(0) = 2;
ub(1) = arma::datum::inf;
ub(2) = 2;
ub(4) = arma::datum::inf;

arma::uvec bounds_type = determine_bounds_type(vals_bound,n_vals,lb,ub);

return 0;
}
57 changes: 57 additions & 0 deletions tests/unit_tests/log_jacobian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*################################################################################
##
## Copyright (C) 2011-2017 Keith O'Hara
##
## This file is part of the MCMC C++ library.
##
## MCMC is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 of the License, or
## (at your option) any later version.
##
## MCMC 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.
##
################################################################################*/

/*
* unit test
*
* Keith O'Hara
* 08/12/2017
*
* This version:
* 08/12/2017
*/

#include "mcmc.hpp"

int main()
{
const bool vals_bound = true;
const int n_vals = 4;

arma::vec lb(n_vals);
lb(0) = 0;
lb(1) = 0;
lb(2) = -arma::datum::inf;
lb(3) = -arma::datum::inf;

arma::vec ub(n_vals);
ub(0) = 2;
ub(1) = arma::datum::inf;
ub(2) = 2;
ub(4) = arma::datum::inf;

arma::uvec bounds_type = mcmc::determine_bounds_type(vals_bound,n_vals,lb,ub);

arma::vec initial_vals = arma::ones(n_vals,1);

arma::vec vals_trans = mcmc::transform(initial_vals,bounds_type,lb,ub);

double lj_val = log_jacobian(vals_trans,bounds_type,lb,ub);

return 0;
}
Loading

0 comments on commit b4b5d3e

Please sign in to comment.