Skip to content

Commit

Permalink
tests: Tests.h -> TestsFixtures.h
Browse files Browse the repository at this point in the history
  • Loading branch information
tvandera committed Jun 23, 2024
1 parent 4a07fec commit 5891c4c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cpp/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FILE (GLOB HEADER_FILES "Tests.h")
FILE (GLOB HEADER_FILES "TestFixtures.h")
source_group ("Header Files" FILES ${HEADER_FILES})

FILE (GLOB SOURCE_FILES "tests.cpp"
Expand Down
83 changes: 83 additions & 0 deletions cpp/Tests/TestFixtures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma once

#include <vector>

#include <SmurffCpp/Types.h>

namespace smurff
{

struct ResultItem;
class DataConfig;

namespace test
{

const double rmse_epsilon = smurff::approx_epsilon<smurff::float_type>();
const double single_item_epsilon = rmse_epsilon * 10;

// noise
extern smurff::NoiseConfig fixed_ncfg;

// dense train data
extern smurff::Matrix trainDenseMatrix;
extern smurff::DenseTensor trainDenseTensor2d;
extern smurff::DenseTensor trainDenseTensor3d;

// sparse train data
extern smurff::SparseMatrix trainSparseMatrix;
extern smurff::SparseTensor trainSparseTensor2d;
extern smurff::SparseTensor trainSparseTensor3d;

// sparse test data
extern smurff::SparseMatrix testSparseMatrix;
extern smurff::SparseTensor testSparseTensor2d;
extern smurff::SparseTensor testSparseTensor3d;

// aux data
extern smurff::DataConfig rowAuxDense;
extern smurff::DataConfig colAuxDense;

// side info
extern smurff::Matrix rowSideDenseMatrix;
extern smurff::Matrix colSideDenseMatrix;
extern smurff::Matrix rowSideDenseMatrix3d;

extern smurff::SparseMatrix rowSideSparseMatrix;
extern smurff::SparseMatrix colSideSparseMatrix;

void checkResultItems(const std::vector<smurff::ResultItem> &actualResultItems,
const std::vector<smurff::ResultItem> &expectedResultItems);

template <class M>
SideInfoConfig makeSideInfoConfig(const M &data, bool direct = true)
{
smurff::NoiseConfig sampled_ncfg(NoiseTypes::sampled);
sampled_ncfg.setPrecision(10.0);
SideInfoConfig picfg(data, sampled_ncfg);
picfg.setDirect(direct);
return picfg;
}

template <class Train, class Test>
Config genConfig(const Train &train, const Test &test, std::vector<PriorTypes> priors)
{
Config config;
config.setPriorTypes(priors);
config.setBurnin(50);
config.setNSamples(50);
config.setVerbose(0);
config.setRandomSeed(1234);
config.setNumLatent(4);

config.getTrain().setData(train);
config.getTrain().setNoiseConfig(fixed_ncfg);
config.getTest().setData(test);

return config;
}

void checkValue(double actualValue, double expectedValue, double epsilon);

} // namespace test
} // namespace smurff
2 changes: 1 addition & 1 deletion cpp/Tests/TestsInputData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <SmurffCpp/Configs/NoiseConfig.h>
#include <SmurffCpp/Utils/MatrixUtils.h>

#include "Tests.h"
#include "TestFixtures.h"

namespace smurff {
namespace test {
Expand Down
2 changes: 1 addition & 1 deletion cpp/Tests/TestsMatrixVsTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <SmurffCpp/Utils/StateFile.h>
#include <SmurffCpp/result.h>

#include "Tests.h"
#include "TestFixtures.h"

namespace smurff {
namespace test {
Expand Down
2 changes: 1 addition & 1 deletion cpp/Tests/TestsPredict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <SmurffCpp/Utils/StateFile.h>
#include <SmurffCpp/result.h>

#include "Tests.h"
#include "TestFixtures.h"

#define TAG_MATRIX_TESTS "[matrix][random]"

Expand Down
2 changes: 1 addition & 1 deletion cpp/Tests/TestsSmurff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <SmurffCpp/Utils/StateFile.h>
#include <SmurffCpp/result.h>

#include "Tests.h"
#include "TestFixtures.h"

#define TAG_MATRIX_TESTS "[matrix][random]"
#define TAG_TWO_DIMENTIONAL_TENSOR_TESTS "[tensor2d][random]"
Expand Down

0 comments on commit 5891c4c

Please sign in to comment.