Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test to help with Jens DofObject issue #9

Merged
merged 3 commits into from Dec 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/base/dof_object.h
Expand Up @@ -67,7 +67,6 @@ class DofObject : public ReferenceCountedObject<DofObject>

/**
* Copy-constructor.

*/
DofObject (const DofObject&);

Expand Down Expand Up @@ -446,6 +445,13 @@ class DofObject : public ReferenceCountedObject<DofObject>
* The ending index for system \p s.
*/
unsigned int end_idx(const unsigned int s) const;

// methods only available for unit testing
#ifdef LIBMESH_IS_UNIT_TESTING
public:
void set_buffer (const std::vector<unsigned int> &buf)
{ _idx_buf = buf; }
#endif
};


Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.am
Expand Up @@ -3,7 +3,8 @@ AUTOMAKE_OPTIONS = subdir-objects
AM_CXXFLAGS = $(libmesh_CXXFLAGS)
AM_CFLAGS = $(libmesh_CFLAGS)
AM_CPPFLAGS = $(libmesh_optional_INCLUDES) -I$(top_builddir)/include \
$(libmesh_contrib_INCLUDES) $(CPPUNIT_CFLAGS)
$(libmesh_contrib_INCLUDES) $(CPPUNIT_CFLAGS) \
-DLIBMESH_IS_UNIT_TESTING
LIBS = $(libmesh_optional_LIBS) $(CPPUNIT_LIBS)

unit_tests_sources = \
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.in
Expand Up @@ -572,7 +572,8 @@ AUTOMAKE_OPTIONS = subdir-objects
AM_CXXFLAGS = $(libmesh_CXXFLAGS)
AM_CFLAGS = $(libmesh_CFLAGS)
AM_CPPFLAGS = $(libmesh_optional_INCLUDES) -I$(top_builddir)/include \
$(libmesh_contrib_INCLUDES) $(CPPUNIT_CFLAGS)
$(libmesh_contrib_INCLUDES) $(CPPUNIT_CFLAGS) \
-DLIBMESH_IS_UNIT_TESTING

unit_tests_sources = \
driver.C \
Expand Down
37 changes: 36 additions & 1 deletion tests/base/dof_object_test.h
Expand Up @@ -12,7 +12,8 @@
CPPUNIT_TEST( testValidProcId ); \
CPPUNIT_TEST( testInvalidateProcId ); \
CPPUNIT_TEST( testSetNSystems ); \
CPPUNIT_TEST( testSetNVariableGroups );
CPPUNIT_TEST( testSetNVariableGroups ); \
CPPUNIT_TEST( testJensEftangBug );

using namespace libMesh;

Expand Down Expand Up @@ -119,6 +120,40 @@ class DofObjectTest {
CPPUNIT_ASSERT_EQUAL( nvpg[vg], aobject.n_vars(s,vg) );
}
}

void testJensEftangBug()
{
libmesh_here();
std::cout << "Debugging DofObject buffer\n"
<< " https://sourceforge.net/mailarchive/forum.php?thread_name=50C8EE7C.8090405%40gmail.com&forum_name=libmesh-users\n";

DofObject aobject(*instance);
unsigned int buf0[] = {2, 8, 257, 0, 257, 96, 257, 192, 257, 0};
aobject.set_buffer(std::vector<unsigned int>(buf0, buf0+10));
aobject.debug_buffer();
std::cout << "aobject.dof_number(0,0,0)=" << aobject.dof_number(0,0,0) << '\n'
<< "aobject.dof_number(0,1,0)=" << aobject.dof_number(0,1,0) << '\n'
<< "aobject.dof_number(0,2,0)=" << aobject.dof_number(0,2,0) << '\n'
<< "aobject.dof_number(1,0,0)=" << aobject.dof_number(1,0,0) << '\n';

CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), (unsigned int) 0);
CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), (unsigned int) 96);
CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), (unsigned int) 192);
CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), (unsigned int) 0);

unsigned int buf1[] = {2, 8, 257, 1, 257, 97, 257, 193, 257, 1};
aobject.set_buffer(std::vector<unsigned int>(buf1, buf1+10));
aobject.debug_buffer();
std::cout << "aobject.dof_number(0,0,0)=" << aobject.dof_number(0,0,0) << '\n'
<< "aobject.dof_number(0,1,0)=" << aobject.dof_number(0,1,0) << '\n'
<< "aobject.dof_number(0,2,0)=" << aobject.dof_number(0,2,0) << '\n'
<< "aobject.dof_number(1,0,0)=" << aobject.dof_number(1,0,0) << '\n';

CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), (unsigned int) 1);
CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), (unsigned int) 97);
CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), (unsigned int) 193);
CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), (unsigned int) 1);
}
};

#endif // #ifdef __dof_object_test_h__