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
AnyParameterProperties tests #4421
Conversation
* avoids using several getters
this ensures that the underlying type is used to cast and make the comparisson
src/shogun/base/AnyParameter.h
Outdated
return static_cast<bool>(m_attribute_mask & other_params); | ||
} | ||
|
||
bool equals(ParameterProperties other_params) const |
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:
/** Compare masks */
bool compare_mask(ParameterProperties other_params) const
{
return m_attribute_mask == other_params ;
}
and then:
/** Compare AnyParameterProperties properties */
bool equals(AnyParameterProperties other) const
{
return (description == other.description) && has_mask(other.get_mask());
}
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!
tests/unit/lib/Any_unittest.cc
Outdated
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 comment
The 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 comment
The 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 comment
The 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.
tests/unit/lib/Any_unittest.cc
Outdated
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 comment
The 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
tests/unit/lib/Any_unittest.cc
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
these last 3 as well
tests/unit/lib/Any_unittest.cc
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
minor indentation glitch
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
++
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.
just a few minor things.
* makes method names clearer
Is this what you mean with check that none are set? |
tests/unit/lib/Any_unittest.cc
Outdated
EXPECT_TRUE(params.has_property(ParameterProperties::GRADIENT)); | ||
EXPECT_TRUE(params.equals( | ||
ParameterProperties::MODEL | ParameterProperties::GRADIENT)); | ||
EXPECT_FALSE(params.compare_mask( |
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.
nope, this just checks that one is not set.
you want to check that none are set. So you need to create an "empty" mask (all zeros) and then call compare_mask
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.
but this empty mask should be created via not explicitly listing the available types.
Again, this is to avoid having to touch all these tests in the case when a type is added
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! And the EXPECT_FALSE
after, are they not necessary then? They should be covered by the empty mask.
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.
not sure what you mean, but what about something like
EXPECT_TRUE(params.compare_mask(ParameterProperties::EMPTY))
or similar
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.
But EXPECT_TRUE(params.compare_mask(ParameterProperties::EMPTY))
is the same as EXPECT_TRUE(params.compare_mask(ParameterProperties()))
. I can add a EMPTY though to the enum.
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.
you can, and of course it is the same. But then it wouldnt test that the default properties are indeed empty, so the test would not be of an use: It would just test that if you create two properties with the default ctor, they have the same parameters. If you would check for EMPTY
(or maybe we call it NONE
(and define it to be 0x0
), then you also assert that the default ctor generates empty parameters, which is exactly what we want here. If people then later start messing around with the ctor (e.g. change the default), the test will fail, so it provides some protection against devs going wild
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.
Ah ok! But then in that case it might make more sense to instantiate the m_attribute_mask
class member in the constructors with ParameterProperties::EMPTY
rather than ParameterProperties()
no? I just used ParameterProperties()
because it was the easiest way to represent zero without any casting.
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.
yes that is even more explicit
This is the equivalent of zero
tests/unit/lib/Any_unittest.cc
Outdated
EXPECT_FALSE(params.get_model()); | ||
|
||
EXPECT_TRUE(params.compare_mask(ParameterProperties::NONE)); | ||
EXPECT_FALSE(params.has_property(ParameterProperties::HYPER)); |
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.
the last three are nop now
Do you think this is ready to be merged? Started working on the new getters in CSGObject using the enums as filters, and was wondering what new methods from this PR I could use. |
As usual, let's keep an eye on azure and buildbot |
Thanks! |
* added method to check mask * avoids using several getters * added tests for AnyParameterProperties * added equals method * overloaded `==` enum bitmask operator * Added None enum type to ParameterProperties
* added method to check mask * avoids using several getters * added tests for AnyParameterProperties * added equals method * overloaded `==` enum bitmask operator * Added None enum type to ParameterProperties
* added method to check mask * avoids using several getters * added tests for AnyParameterProperties * added equals method * overloaded `==` enum bitmask operator * Added None enum type to ParameterProperties
* added method to check mask * avoids using several getters * added tests for AnyParameterProperties * added equals method * overloaded `==` enum bitmask operator * Added None enum type to ParameterProperties
Added tests to check binary logic of AnyParameterProperties.m_attribute_mask.