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

Introduce tests for CTree #167

Merged
merged 15 commits into from
Jan 16, 2018
Merged

Introduce tests for CTree #167

merged 15 commits into from
Jan 16, 2018

Conversation

jbduncan
Copy link
Contributor

@jbduncan jbduncan commented Dec 15, 2017

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!

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

Hey @jrtom, my PR here is not done yet, as I still have to write tests for CTreeNetwork (CTree should be tested extensively now), but I would greatly appreciate any feedback you may have at this point!

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

(Oh oops, seems that CTree#{root,depth,height] haven't been tested yet. But I'll tackle those during or after giving CTreeNetwork a go.)

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

(Actually, I've realised that I do not have the time and energy to tackle testing CTreeNetwork, so I'll leave that task to one side.)

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

Because of a number of uber commits which were merged into jung/master recently, it's proving to be too difficult for me to resolve conflicts, even with the built-in GitHub "Resolve conflicts" button, so I'm closing this PR with the intent to re-open it afresh atop a recent version of jung/master.

@jbduncan jbduncan closed this Jan 5, 2018
@jrtom
Copy link
Owner

jrtom commented Jan 5, 2018

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.)

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

@jrtom It's strange - I was having conflicts with ObservableNetwork and some other file (I cannot remember which now). Both files had a lot of changes to do with the recent "vertex" to "node" normalisation. And no matter whether I used git rebase or the GitHub "Resolve conflicts" button, I ended up either with git saying that I had ~87 commits to push instead of ~8 (from rebasing), or the conflicts apparently weren't resolved for some bizarre reason (from using the "Resolve conflicts" button).

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. :)

@jbduncan jbduncan reopened this Jan 5, 2018
@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

Oh no, wait, the merge conflict seems to be back?

This is doing my head in. :/

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

@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.

@jbduncan jbduncan closed this Jan 5, 2018
@jbduncan jbduncan reopened this Jan 5, 2018
@jrtom
Copy link
Owner

jrtom commented Jan 5, 2018

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.)

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 5, 2018

Probably the easiest way to resolve this would be to revert the changes to those two files, which are unrelated textual cleanup changes anyway.

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. :)

(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.)

I personally think that the null checks are justified for the ObservableNetwork constructor and *GraphEvent* methods, as AFAICT those methods would otherwise allow nulls to silently pass-through. But for all the other methods, I think you make a good point. So if you have no objections, I will remove the null checks for all the methods except the constructor and *GraphEvent* methods.

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 7, 2018

@jrtom I've managed to merge jung/master into this PR after a couple of tries, so there's no need to temporarily revert changes to ObservableNetwork and ParallelEdgeIndexFunction now. :)

@jbduncan
Copy link
Contributor Author

jbduncan commented Jan 7, 2018

@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.
*/
Copy link
Contributor

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope :)

Copy link
Contributor Author

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.

@jrtom
Copy link
Owner

jrtom commented Jan 9, 2018

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).

@jbduncan
Copy link
Contributor Author

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? :)

@jrtom
Copy link
Owner

jrtom commented Jan 16, 2018

Taking a look now.

By the way, thanks for taking a look at @tomnelson's layout events change CL. :)

Copy link
Owner

@jrtom jrtom left a 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> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch :)

Copy link
Contributor Author

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");
Copy link
Owner

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.

Copy link
Contributor Author

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
Copy link
Owner

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?

Copy link
Contributor Author

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 jrtom merged commit a5de353 into jrtom:master Jan 16, 2018
@jbduncan
Copy link
Contributor Author

@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?

@jbduncan
Copy link
Contributor Author

Oh, I found the messages regarding the breakages in my emails:

@jbduncan the change to DelegateCTreeNetwork::setDepth broke the TreeCollapseDemo. You might want to have a look at it to make sure it does what you want.

and:

Also, the new Preconditions checks in TreeUtils make it impossible to re-expand the root node once you collapse there. I'll look into that more tomorrow.
Just run TreeCollapseDemo and select various nodes to collapse then expand. You'll see where the problems are.

I can't seem to reproduce message 1 regarding DelegateCTreeNetwork::setDepth. @tomnelson Could you clarify for me what I need to do to see the respective breakage in TreeCollapseDemo?

I have been able to reproduce message 2 regarding TreeUtils; it looks like TreeUtils::addSubTree throws a NullPointerException because it doesn't expect parameter subTreeParent to be null. But I'm struggling to understand why null is being passed to it, and why null should be a valid value. @tomnelson Could you clarify things for me?

@jbduncan
Copy link
Contributor Author

Message 1 has been fixed in #202. Message 2 is being addressed in #204.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

specifying a new Tree API
3 participants