first approach including first tests

master
Marc Wäckerlin 8 years ago
parent 17e6364f45
commit b54af4681a
  1. 1
      COPYING
  2. 16
      ChangeLog
  3. 1
      INSTALL
  4. 97
      ax_cxx_compile_stdcxx_11.m4
  5. 2
      ax_init_standard_project.m4
  6. 1
      configure.ac
  7. 6
      examples/makefile.am
  8. 23
      examples/matrix-sample.cxx
  9. 2
      src/makefile.am
  10. 299
      src/matrix.hxx
  11. 215
      test/basic.cxx
  12. 8
      test/makefile.am

@ -0,0 +1 @@
/usr/share/automake-1.15/COPYING

@ -0,0 +1,16 @@
2016-07-30 08:50
* ., AUTHORS, ChangeLog, NEWS, README, autogen.sh, ax_check_qt.m4,
ax_cxx_compile_stdcxx_11.m4, ax_init_standard_project.m4,
bootstrap.sh, build-in-docker.conf, build-in-docker.sh,
build-resource-file.sh, configure.ac, debian,
debian/changelog.in, debian/compat, debian/control.in,
debian/docs, debian/libmatricxx-dev.install,
debian/libmatricxx.install, debian/rules, doc, doc/doxyfile.in,
doc/makefile.am, examples, examples/makefile.am,
libmatricxx.desktop.in, libmatricxx.spec.in,
mac-create-app-bundle.sh, makefile.am, resolve-debbuilddeps.sh,
resolve-rpmbuilddeps.sh, sql-to-dot.sed, src,
src/libmatricxx.pc.in, src/makefile.am, src/version.cxx,
src/version.hxx, test, test/makefile.am: initial project

@ -0,0 +1 @@
/usr/share/automake-1.15/INSTALL

@ -4,12 +4,16 @@
#
# SYNOPSIS
#
# AX_REQUIRE_STDCXX_11
# AX_REQUIRE_STDCXX_14
# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
# AX_CXX_COMPILE_STDCXX_14([ext|noext],[mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# standard; if necessary, add switches to CXXFLAGS to enable support.
# or C++14 standard; if necessary, add switches to CXXFLAGS to
# enable support.
#
# The first argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
@ -131,3 +135,94 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
AC_SUBST(HAVE_CXX11)
fi
])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_14], [dnl
m4_if([$1], [], [],
[$1], [ext], [],
[$1], [noext], [],
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_14])])dnl
m4_if([$2], [], [ax_cxx_compile_cxx14_required=true],
[$2], [mandatory], [ax_cxx_compile_cxx14_required=true],
[$2], [optional], [ax_cxx_compile_cxx14_required=false],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_14])])dnl
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++14 features by default,
ax_cv_cxx_compile_cxx14,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[ax_cv_cxx_compile_cxx14=yes],
[ax_cv_cxx_compile_cxx14=no])])
if test x$ax_cv_cxx_compile_cxx14 = xyes; then
ac_success=yes
fi
m4_if([$1], [noext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=gnu++14 -std=gnu++0y; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx14_$switch])
AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
m4_if([$1], [ext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=c++14 -std=c++0y; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx14_$switch])
AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx14_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++14 language features is required.])
fi
else
if test x$ac_success = xno; then
HAVE_CXX14=0
AC_MSG_NOTICE([No compiler with C++14 support was found])
else
HAVE_CXX14=1
AC_DEFINE(HAVE_CXX14,1,
[define if the compiler supports basic C++14 syntax])
fi
HAVE_CXX11=${HAVE_CXX14}
AC_SUBST(HAVE_CXX11)
AC_SUBST(HAVE_CXX14)
fi
])
AC_DEFUN([AX_REQUIRE_STDCXX_11], [
if test x${HAVE_CXX11} != x1; then
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
fi
])
AC_DEFUN([AX_REQUIRE_STDCXX_14], [
if test x${HAVE_CXX14} != x1; then
AC_MSG_ERROR([*** A compiler with support for C++14 language features is required.])
fi
])

