Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #712 from vigsterkr/utest
Browse files Browse the repository at this point in the history
Fix unit testing of LatentSVM
  • Loading branch information
lisitsyn committed Aug 13, 2012
2 parents 5df0dcd + 2e361a5 commit 60278ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
48 changes: 24 additions & 24 deletions tests/unit/latent/LatentSVM_unittest.cc
@@ -1,58 +1,58 @@
#include "MockLatentModel.h"
#include <shogun/classifier/svm/LatentLinearMachine.h>
#include <shogun/latent/LatentSVM.h>

using namespace shogun;
using ::testing::Return;

TEST(LatentSVM, ctor)
TEST(LatentModel, argmax_h)
{
using ::testing::AtLeast;
using ::testing::Exactly;
using ::testing::AtMost;
using ::testing::_;

MockCLatentModel* model = new MockCLatentModel();
int32_t dim = 10, samples = 20;
SGVector<float64_t> a(dim);
CData* data = new CData();

ON_CALL(*model, get_dim())
.WillByDefault(Return(dim));

ON_CALL(*model, get_num_vectors())
.WillByDefault(Return(samples));

EXPECT_CALL(*model, get_dim())
.Times(Exactly(1));

EXPECT_CALL(*model, get_num_vectors())
.Times(Exactly(1));
EXPECT_CALL(*model, infer_latent_variable(_,_))
.Times(AtMost(samples))
.WillRepeatedly(Return(data));

CLatentLinearMachine* lsvm = new CLatentLinearMachine(model, 10);
model->argmax_h(a);

SG_UNREF(lsvm);
SG_UNREF(data);
SG_UNREF(model);
}

TEST(LatentSVM, argmax_h)
TEST(LatentSVM, ctor)
{
using ::testing::AtMost;
using ::testing::_;
using ::testing::AtLeast;
using ::testing::Exactly;

MockCLatentModel* model = new MockCLatentModel();
int32_t dim = 10, samples = 20;
SGVector<float64_t> a(dim);
CLatentData* data = new CLatentData();

ON_CALL(*model, get_dim())
.WillByDefault(Return(dim));

ON_CALL(*model, get_num_vectors())
.WillByDefault(Return(samples));

EXPECT_CALL(*model, infer_latent_variable(_,_))
.Times(AtMost(samples))
.WillRepeatedly(Return(data));
EXPECT_CALL(*model, get_dim())
.Times(Exactly(1));

model->argmax_h(a);
EXPECT_CALL(*model, get_num_vectors())
.Times(Exactly(1));

SG_UNREF(data);
SG_UNREF(model);
CLatentSVM* lsvm = new CLatentSVM(model, 10);

SG_UNREF(lsvm);
}

TEST(LatentSVM, apply)
Expand All @@ -63,7 +63,7 @@ TEST(LatentSVM, apply)
MockCLatentModel* model = new MockCLatentModel();
int32_t dim = 10, samples = 20;
SGVector<float64_t> a(dim);
CLatentData* data = new CLatentData();
CData* data = new CData();
CLatentFeatures* f = new CLatentFeatures(samples);

ON_CALL(*model, get_dim())
Expand All @@ -83,7 +83,7 @@ TEST(LatentSVM, apply)
.Times(samples)
.WillRepeatedly(Return(a));

CLatentLinearMachine* lsvm = new CLatentLinearMachine(model, 10);
CLatentSVM* lsvm = new CLatentSVM(model, 10);

lsvm->apply(f);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/latent/MockLatentModel.h
Expand Up @@ -8,7 +8,7 @@ namespace shogun {
MOCK_CONST_METHOD0(get_num_vectors, int32_t());
MOCK_CONST_METHOD0(get_dim, int32_t());
MOCK_METHOD1(get_psi_feature_vector, SGVector<float64_t>(index_t idx));
MOCK_METHOD2(infer_latent_variable, CLatentData*(const SGVector<float64_t>& w, index_t idx));
MOCK_METHOD2(infer_latent_variable, CData*(const SGVector<float64_t>& w, index_t idx));
MOCK_METHOD1(argmax_h, void(const SGVector<float64_t>& w));
MOCK_CONST_METHOD0(get_name, const char*());
};
Expand Down

0 comments on commit 60278ef

Please sign in to comment.