[98f06f]: src / modules / bugs / functions / test.cc  Maximize  Restore  History

Download this file

398 lines (338 with data), 11.8 kB

  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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#include "test.h"
#include "Abs.h"
#include "ArcCos.h"
#include "ArcCosh.h"
#include "ArcSin.h"
#include "ArcSinh.h"
#include "ArcTan.h"
#include "ArcTanh.h"
#include "CLogLog.h"
#include "Cos.h"
#include "Cosh.h"
#include "DFunction.h"
#include "DIntervalFunc.h"
#include "DPQFunction.h"
#include "DRoundFunc.h"
#include "DSumFunc.h"
#include "Equals.h"
#include "Exp.h"
#include "ICLogLog.h"
#include "IfElse.h"
#include "ILogit.h"
#include "InProd.h"
#include "InterpLin.h"
#include "Inverse.h"
#include "LogDet.h"
#include "LogFact.h"
#include "LogGam.h"
#include "Log.h"
#include "Logit.h"
#include "MatMult.h"
#include "Max.h"
#include "Mean.h"
#include "Min.h"
#include "Order.h"
#include "PFunction.h"
#include "Phi.h"
#include "Probit.h"
#include "Prod.h"
#include "QFunction.h"
#include "Rank.h"
#include "Round.h"
#include "SD.h"
#include "Sin.h"
#include "Sinh.h"
#include "Sort.h"
#include "Sqrt.h"
#include "Step.h"
#include "Sum.h"
#include "Tan.h"
#include "Tanh.h"
#include "test.h"
#include "Transpose.h"
#include "Trunc.h"
#include <JRmath.h>
#include <util/nainf.h>
#include <util/integer.h>
using jags::checkInteger;
using std::vector;
using std::string;
#include <climits>
static double tol = 16 * DBL_EPSILON;
void BugsFunTest::setUp()
{
//Trigonometric functions and their inverses
_sin = new jags::bugs::Sin;
_cos = new jags::bugs::Cos;
_tan = new jags::bugs::Tan;
_arccos = new jags::bugs::ArcCos;
_arcsin = new jags::bugs::ArcSin;
_arctan = new jags::bugs::ArcTan;
//Hyperbolic functions and their inverses
_sinh = new jags::bugs::Sinh;
_cosh = new jags::bugs::Cosh;
_tanh = new jags::bugs::Tanh;
_arcsinh = new jags::bugs::ArcSinh;
_arccosh = new jags::bugs::ArcCosh;
_arctanh = new jags::bugs::ArcTanh;
//Link functions and their inverses
_cloglog = new jags::bugs::CLogLog;
_log = new jags::bugs::Log;
_logit = new jags::bugs::Logit;
_probit = new jags::bugs::Probit;
_icloglog = new jags::bugs::ICLogLog;
_exp = new jags::bugs::Exp;
_ilogit = new jags::bugs::ILogit;
_phi = new jags::bugs::Phi;
//Scalar summaries of vectors
_max = new jags::bugs::Max;
_mean = new jags::bugs::Mean;
_min = new jags::bugs::Min;
_sum = new jags::bugs::Sum;
_sd = new jags::bugs::SD;
_prod = new jags::bugs::Prod;
//Mathematical functions
_logfact = new jags::bugs::LogFact;
_loggam = new jags::bugs::LogGam;
_sqrt = new jags::bugs::Sqrt;
//Lossy scalar functions
_round = new jags::bugs::Round;
_step = new jags::bugs::Step;
_trunc = new jags::bugs::Trunc;
_abs = new jags::bugs::Abs;
//Observable functions
_dinterval = new jags::bugs::DIntervalFunc;
_dround = new jags::bugs::DRoundFunc;
_dsum = new jags::bugs::DSumFunc;
//_equals = new jags::bugs::Equals;
//Sorting functions
_order = new jags::bugs::Order;
_rank = new jags::bugs::Rank;
_sort = new jags::bugs::Sort;
//Matrix functions
_inverse = new jags::bugs::Inverse;
_logdet = new jags::bugs::LogDet;
_matmult = new jags::bugs::MatMult;
_transpose = new jags::bugs::Transpose;
//Odds and sods
_ifelse = new jags::bugs::IfElse;
_inprod = new jags::bugs::InProd;
_interplin = new jags::bugs::InterpLin;
}
void BugsFunTest::tearDown()
{
//Trigonometric functions and their inverses
delete _sin;
delete _cos;
delete _tan;
delete _arccos;
delete _arcsin;
delete _arctan;
//Hyperbolic functions and their inverses
delete _sinh;
delete _cosh;
delete _tanh;
delete _arcsinh;
delete _arccosh;
delete _arctanh;
//Link functions and their inverses
delete _cloglog;
delete _log;
delete _logit;
delete _probit;
delete _icloglog;
delete _exp;
delete _ilogit;
delete _phi;
//Scalar summaries of vectors
delete _max;
delete _mean;
delete _min;
delete _sum;
delete _sd;
delete _prod;
//Mathematical functions
delete _logfact;
delete _loggam;
delete _sqrt;
//Lossy scalar functions
delete _round;
delete _step;
delete _trunc;
delete _abs;
//Observable functions
delete _dinterval;
delete _dround;
delete _dsum;
//delete _equals
//Sorting functions
delete _order;
delete _rank;
delete _sort;
//Matrix functions
delete _inverse;
delete _logdet;
delete _matmult;
delete _transpose;
//Odds and sods
delete _ifelse;
delete _inprod;
delete _interplin;
}
void BugsFunTest::name()
{
//Trigonometric functions
CPPUNIT_ASSERT_EQUAL(string("sin"), _sin->name());
CPPUNIT_ASSERT_EQUAL(string("cos"), _cos->name());
CPPUNIT_ASSERT_EQUAL(string("tan"), _tan->name());
CPPUNIT_ASSERT_EQUAL(string("arcsin"), _arcsin->name());
CPPUNIT_ASSERT_EQUAL(string("arccos"), _arccos->name());
CPPUNIT_ASSERT_EQUAL(string("arctan"), _arctan->name());
//Hyperbolic functions
CPPUNIT_ASSERT_EQUAL(string("sinh"), _sinh->name());
CPPUNIT_ASSERT_EQUAL(string("cosh"), _cosh->name());
CPPUNIT_ASSERT_EQUAL(string("tanh"), _tanh->name());
CPPUNIT_ASSERT_EQUAL(string("arcsinh"), _arcsinh->name());
CPPUNIT_ASSERT_EQUAL(string("arccosh"), _arccosh->name());
CPPUNIT_ASSERT_EQUAL(string("arctanh"), _arctanh->name());
//Link functions
CPPUNIT_ASSERT_EQUAL(string("cloglog"), _cloglog->name());
CPPUNIT_ASSERT_EQUAL(string("log"), _log->name());
CPPUNIT_ASSERT_EQUAL(string("logit"), _logit->name());
CPPUNIT_ASSERT_EQUAL(string("probit"), _probit->name());
CPPUNIT_ASSERT_EQUAL(string("icloglog"), _icloglog->name());
CPPUNIT_ASSERT_EQUAL(string("exp"), _exp->name());
CPPUNIT_ASSERT_EQUAL(string("ilogit"), _ilogit->name());
CPPUNIT_ASSERT_EQUAL(string("phi"), _phi->name());
//Scalar summaries of vectors
CPPUNIT_ASSERT_EQUAL(string("max"), _max->name());
CPPUNIT_ASSERT_EQUAL(string("mean"), _mean->name());
CPPUNIT_ASSERT_EQUAL(string("min"), _min->name());
CPPUNIT_ASSERT_EQUAL(string("sum"), _sum->name());
CPPUNIT_ASSERT_EQUAL(string("sd"), _sd->name());
CPPUNIT_ASSERT_EQUAL(string("prod"), _prod->name());
//Mathematical functions
CPPUNIT_ASSERT_EQUAL(string("logfact"), _logfact->name());
CPPUNIT_ASSERT_EQUAL(string("loggam"), _loggam->name());
CPPUNIT_ASSERT_EQUAL(string("sqrt"), _sqrt->name());
//Lossy scalar functions
CPPUNIT_ASSERT_EQUAL(string("round"), _round->name());
CPPUNIT_ASSERT_EQUAL(string("step"), _step->name());
CPPUNIT_ASSERT_EQUAL(string("trunc"), _trunc->name());
CPPUNIT_ASSERT_EQUAL(string("abs"), _abs->name());
//Observable functions
CPPUNIT_ASSERT_EQUAL(string("dinterval"), _dinterval->name());
CPPUNIT_ASSERT_EQUAL(string("dround"), _dround->name());
CPPUNIT_ASSERT_EQUAL(string("dsum"), _dsum->name());
CPPUNIT_ASSERT_EQUAL(string("order"), _order->name());
CPPUNIT_ASSERT_EQUAL(string("rank"), _rank->name());
CPPUNIT_ASSERT_EQUAL(string("sort"), _sort->name());
//Matrix functions
CPPUNIT_ASSERT_EQUAL(string("inverse"), _inverse->name());
CPPUNIT_ASSERT_EQUAL(string("logdet"), _logdet->name());
CPPUNIT_ASSERT_EQUAL(string("%*%"), _matmult->name());
CPPUNIT_ASSERT_EQUAL(string("t"), _transpose->name());
//odds and ends
CPPUNIT_ASSERT_EQUAL(string("ifelse"), _ifelse->name());
CPPUNIT_ASSERT_EQUAL(string("inprod"), _inprod->name());
CPPUNIT_ASSERT_EQUAL(string("interp.lin"), _interplin->name());
}
void BugsFunTest::alias()
{
//Trigonometric functions
CPPUNIT_ASSERT_EQUAL(string(""), _sin->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _cos->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _tan->alias());
CPPUNIT_ASSERT_EQUAL(string("asin"), _arcsin->alias());
CPPUNIT_ASSERT_EQUAL(string("acos"), _arccos->alias());
CPPUNIT_ASSERT_EQUAL(string("atan"), _arctan->alias());
//Hyperbolic functions
CPPUNIT_ASSERT_EQUAL(string(""), _sinh->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _cosh->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _tanh->alias());
CPPUNIT_ASSERT_EQUAL(string("asinh"), _arcsinh->alias());
CPPUNIT_ASSERT_EQUAL(string("acosh"), _arccosh->alias());
CPPUNIT_ASSERT_EQUAL(string("atanh"), _arctanh->alias());
//Link functions
CPPUNIT_ASSERT_EQUAL(string(""), _cloglog->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _log->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _logit->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _probit->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _icloglog->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _exp->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _ilogit->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _phi->alias());
//Scalar summaries of vectors
CPPUNIT_ASSERT_EQUAL(string(""), _max->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _mean->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _min->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _sum->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _sd->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _prod->alias());
//Mathematical functions
CPPUNIT_ASSERT_EQUAL(string(""), _logfact->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _loggam->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _sqrt->alias());
//Lossy scalar functions
CPPUNIT_ASSERT_EQUAL(string(""), _round->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _step->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _trunc->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _abs->alias());
//Observable functions
CPPUNIT_ASSERT_EQUAL(string(""), _dinterval->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _dround->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _dsum->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _order->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _rank->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _sort->alias());
//Matrix functions
CPPUNIT_ASSERT_EQUAL(string(""), _inverse->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _logdet->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _matmult->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _transpose->alias());
//odds and ends
CPPUNIT_ASSERT_EQUAL(string(""), _ifelse->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _inprod->alias());
CPPUNIT_ASSERT_EQUAL(string(""), _interplin->alias());
}
/*
void BugsFunTest::trig()
{
double v;
vector<double const *> args(1);
args[0] = &v;
v = 0;
CPPUNIT_ASSERT_EQUAL(0.0, _sin->evaluate(args));
CPPUNIT_ASSERT_EQUAL(1.0, _cos->evaluate(args));
CPPUNIT_ASSERT_EQUAL(0.0, _tan->evaluate(args));
v = M_PI / 4;
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, _tan->evaluate(args), tol);
v = M_PI / 2;
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, _sin->evaluate(args), tol);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, _cos->evaluate(args), tol);
v = 3 * M_PI / 4;
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, _tan->evaluate(args), tol);
v = M_PI;
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, _sin->evaluate(args), tol);
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, _cos->evaluate(args), tol);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, _tan->evaluate(args), tol);
v = 5 * M_PI / 4;
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, _tan->evaluate(args), tol);
v = 3 * M_PI / 2;
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, _sin->evaluate(args), tol);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, _cos->evaluate(args), tol);
// v = 5 * M_PI / 4;
// CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, _tan->evaluate(args), tol);
}
*/
/*
//Link functions and their inverses
delete _cloglog;
delete _log;
delete _logit;
delete _probit;
delete _icloglog;
delete _exp;
delete _ilogit;
delete _phi;
*/

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks