-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
AnyParameterProperties tests #4421
Changes from 6 commits
400fdca
af9ba26
fcfe78d
690c833
27fe165
1e58b69
eee7074
2cc3835
a5dc6b5
45caae8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
// modified by Gil Hoben | ||
|
||
#include<type_traits> | ||
|
||
|
@@ -106,5 +108,11 @@ namespace shogun { | |
static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs)); | ||
return lhs; | ||
} | ||
template<typename E> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ |
||
typename std::enable_if<enable_bitmask_operators<E>::enable, bool>::type | ||
operator==(E lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
return static_cast<underlying>(lhs) == static_cast<underlying>(rhs); | ||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -691,3 +691,65 @@ TEST(Any, lazy_cloneable_visitable) | |
EXPECT_FALSE(any.visitable()); | ||
EXPECT_THROW(any.visit(nullptr), std::logic_error); | ||
} | ||
|
||
TEST(AnyParameterProperties, old_api_default) | ||
{ | ||
AnyParameterProperties params = AnyParameterProperties(); | ||
|
||
EXPECT_EQ( | ||
params.get_model_selection(), | ||
EModelSelectionAvailability::MS_NOT_AVAILABLE); | ||
EXPECT_EQ( | ||
params.get_gradient(), EGradientAvailability::GRADIENT_NOT_AVAILABLE); | ||
EXPECT_FALSE(params.get_model()); | ||
} | ||
|
||
TEST(AnyParameterProperties, new_api_default) | ||
{ | ||
AnyParameterProperties params = AnyParameterProperties(); | ||
|
||
EXPECT_TRUE(params.equals(ParameterProperties())); | ||
EXPECT_FALSE(params.has_property(ParameterProperties::MODEL)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as said before, can we not explicitly test that those are not set, but in fact that none are set. Otherwise we will have to modify tests when we add new attributes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did think I saw that comment in the previous PR, but the next day the comment disappeared.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that happens on force push. I keep the notification emails to not loose comments when github hides them. |
||
EXPECT_FALSE(params.has_property(ParameterProperties::GRADIENT)); | ||
EXPECT_FALSE(params.has_property(ParameterProperties::HYPER)); | ||
} | ||
|
||
TEST(AnyParameterProperties, old_custom_ctor) | ||
{ | ||
AnyParameterProperties params = AnyParameterProperties( | ||
"test", EModelSelectionAvailability::MS_NOT_AVAILABLE, | ||
EGradientAvailability::GRADIENT_AVAILABLE, true); | ||
|
||
EXPECT_EQ(params.get_description(), "test"); | ||
EXPECT_EQ( | ||
params.get_model_selection(), | ||
EModelSelectionAvailability::MS_NOT_AVAILABLE); | ||
EXPECT_EQ(params.get_gradient(), EGradientAvailability::GRADIENT_AVAILABLE); | ||
EXPECT_TRUE(params.get_model()); | ||
|
||
EXPECT_TRUE(params.has_property(ParameterProperties::MODEL)); | ||
EXPECT_TRUE(params.has_property(ParameterProperties::GRADIENT)); | ||
EXPECT_TRUE(params.equals( | ||
ParameterProperties::MODEL | ParameterProperties::GRADIENT)); | ||
EXPECT_FALSE(params.equals(ParameterProperties::MODEL)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everything else should be false. And that should be tested. Not just these two, same reasoning as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor indentation glitch |
||
EXPECT_FALSE(params.has_property(ParameterProperties::HYPER)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the last three are nop now |
||
} | ||
|
||
TEST(AnyParameterProperties, new_custom_ctor) | ||
{ | ||
AnyParameterProperties params = AnyParameterProperties( | ||
"test", ParameterProperties::MODEL | ParameterProperties::GRADIENT); | ||
|
||
EXPECT_EQ(params.get_description(), "test"); | ||
EXPECT_EQ( | ||
params.get_model_selection(), | ||
EModelSelectionAvailability::MS_NOT_AVAILABLE); | ||
EXPECT_EQ(params.get_gradient(), EGradientAvailability::GRADIENT_AVAILABLE); | ||
EXPECT_TRUE(params.get_model()); | ||
|
||
EXPECT_TRUE(params.has_property(ParameterProperties::MODEL)); | ||
EXPECT_TRUE(params.has_property(ParameterProperties::GRADIENT)); | ||
EXPECT_TRUE(params.equals( | ||
ParameterProperties::MODEL | ParameterProperties::GRADIENT)); | ||
EXPECT_FALSE(params.has_property(ParameterProperties::HYPER)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these last 3 as well |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure about this. equals should always just be true if really everything is semantically equal. So that would include the description and the name. Maybe a rename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! I just think in most cases the description will differ, yet we only want to know if they have the same
ParameterProperties
.Could just have:
and then:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first one is definitely useful, so let's have that
Second one I dont know whether we need this? But if we do, then all fields need to be compared of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second one is a bit of overkill and I cant think of a situation where it would be useful.. I'll just stick to the first one!