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

Implement method for finding coarsest ZonedTimeGrain #230

Merged
merged 6 commits into from
Apr 7, 2017

Conversation

QubitPi
Copy link
Contributor

@QubitPi QubitPi commented Apr 5, 2017

No description provided.

@QubitPi QubitPi force-pushed the get-coarsest-ZonedTimeGrain branch from 5686dd8 to fd99497 Compare April 5, 2017 21:46
@QubitPi QubitPi self-assigned this Apr 5, 2017
@QubitPi QubitPi force-pushed the get-coarsest-ZonedTimeGrain branch 2 times, most recently from 1155253 to 816b0f8 Compare April 5, 2017 21:59
*/
public static ZonedTimeGrain getCoarsestTimeGrain(Collection<ZonedTimeGrain> zonedTimeGrains) {
return zonedTimeGrains.stream()
.sorted(Comparator.comparing(ZonedTimeGrain::getEstimatedDuration))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we comparing based on estimated duration instead of using the GranularityComparator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cdeszaq Because GranularityComparator compares by taking PhysicalTable not ZonedTimeGrain. I can write a comparator for ZonedTimeGrain if that's you would like to do.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point. That's unfortunate. If the intent of this helper method is to make it easy to select the coarsest grain from a collection of PhysicalTables, perhaps we should convert this method to do that, and then use the GranularityComparator?

@@ -326,6 +328,32 @@ class IntervalUtilsSpec extends Specification {
DAY | ["2012-02-03/2017-04-04"] | ["2012-02-03/2012-05-04", "2017-02-03/2017-04-04"]
}

@Unroll
def "getCoarsestTimeGrain returns duration of #expected among #duration1, #duration2, #duration3"() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we testing / asserting behavior about durations when we are generally dealing with ZonedTimeGrain?

Copy link
Contributor Author

@QubitPi QubitPi Apr 6, 2017

Choose a reason for hiding this comment

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

@cdeszaq By digging into the source code, I found that comparing ZonedTimeGrain is the same thing as comparing duration. Would you like me to change the testing behavior anyway?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. It's better to keep the tests focused on the external interface and the behavior, and to try to not duplicate what the code under test is doing when testing it.

duration1 | duration2 | duration3 | expected
1 | 2 | 3 | 1
1 | 1 | 3 | 1
3 | 3 | 3 | 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason we're using mocked grains instead of using real grains and giving them a timezone?

where:
duration1 | duration2 | duration3 | expected
1 | 2 | 3 | 1
1 | 1 | 3 | 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make sure to test what happens when we have the same grain but different time zones.

/**
* Returns the coarsest ZonedTimeGrain among a set of ZonedTimeGrains.
* <p>
* If the set of ZonedTimeGrains is empty, return null.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we returning null here? Do we really expect null to be a valid return value? If we do, we should make that explicit in the return type by using Optional and force callers to deal with the fact that it could come back as null.

@QubitPi QubitPi force-pushed the get-coarsest-ZonedTimeGrain branch from 3a33f14 to c2c5e23 Compare April 7, 2017 18:22
Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

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

Just 3 very small things. I'm good with this once those are looked at.

MINUTE | HOUR | DAY | 'America/Chicago' | 'America/Los_Angeles' | 'America/Phoenix' | DAY | 'America/Phoenix' | 'different grains and different time zones'
}

def "getCoarsestTimeGrain returns null on empty input time grain collections"() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be returns empty, not null, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes


def "getCoarsestTimeGrain returns null on empty input time grain collections"() {
expect:
IntervalUtils.getCoarsestTimeGrain(Collections.emptyList()) == Optional.empty()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just use groovy's list literal for an empty list: []

timeGrain1 | timeGrain2 | timeGrain3 | timeZone1 | timeZone2 | timeZone3 | expectedTimeGrain | expectedTimeZone | description
DAY | DAY | DAY | 'America/Chicago' | 'America/Los_Angeles' | 'America/Phoenix' | DAY | 'America/Chicago' | 'same grain but different time zones'
MINUTE | HOUR | DAY | 'America/Phoenix' | 'America/Phoenix' | 'America/Phoenix' | DAY | 'America/Phoenix' | 'same time zone but different grans'
MINUTE | HOUR | DAY | 'America/Chicago' | 'America/Los_Angeles' | 'America/Phoenix' | DAY | 'America/Phoenix' | 'different grains and different time zones'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add some more cases that use week, month, quarter, and year? Some of those (ie. week) are odd in terms of how they line up, so that would be good to double-check.

Copy link
Collaborator

@garyluoex garyluoex left a comment

Choose a reason for hiding this comment

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

Good

@QubitPi QubitPi merged commit c4578aa into master Apr 7, 2017
@QubitPi QubitPi deleted the get-coarsest-ZonedTimeGrain branch April 7, 2017 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants