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

Refactoring AbstractRib and adding tests #598

Merged
merged 2 commits into from
Oct 23, 2017
Merged

Conversation

progwriter
Copy link
Contributor

Fixes #591

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Pretty awesome.


/*
If prefixes don't match exactly, look at the current bit. That determines whether we look
left of right. As long as the child is not null, recurse.
Copy link
Member

Choose a reason for hiding this comment

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

left or right

Copy link
Member

Choose a reason for hiding this comment

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

Either use Java multiline comment form

/*
 * ...
 */

or Java single-line block comment form:

// Line 1
// Line 2
// Line 3


// Assertions
// Check routes size
assertThat(_rib.getRoutes().size(), is(1));
Copy link
Member

Choose a reason for hiding this comment

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

can use Matchers.hasSize for this, I think. Assuming it's a Collection, not a Map.


@Test
public void testRibConstructor() {
// Test: the setupEmptyRib() fixture
Copy link
Member

Choose a reason for hiding this comment

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

Drop these comments -- structuring the test in a logical order with, optionally, whitespace between sections is good enough :)


@Test
public void testMultiOverlappingRouteAdd() {
// Setup/Test: Add multiple routes with overlapping prefixes
Copy link
Member

Choose a reason for hiding this comment

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

This type of comment where useful for understanding test goals should go in the function javadoc.


match = _rib.longestPrefixMatch(new Ip("10.1.1.2"));
assertThat(match.size(), equalTo(1));
assertThat(match, contains(routes.get(1)));
Copy link
Member

Choose a reason for hiding this comment

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

also test one that doesn't match (even though the rib is not empty ;).

import org.junit.Test;

/**
* Test the AbstractRib tree logic. To avoid worrying about route preference comparisons, testing
Copy link
Member

Choose a reason for hiding this comment

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

Simpler:

/** Tests of {@link AbstractRib}. */

Then move the bit about StaticRoute to the _rib variable.

My general rule here is that public Javadoc is for people looking at "What does X do?" whereas private documentation is for people reading the code ("how does X work?").

[And, I don't think I care how we test AbstractRib until I'm reading the code.]

*/
public class AbstractRibTest {
private AbstractRib<StaticRoute> _rib;
private StaticRoute _mostGeneralRoute;
Copy link
Member

Choose a reason for hiding this comment

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

private static final StaticRoute MOST_GENERAL_ROUTE = ...

Since it's a constant that will never change per test.

@progwriter progwriter removed the request for review from arifogel October 23, 2017 18:31
@dhalperi dhalperi merged commit f6fc3d5 into master Oct 23, 2017
@dhalperi dhalperi deleted the abstract-rib-refactor branch October 23, 2017 19:01
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.

None yet

2 participants