Unit testing

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/branches/mira-mtm5@3615 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
bhaddow 2010-10-12 13:00:36 +00:00
parent 58f32a0088
commit ec902882e0
6 changed files with 177 additions and 2 deletions

View File

@ -11,4 +11,7 @@ endif
if WITH_SERVER
SERVER = server
endif
SUBDIRS = moses/src moses-chart/src OnDiskPt/src kenlm moses-cmd/src misc moses-chart-cmd/src CreateOnDisk/src mira $(MERT) $(SERVER)
if WITH_UNITTEST
UNITTEST = unittest
endif
SUBDIRS = moses/src moses-chart/src OnDiskPt/src kenlm moses-cmd/src misc moses-chart-cmd/src CreateOnDisk/src mira $(MERT) $(SERVER) $(UNITTEST)

View File

@ -101,6 +101,11 @@ AC_ARG_ENABLE(boost,
[enable_boost=yes]
)
AC_ARG_ENABLE(unittest,
[AC_HELP_STRING([--enable-unittest],[build unit tests - requires boost test])],
[enable_unittest=yes]
)
AC_ARG_WITH(zlib,
[AC_HELP_STRING([--with-zlib=PATH], [(optional) path to zlib])],
[with_zlib=$withval],
@ -141,6 +146,17 @@ else
AC_MSG_NOTICE([Building non-threaded moses. This will disable the moses server])
fi
if test "x$enable_unittest" = 'xyes'
then
if test "x$BOOST_CPPFLAGS" = 'x'
then
AC_MSG_ERROR([Require boost to build unit tests])
fi
AC_MSG_NOTICE([Building unit tests])
AM_CONDITIONAL([WITH_UNITTEST], true)
fi
if test "x$with_protobuf" != 'xno'
then
SAVE_CPPFLAGS="$CPPFLAGS"
@ -259,6 +275,6 @@ fi
LIBS="$LIBS -lz"
AC_CONFIG_FILES(Makefile OnDiskPt/src/Makefile moses/src/Makefile moses-chart/src/Makefile moses-cmd/src/Makefile moses-chart-cmd/src/Makefile misc/Makefile mert/Makefile server/Makefile CreateOnDisk/src/Makefile mira/Makefile kenlm/Makefile)
AC_CONFIG_FILES(Makefile OnDiskPt/src/Makefile moses/src/Makefile moses-chart/src/Makefile moses-cmd/src/Makefile moses-chart-cmd/src/Makefile misc/Makefile mert/Makefile server/Makefile CreateOnDisk/src/Makefile mira/Makefile kenlm/Makefile unittest/Makefile)
AC_OUTPUT()

8
unittest/Makefile.am Normal file
View File

@ -0,0 +1,8 @@
bin_PROGRAMS = moses_test
moses_test_SOURCES = MosesTest.cpp \
ScoreComponentCollectionTest.cpp \
TargetBigramFeatureTest.cpp
moses_test_CPPFLAGS = -W -Wall -I$(top_srcdir)/moses/src $(BOOST_CPPFLAGS) -DBOOST_TEST_DYN_LINK
moses_test_LDADD = -L$(top_srcdir)/moses/src -lmoses $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) -L$(top_srcdir)/OnDiskPt/src -lOnDiskPt -lboost_unit_test_framework
moses_test_DEPENDENCIES = $(top_srcdir)/moses/src/libmoses.la $(top_srcdir)/OnDiskPt/src/libOnDiskPt.a

24
unittest/MosesTest.cpp Normal file
View File

@ -0,0 +1,24 @@
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2010 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
//Supplies the main for the moses test module
#define BOOST_TEST_MODULE moses
#include <boost/test/unit_test.hpp>

View File

@ -0,0 +1,92 @@
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2010 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include <boost/test/unit_test.hpp>
#include <DummyScoreProducers.h>
#include <FeatureFunction.h>
#include <ScoreComponentCollection.h>
using namespace Moses;
BOOST_AUTO_TEST_SUITE(scc)
class MockSingleFeature : public StatelessFeatureFunction {
public:
MockSingleFeature(): StatelessFeatureFunction("MockSingle") {}
std::string GetScoreProducerWeightShortName() const {return "sf";}
size_t GetNumScoreComponents() const {return 1;}
};
class MockMultiFeature : public StatelessFeatureFunction {
public:
MockMultiFeature(): StatelessFeatureFunction("MockMulti") {}
std::string GetScoreProducerWeightShortName() const {return "mf";}
size_t GetNumScoreComponents() const {return 5;}
};
struct MockProducers {
MockProducers(): single(new MockSingleFeature()),
multi(new MockMultiFeature()) {}
~MockProducers() {delete single; delete multi;}
MockSingleFeature* single;
MockMultiFeature* multi;
};
BOOST_FIXTURE_TEST_CASE(ctor, MockProducers)
{
ScoreComponentCollection scc;
BOOST_CHECK_EQUAL(scc.GetScoreForProducer(single),0);
float expected[] = {0,0,0,0,0};
std::vector<float> actual= scc.GetScoresForProducer(multi);
BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected+5, actual.begin(), actual.begin()+5);
}
BOOST_FIXTURE_TEST_CASE(plusequals, MockProducers)
{
float arr1[] = {1,2,3,4,5};
float arr2[] = {2,4,6,8,10};
std::vector<float> vec1(arr1,arr1+5);
std::vector<float> vec2(arr2,arr2+5);
ScoreComponentCollection scc;
scc.PlusEquals(single, 3.4f);
BOOST_CHECK_EQUAL(scc.GetScoreForProducer(single), 3.4f);
scc.PlusEquals(multi,vec1);
std::vector<float> actual = scc.GetScoresForProducer(multi);
BOOST_CHECK_EQUAL_COLLECTIONS(vec1.begin(),vec1.end()
,actual.begin(), actual.end());
scc.PlusEquals(multi,vec1);
actual = scc.GetScoresForProducer(multi);
BOOST_CHECK_EQUAL_COLLECTIONS(vec2.begin(),vec2.end(),
actual.begin(), actual.end());
BOOST_CHECK_EQUAL(scc.GetScoreForProducer(single), 3.4f);
}
BOOST_AUTO_TEST_CASE(test)
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -0,0 +1,32 @@
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2010 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(target_bigram)
BOOST_AUTO_TEST_CASE(Test2)
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()