-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
LatentSVM_unittest.cc
110 lines (83 loc) · 2.19 KB
/
LatentSVM_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
107
108
109
110
#include "MockLatentModel.h"
#include <shogun/lib/config.h>
#ifdef USE_GPL_SHOGUN
#include <shogun/latent/LatentSVM.h>
using namespace shogun;
using ::testing::Return;
using ::testing::NiceMock;
/** gmock REV 443 and freebsd doesn't play nicely */
#ifdef FREEBSD
TEST(LatentModel, DISABLED_argmax_h)
#else
TEST(LatentModel, argmax_h)
#endif
{
using ::testing::AtMost;
using ::testing::_;
using ::testing::NiceMock;
NiceMock<MockCLatentModel> model;
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, infer_latent_variable(_,_))
.Times(AtMost(samples))
.WillRepeatedly(Return(data));
model.argmax_h(a);
SG_UNREF(data);
}
#ifdef FREEBSD
TEST(LatentSVM, DISABLED_ctor)
#else
TEST(LatentSVM, ctor)
#endif
{
using ::testing::AtLeast;
using ::testing::Exactly;
MockCLatentModel model; model.ref();
int32_t dim = 10, samples = 20;
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));
CLatentSVM* lsvm = new CLatentSVM(&model, 10);
SG_UNREF(lsvm);
}
#ifdef FREEBSD
TEST(LatentSVM, DISABLED_apply)
#else
TEST(LatentSVM, apply)
#endif
{
using ::testing::AtMost;
using ::testing::_;
using ::testing::NiceMock;
NiceMock<MockCLatentModel> model; model.ref();
int32_t dim = 10, samples = 20;
SGMatrix<float64_t> feats(dim, samples);
CDenseFeatures<float64_t>* dense_feats = new CDenseFeatures<float64_t>(feats);
CData* data = new CData();
CLatentFeatures* f = new CLatentFeatures(samples);
ON_CALL(model, get_dim())
.WillByDefault(Return(dim));
ON_CALL(model, get_num_vectors())
.WillByDefault(Return(samples));
EXPECT_CALL(model, get_num_vectors())
.Times(2);
EXPECT_CALL(model, infer_latent_variable(_,_))
.Times(samples)
.WillRepeatedly(Return(data));
EXPECT_CALL(model, get_psi_feature_vectors())
.Times(1)
.WillOnce(Return(dense_feats));
CLatentSVM* lsvm = new CLatentSVM(&model, 10);
lsvm->apply(f);
SG_UNREF(lsvm);
SG_UNREF(dense_feats);
}
#endif //USE_GPL_SHOGUN