EMatrix_unit_tests.cpp 1.7 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * EMatrix_unit_tests.cpp
 *
 *  Created on: Feb 13, 2018
 *      Author: i-bird
 */

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "DMatrix/EMatrix.hpp"
#include "memory/HeapMemory.hpp"

13 14
#ifdef HAVE_EIGEN

incardon's avatar
incardon committed
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 104 105 106
BOOST_AUTO_TEST_SUITE (EMatrix_test)

BOOST_AUTO_TEST_CASE( EMatrix_test_use)
{
	{
	EMatrixXd em;

	em.resize(8,5);

	for (size_t i = 0 ; i < 8 ; i++)
	{
		for (size_t j = 0 ; j < 5 ; j++)
		{em(i,j) = i*8+j;}
	}

	size_t pr = 0;
	em.packRequest(pr);

	// allocate the memory
	HeapMemory pmem;
	pmem.allocate(pr);
	ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(pr,pmem));
	mem.incRef();

	BOOST_REQUIRE_EQUAL(pr,8*5*sizeof(double) + 2*sizeof(size_t));

	Pack_stat sts;
	em.pack(mem,sts);

	// Reset to zero
	for (size_t i = 0 ; i < 8 ; i++)
	{
		for (size_t j = 0 ; j < 5 ; j++)
		{em(i,j) = 0;}
	}

	Unpack_stat ps;
	em.unpack(mem,ps);

	for (size_t i = 0 ; i < 8 ; i++)
	{
		for (size_t j = 0 ; j < 5 ; j++)
		{BOOST_REQUIRE_EQUAL(em(i,j),i*8+j);}
	}
	}


	{
	EMatrix3d em;

	em.resize(3,3);

	for (size_t i = 0 ; i < 3 ; i++)
	{
		for (size_t j = 0 ; j < 3 ; j++)
		{em(i,j) = i*8+j;}
	}

	size_t pr = 0;
	em.packRequest(pr);

	// allocate the memory
	HeapMemory pmem;
	pmem.allocate(pr);
	ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(pr,pmem));
	mem.incRef();

	BOOST_REQUIRE_EQUAL(pr,3*3*sizeof(double) + 2*sizeof(size_t));

	Pack_stat sts;
	em.pack(mem,sts);

	// Reset to zero
	for (size_t i = 0 ; i < 3 ; i++)
	{
		for (size_t j = 0 ; j < 3 ; j++)
		{em(i,j) = 0;}
	}

	Unpack_stat ps;
	em.unpack(mem,ps);

	for (size_t i = 0 ; i < 3 ; i++)
	{
		for (size_t j = 0 ; j < 3 ; j++)
		{BOOST_REQUIRE_EQUAL(em(i,j),i*8+j);}
	}
	}
}

BOOST_AUTO_TEST_SUITE_END()

107 108

#endif