Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that old parameter names and tag parameter names match #4114

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shogun/base/SGObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <shogun/lib/parameter_observers/ObservedValue.h>
#include <shogun/lib/tag.h>

#include <utility>
#include <set>
#include <utility>

/** \namespace shogun
* @brief all of classes and functions are contained in the shogun namespace
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/base/class_list.cpp.templ
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void shogun::delete_object(CSGObject* object)
delete object;
}

std::set<std::string> available_objects()
std::set<std::string> shogun::available_objects()
{
std::set<std::string> result;
for (class_list_entry_t* i=class_list; i->m_class_name != NULL;
Expand Down
43 changes: 42 additions & 1 deletion tests/unit/base/SGObject_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2013 Heiko Strathmann
* Written (W) 2013-2018 Heiko Strathmann
* Written (W) 2014 Thoralf Klein
* Written (W) 2015 Wu Lin
*/

#include "MockObject.h"
#include <shogun/base/class_list.h>
#include <shogun/base/some.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/io/SerializableAsciiFile.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/kernel/LinearKernel.h>
#include <shogun/lib/DataType.h>
#include <shogun/machine/gp/ExactInferenceMethod.h>
#include <shogun/machine/gp/GaussianLikelihood.h>
#include <shogun/machine/gp/ZeroMean.h>
#include <shogun/neuralnets/NeuralNetwork.h>
#include <shogun/regression/GaussianProcessRegression.h>

#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
Expand Down Expand Up @@ -545,3 +548,41 @@ TEST(SGObject, watched_parameter_object)
obj = nullptr;
EXPECT_EQ(other_obj->ref_count(), 1);
}

// temporary test until old parameter framework is gone
// enable test to hunt for parameters not registered in tags
// see https://github.com/shogun-toolbox/shogun/issues/4117
TEST(SGObjectAll, DISABLED_tag_coverage)
{
auto class_names = available_objects();

for (auto class_name : class_names)
{
auto obj = create(class_name.c_str(), PT_NOT_GENERIC);

// templated classes cannot be created in the above way
if (!obj)
{
// only test single generic type here: all types have the same
// parameter names
obj = create(class_name.c_str(), PT_FLOAT64);
}

// whether templated or not
ASSERT_NE(obj, nullptr);

// old parameter framework names
std::set<std::string> old_names;
for (auto i : range(obj->m_parameters->get_num_parameters()))
old_names.insert(obj->m_parameters->get_parameter(i)->m_name);
auto tag_names = obj->parameter_names();

// hack to increase readability of error messages
old_names.insert("Class: " + class_name);
tag_names.insert("Class: " + class_name);

EXPECT_EQ(tag_names, old_names);

SG_UNREF(obj);
}
}