-
Notifications
You must be signed in to change notification settings - Fork 115
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
Introduce tests for CTree #167
Conversation
Hey @jrtom, my PR here is not done yet, as I still have to write tests for |
(Oh oops, seems that |
(Actually, I've realised that I do not have the time and energy to tackle testing |
Because of a number of uber commits which were merged into |
Can you tell me what conflicts you were encountering? Your latest commit passed the tests, so while I haven't looked in detail at all the changes in this PR, we might be able to go ahead and merge what you have if everything looks OK. (And then you can take on CTreeNetwork at another time if that works for you.) |
@jrtom It's strange - I was having conflicts with It's funny that the tests only pass only now. I could've sworn there was still a merge conflict after I resolved things using "Resolve conflicts". I'll re-open this PR then, as things seem to have resolved (haha) themselves. :) |
Oh no, wait, the merge conflict seems to be back? This is doing my head in. :/ |
@jrtom If it's alright with you, I think I'll close this PR again. I went and opened #172 before I saw your earlier message, and #172 doesn't seem to suffer from this merge conflict problem, so I think it should be easier to review and merge and this PR. |
Probably the easiest way to resolve this would be to revert the changes to those two files, which are unrelated textual cleanup changes anyway. (Side point: I'm not sure it's helpful for ObservableNetwork to be doing all those null checks, unless we're presuming that the delegate won't be doing them...and in the case of the common.graph implementations, it is.) |
Okay, that sounds like a way forward to me. Were you thinking of reverting the changes to those files youself? If not, I could open a PR myself, but it would have to wait until tomorrow earliest, as I need to get to bed soon. :)
I personally think that the null checks are justified for the |
@jrtom I've managed to merge |
@jrtom I believe that I've fixed all test errors reported by Travis, so I'm ready for another review whenever you are. :) FYI, before merging, I'd quite like to squash all my commits, so unless you can squash them on your end, I'd like to be given time after the next review to squash them myself. |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
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.
Is that the correct license and copyright if it's going into JUNG?
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 :)
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.
Indeed it isn't, good catch! I'll address this later today.
I'll take a look at this in the next day or so. Regarding commit-squashing, that's easy to do as part of the merge, so just remind me before I do the merge (i.e., when it looks like we're done addressing comments). |
Hi @jrtom, how are you doing with reviewing this PR? Do you need anything from my end, or do you just need more time to look through things? :) |
Taking a look now. By the way, thanks for taking a look at @tomnelson's layout events change CL. :) |
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.
Basically looks good. Thanks for taking this on. :)
I made one minor suggestion but we can do that in a separate pass.
@@ -24,18 +28,16 @@ | |||
import java.util.Optional; | |||
import java.util.Set; | |||
|
|||
class DelegateCTree<N> implements MutableCTree<N> { | |||
class DelegateCTree<N> extends AbstractGraph<N> implements MutableCTree<N> { |
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.
good catch :)
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.
Ta! :)
: Optional.of(Iterables.getOnlyElement(predecessors)); | ||
} | ||
|
||
@Override | ||
public int depth(N node) { | ||
Preconditions.checkArgument(delegate.nodes().contains(node)); | ||
checkNotNull(node, "node"); |
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've got a bunch of identical checks in the accessors. Consider creating a private method to sanity check the input:
private void sanityCheckNode(N node) {
checkNotNull(node, "node");
checkArgument(delegate.nodes().contains(node), NODE_NOT_IN_TREE, node);
}
That both reduces the amount of code and makes it easier for us to uniformly change our error handling if desired.
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.
Good catch! I'll try to remember to address this if I find the time to improve the tests. :)
} | ||
|
||
static <N> void validateTree(CTree<N> tree) { | ||
// TODO: Replace Graphs#copyOf with a tree-specific copyOf method if it ever turns up |
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'm not sure what might cause us to write a tree-specific version of this method. Did you have anything specific in mind, i.e., how might that be useful?
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.
Oops, I've just realised that I never responded to this comment. Sorry @jrtom!
I think I was concerned that using Graphs#copyOf
forced one of the parameters of assertStronglyEquivalent
to be of type Graph
instead of CTree
. If I remember correctly, the way I saw things then, this prevented the test from checking that if a CTree
was copied then it's root()
and height()
remained the same and that the depth()
s and predecessor()
s of each of its nodes remained unchanged.
But having said this, TreeUtils
doesn't have a copyOf
method AFAICT, and it's unclear to me if there ever will be such a method.
Should I expand this TODO comment?
Or do you think it's not worth the effort and that I should just remove it (and in the process remove this TODO as well)?
@jrtom, we discussed privately that my PR here caused a breakage somewhere in JUNG (I think with one of the demos managed by @tomnelson specifically), and that I'd raise a new PR to fix it, but I can't seem to find that breakage any longer. @tomnelson @jrtom Would you kindly point me in the direction of the message that mentioned the breakage, or would you kindly remind me what the breakage was? |
Oh, I found the messages regarding the breakages in my emails:
and:
I can't seem to reproduce message 1 regarding I have been able to reproduce message 2 regarding |
This is a work-in-progress PR to introduce tests for CTree et al. It partially resolves #83.
The tests are heavily inspired by Guava's own
com.google.common.graph
tests and borrows their general structure and many other ideas. At time of writing, no effort has been made yet to make the tests go green.Constructive feedback is welcome!