/usr/include/opengm/unittests/test.hxx is in libopengm-dev 2.3.6+20160905-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #pragma once
#ifndef OPENGM_TEST_HXX
#define OPENGM_TEST_HXX
#include <cstdlib>
#include <sstream>
#include <stdexcept>
#include <iostream>
#include <vector>
#include "opengm/opengm.hxx"
#include "opengm/utilities/indexing.hxx"
/// \cond HIDDEN_SYMBOLS
#define OPENGM_TEST(x) \
if(!(x)) { \
std::stringstream s; \
s << #x << " does not hold [line " << __LINE__ << "]"; \
throw std::logic_error(s.str().c_str()); \
exit(1); \
}
#define OPENGM_TEST_EQUAL(x, y) \
if(!(x == y)) { \
std::stringstream s; \
s << x << " != " << y << " [line " << __LINE__ << ": " << #x << " == " << #y << " ]"; \
throw std::logic_error(s.str().c_str()); \
exit(1); \
}
#define OPENGM_TEST_EQUAL_TOLERANCE(x, y, epsilon) \
if( (x<y && y-epsilon > x) || (x>y && x-epsilon > y) ) { \
std::stringstream s; \
s << x << " != " << y << " [line " << __LINE__ << ": " << #x << " == " << #y << " ]"; \
throw std::logic_error(s.str().c_str()); \
exit(1); \
}
#define OPENGM_UNUSED(x) (void)x
#define OPENGM_TEST_EQUAL_SEQUENCE(b1,e1,b2) testEqualSequence(b1,e1,b2)
template<class F1,class F2>
void testEqualFactor(const F1 & f1,const F2 & f2)
{
OPENGM_TEST_EQUAL(f1.numberOfVariables(),f2.numberOfVariables());
std::vector<size_t> factorShape(f1.numberOfVariables());
for(size_t i=0;i<f1.numberOfVariables();++i) {
OPENGM_TEST_EQUAL(f1.variableIndex(i),f2.variableIndex(i));
OPENGM_TEST_EQUAL(f1.numberOfLabels(i),f2.numberOfLabels(i));
factorShape[i]=f1.numberOfLabels(i);
}
opengm::ShapeWalker< std::vector<size_t>::const_iterator > walker(factorShape.begin(), factorShape.size() );
if(f1.numberOfVariables()!=0) {
OPENGM_TEST_EQUAL(f1.size(),f2.size());
for(size_t i=0;i<f1.size();++i,++walker) {
OPENGM_TEST_EQUAL_TOLERANCE(f1(walker.coordinateTuple().begin()),f2(walker.coordinateTuple().begin()),0.00001);
}
}
else{
size_t coordinate[]={0};
OPENGM_TEST_EQUAL_TOLERANCE(f1(coordinate),f2(coordinate),0.00001);
}
}
template<class Gm1, class Gm2>
struct GraphicalModelEqualityTest
{
void operator()(const Gm1 & gm1,const Gm2 & gm2)const
{
OPENGM_TEST(gm1.numberOfVariables()==gm2.numberOfVariables());
OPENGM_TEST(gm1.numberOfFactors()==gm2.numberOfFactors());
for(size_t i=0;i<gm1.numberOfVariables();++i)
{
OPENGM_TEST(gm1.numberOfLabels(i)==gm2.numberOfLabels(i));
}
for(size_t i=0;i<gm1.numberOfFactors();++i) {
testEqualFactor(gm1[i],gm2[i]);
}
}
};
template<class It1, class It2>
void testEqualSequence(It1 begin1, It1 end1, It2 begin2) {
while(begin1 != end1) {
OPENGM_TEST(*begin1 == *begin2);
++begin1;
++begin2;
}
}
template<class Gm1, class Gm2>
inline void testEqualGm(const Gm1 & gm1,const Gm2 & gm2)
{
GraphicalModelEqualityTest<Gm1,Gm2> testEqualGmFunctor;
testEqualGmFunctor(gm1,gm2);
}
/// \endcond
#endif // #ifndef OPENGM_TEST_HXX
|