@ -273,7 +273,7 @@ EOF
AC_DEFUN([AX_USE_CXX], [
m4_include(ax_cxx_compile_stdcxx_11.m4)
AC_LANG(C++)
AX_CXX_COMPILE_STDCXX_11(noext, optional)
AX_CXX_COMPILE_STDCXX_14(noext, optional)
AC_PROG_CXX
AC_PROG_CPP

@ -32,6 +32,7 @@ AX_BUILD_EXAMPLES
#AX_CHECK_QT([QT], [QtCore QtGui QtNetwork], [QtWidgets])
#AX_REQUIRE_QT([QT], [QtCore QtGui QtNetwork], [QtWidgets])
#AX_QT_NO_KEYWORDS
AX_REQUIRE_STDCXX_14
# create output
AC_OUTPUT

@ -10,6 +10,10 @@
AM_CPPFLAGS = -I${top_srcdir}/src -I${top_builddir}/src
AM_LDFLAGS = -L${abs_top_builddir}/src/.libs
LDADD = -lmatricxx
#LDADD = -lmatricxx
noinst_PROGRAMS = matrix-sample
matrix_sample_SOURCES = matrix-sample.cxx
MAINTAINERCLEANFILES = makefile.in

@ -0,0 +1,23 @@
/*! @file
@id $Id$
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#include <matrix.hxx>
int main(int, char**) {
// Matrix<int, 3, 4> m1{1, 2, 3, 4,
// 5, 6, 7, 8,
// 9, 10, 11, 12};
// std::cout<<"m1 = "<<m1<<'\n';
// Matrix<int, 3, 4> m2 = m1;
// std::cout<<"m1 = "<<m1<<'\n';
// Matrix<int, 3, 4> m3;
// m3 = m1 + m2;
// std::cout<<"m1 = "<<m1<<'\n';
// std::cout<<"m2 = "<<m2<<'\n';
// std::cout<<"m3 = "<<m3<<'\n';
return 0;
}

@ -8,4 +8,6 @@
## 1 2 3 4 5 6 7 8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890
include_HEADERS = matrix.hxx
MAINTAINERCLEANFILES = makefile.in

@ -0,0 +1,299 @@
/*! @file
@id $Id$
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#include <iostream>
#include <cstring>
#include <cassert>
#include <type_traits>
#define LOG std::cout<<__PRETTY_FUNCTION__<<std::endl
template<typename T, size_t ROWS=0, size_t COLUMNS=0> class Matrix {
//........................................................const.variables
protected:
static const size_t SIZE = ROWS*COLUMNS;
static const size_t MEM_SIZE = ROWS*COLUMNS*sizeof(T);
//...............................................................typedefs
public:
/// @name Auxiliary Classes
///{
/// Return One Row as Vector, internally used for element access
/** Only used to access values:
@code
Matrix<int,4,4> m;
m[2][2] = 1;
@endcode */
class RowVector {
public:
T& operator[](size_t column) {
return _v[column];
}
protected:
friend class Matrix;
RowVector() = delete; // forbidden
RowVector(T c[COLUMNS]): _v(c) {}
T *_v;
};
/// Same as RowVector, but in a constant environment.
class ConstRowVector {
public:
const T& operator[](size_t column) const {
return _v[column];
}
protected:
friend class Matrix;
ConstRowVector() = delete; // forbidden
ConstRowVector(const T c[COLUMNS]): _v(c) {}
const T *_v;
};
///}
//................................................................methods
public:
/// @name construction
///{
Matrix() {
LOG;
memset(_c, 0, MEM_SIZE);
}
template<typename ...ARGS>
Matrix(ARGS...t): _c{std::forward<T>(t)...} {
LOG;
static_assert(sizeof...(t)==SIZE, "variadic matrix initialisation requires correct array size");
}
Matrix(const Matrix& o) {
LOG;
memcpy(_c, o._c, MEM_SIZE);
}
///}
/// @name operators
///{
Matrix& operator=(T oc[ROWS][COLUMNS]) {
LOG;
memcpy(_c, oc, MEM_SIZE);
return *this;
}
Matrix& operator=(const Matrix& o) {
LOG;
memcpy(_c, o._c, MEM_SIZE);
return *this;
}
Matrix& operator+=(const Matrix& o) {
LOG;
T *to((T*)(_c)+MEM_SIZE), *from((T*)(o._c)+MEM_SIZE);
while (to>(T*)(_c)) *--to += *--from;
return *this;
}
RowVector operator[](size_t row) {
return RowVector(_c[row]);
}
const ConstRowVector operator[](size_t row) const {
return ConstRowVector(_c[row]);
}
///}
//..............................................................variables
protected:
T _c[ROWS][COLUMNS];
};
template<typename T> class Matrix<T, 0, 0> {
//..............................................................constants
public:
const size_t ROWS;
const size_t COLUMNS;
const size_t SIZE;
const size_t MEM_SIZE;
//...............................................................typedefs
public:
/// @name Auxiliary Classes
///{
/// Return One Row as Vector, internally used for element access
/** Only used to access values:
@code
Matrix<int,4,4> m;
m[2][2] = 1;
@endcode */
class RowVector {
public:
T& operator[](size_t column) {
assert(column<_m.COLUMNS);
return _v[column];
}
protected:
friend class Matrix;
RowVector() = delete; // forbidden
RowVector(const Matrix& m, T c[]): _m(m), _v(c) {}
const Matrix& _m;
T *_v;
};
/// Same as RowVector, but in a constant environment.
class ConstRowVector {
public:
const T& operator[](size_t column) const {
assert(column<_m.COLUMNS);
return _v[column];
}
protected:
friend class Matrix;
ConstRowVector() = delete; // forbidden
ConstRowVector(const Matrix& m, const T c[]): _m(m), _v(c) {}
const Matrix& _m;
const T *_v;
};
///}
//................................................................methods
public:
/// @name construction
///{
Matrix(size_t rows, size_t columns):
ROWS(rows),
COLUMNS(columns),
SIZE(rows*columns),
MEM_SIZE(rows*columns*sizeof(T)),
_c(new T[rows*columns]) {
LOG;
memset(_c, 0, MEM_SIZE);
}
template<typename ...ARGS>
Matrix(size_t rows, size_t columns, ARGS...t):
Matrix(rows, columns) {
LOG;
assert(sizeof...(t)==SIZE);
copy_args(_c, t...);
}
Matrix(const Matrix& o): Matrix(o.ROWS, o.COLUMNS) {
LOG;
memcpy(_c, o._c, MEM_SIZE);
}
///}
/// @name destruction
///{
~Matrix() {
delete[] _c;
}
///}
/// @name operators
///{
Matrix& operator=(T oc[]) {
LOG;
assert(sizeof(oc)==MEM_SIZE);
memcpy(_c, oc, MEM_SIZE);
return *this;
}
Matrix& operator=(const Matrix& o) {
LOG;
if (o.ROWS!=ROWS&&o.COLUMNS!=COLUMNS) {
delete[] _c;
ROWS = o.ROWS;
COLUMNS = o.COLUMNS;
SIZE = o.SIZE;
MEM_SIZE = o.MEM_SIZE;
_c = new T[SIZE];
}
memcpy(_c, o._c, MEM_SIZE);
return *this;
}
Matrix& operator+=(const Matrix& o) {
LOG;
assert(o.ROWS==ROWS);
assert(o.COLUMNS==COLUMNS);
T *to((T*)(_c)+MEM_SIZE), *from((T*)(o._c)+MEM_SIZE);
while (to>(T*)(_c)) *--to += *--from;
return *this;
}
RowVector operator[](size_t row) {
assert(row<ROWS);
return RowVector(*this, _c+row*COLUMNS);
}
const ConstRowVector operator[](size_t row) const {
assert(row<ROWS);
return ConstRowVector(*this, _c+row*COLUMNS);
}
///}
//................................................................methods
protected:
void copy_args(T*) {}
template<typename ...ARGS>
void copy_args(T* to, T t1, ARGS...t) {
*to = t1;
copy_args(++to, t...);
}
//..............................................................variables
protected:
T* _c;
};
template<typename T, size_t ROWS, size_t COLUMNS>
Matrix<T, ROWS, COLUMNS> operator+(const Matrix<T, ROWS, COLUMNS>& m1, const Matrix<T, ROWS, COLUMNS>& m2) {
LOG;
Matrix<T, ROWS, COLUMNS> res(m1);
return res+=m2;
}
template<typename T, size_t ROWS, size_t COLUMNS>
std::ostream& operator<<(std::ostream& s, const Matrix<T, ROWS, COLUMNS>& m) {
LOG;
for (size_t w = 0; w < m.ROWS; ++w) {
for (size_t h = 0; h < m.COLUMNS;++h) {
s<<m[w][h]<<' ';
}
s<<'\n';
}
}

@ -0,0 +1,215 @@
/*! @file
@id $Id$
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#include <matrix.hxx>
#include <cppunit/TestFixture.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/XmlOutputter.h>
#include <fstream>
class TemplateMatrixTest: public CppUnit::TestFixture {
public:
template<typename T>
void initFromArray1() {
Matrix<T,2,4> m {1, 2, 3, 4,
5, 6, 7, 8};
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]);
CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]);
}
template<typename T>
void initFromArray2() {
Matrix<T,2,4> m(1, 2, 3, 4,
5, 6, 7, 8);
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]);
CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]);
}
template<typename T>
void initFromArray3() {
Matrix<T,2,4> m({1, 2, 3, 4,
5, 6, 7, 8});
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]);
CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]);
}
template<typename T>
void initFromOtherMatrix() {
Matrix<T,2,4> m1(1, 2, 3, 4,
5, 6, 7, 8);
m1[1][2] = 13;
Matrix<T,2,4> m2(m1);
m1[0][2] = 16;
m2[0][0] = 0;
CPPUNIT_ASSERT_EQUAL((T)1, m1[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m1[0][1]);
CPPUNIT_ASSERT_EQUAL((T)16, m1[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m1[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m1[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m1[1][1]);
CPPUNIT_ASSERT_EQUAL((T)13, m1[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m1[1][3]);
CPPUNIT_ASSERT_EQUAL((T)0, m2[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m2[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m2[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m2[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m2[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m2[1][1]);
CPPUNIT_ASSERT_EQUAL((T)13, m2[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m2[1][3]);
}
template<typename T>
void initFromDefault() {
Matrix<T,2,2> m;
CPPUNIT_ASSERT_EQUAL((T)0, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)0, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)0, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)0, m[1][1]);
}
CPPUNIT_TEST_SUITE(TemplateMatrixTest);
CPPUNIT_TEST(initFromArray1<int>);
CPPUNIT_TEST(initFromArray1<long>);
CPPUNIT_TEST(initFromArray1<unsigned>);
CPPUNIT_TEST(initFromArray1<unsigned long>);
CPPUNIT_TEST(initFromArray1<float>);
CPPUNIT_TEST(initFromArray1<double>);
CPPUNIT_TEST(initFromArray2<int>);
CPPUNIT_TEST(initFromArray2<long>);
CPPUNIT_TEST(initFromArray2<unsigned>);
CPPUNIT_TEST(initFromArray2<unsigned long>);
CPPUNIT_TEST(initFromArray2<float>);
CPPUNIT_TEST(initFromArray2<double>);
CPPUNIT_TEST(initFromArray3<int>);
CPPUNIT_TEST(initFromArray3<long>);
CPPUNIT_TEST(initFromArray3<unsigned>);
CPPUNIT_TEST(initFromArray3<unsigned long>);
CPPUNIT_TEST(initFromArray3<float>);
CPPUNIT_TEST(initFromArray3<double>);
CPPUNIT_TEST(initFromOtherMatrix<int>);
CPPUNIT_TEST(initFromOtherMatrix<long>);
CPPUNIT_TEST(initFromOtherMatrix<unsigned>);
CPPUNIT_TEST(initFromOtherMatrix<unsigned long>);
CPPUNIT_TEST(initFromOtherMatrix<float>);
CPPUNIT_TEST(initFromOtherMatrix<double>);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(TemplateMatrixTest);
class VariableMatrixTest: public CppUnit::TestFixture {
public:
template<typename T>
void initFromArray1() {
Matrix<T> m(2,4,
1, 2, 3, 4,
5, 6, 7, 8);
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]);
CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]);
}
template<typename T>
void initFromArray2() {
Matrix<T> m(2, 4,
1, 2, 3, 4,
5, 6, 7, 8);
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]);
CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]);
}
template<typename T>
void initFromOtherMatrix() {
Matrix<T> m1(2, 4,
1, 2, 3, 4,
5, 6, 7, 8);
m1[1][2] = 13;
Matrix<T> m2(m1);
m1[0][2] = 16;
m2[0][0] = 0;
CPPUNIT_ASSERT_EQUAL((T)1, m1[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m1[0][1]);
CPPUNIT_ASSERT_EQUAL((T)16, m1[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m1[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m1[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m1[1][1]);
CPPUNIT_ASSERT_EQUAL((T)13, m1[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m1[1][3]);
CPPUNIT_ASSERT_EQUAL((T)0, m2[0][0]);
CPPUNIT_ASSERT_EQUAL((T)2, m2[0][1]);
CPPUNIT_ASSERT_EQUAL((T)3, m2[0][2]);
CPPUNIT_ASSERT_EQUAL((T)4, m2[0][3]);
CPPUNIT_ASSERT_EQUAL((T)5, m2[1][0]);
CPPUNIT_ASSERT_EQUAL((T)6, m2[1][1]);
CPPUNIT_ASSERT_EQUAL((T)13, m2[1][2]);
CPPUNIT_ASSERT_EQUAL((T)8, m2[1][3]);
}
template<typename T>
void initFromDefault() {
Matrix<T> m(2, 4);
CPPUNIT_ASSERT_EQUAL((T)0, m[0][0]);
CPPUNIT_ASSERT_EQUAL((T)0, m[0][1]);
CPPUNIT_ASSERT_EQUAL((T)0, m[1][0]);
CPPUNIT_ASSERT_EQUAL((T)0, m[1][1]);
}
CPPUNIT_TEST_SUITE(VariableMatrixTest);
CPPUNIT_TEST(initFromArray1<int>);
CPPUNIT_TEST(initFromArray1<long>);
CPPUNIT_TEST(initFromArray1<unsigned>);
CPPUNIT_TEST(initFromArray1<unsigned long>);
CPPUNIT_TEST(initFromArray1<float>);
CPPUNIT_TEST(initFromArray1<double>);
CPPUNIT_TEST(initFromArray2<int>);
CPPUNIT_TEST(initFromArray2<long>);
CPPUNIT_TEST(initFromArray2<unsigned>);
CPPUNIT_TEST(initFromArray2<unsigned long>);
CPPUNIT_TEST(initFromArray2<float>);
CPPUNIT_TEST(initFromArray2<double>);
CPPUNIT_TEST(initFromOtherMatrix<int>);
CPPUNIT_TEST(initFromOtherMatrix<long>);
CPPUNIT_TEST(initFromOtherMatrix<unsigned>);
CPPUNIT_TEST(initFromOtherMatrix<unsigned long>);
CPPUNIT_TEST(initFromOtherMatrix<float>);
CPPUNIT_TEST(initFromOtherMatrix<double>);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(VariableMatrixTest);
int main(int argc, char** argv) try {
std::ofstream ofs((*argv+std::string(".xml")).c_str());
CppUnit::TextUi::TestRunner runner;
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs));
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
return runner.run() ? 0 : 1;
} catch (std::exception& e) {
std::cerr<<"***Exception: "<<e.what()<<std::endl;
return 1;
}

@ -10,8 +10,12 @@
AM_CPPFLAGS = -I${top_srcdir}/src -I${top_builddir}/src
AM_LDFLAGS = -L${abs_top_builddir}/src/.libs
LDADD = -lmatricxx
LDADD = -lcppunit
#LDADD = -lmatricxx
TESTS =
check_PROGRAMS = basic
TESTS = ${check_PROGRAMS}
basic_SOURCES = basic.cxx
MAINTAINERCLEANFILES = makefile.in

Loading…
Cancel
Save