Follow-up changes to TimeOfYear from []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123316677
This commit is contained in:
ctingue 2016-05-26 07:21:39 -07:00 committed by Ben McIlwain
parent a09f478ac0
commit 510da196d7
2 changed files with 39 additions and 46 deletions

View file

@ -70,15 +70,14 @@ public class TimeOfYearTest {
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.closed(startDate, endDate));
ImmutableSet<DateTime> expected = ImmutableSet.<DateTime>of(
DateTime.parse("2012-05-01T00:00:00Z"),
DateTime.parse("2013-05-01T00:00:00Z"),
DateTime.parse("2014-05-01T00:00:00Z"),
DateTime.parse("2015-05-01T00:00:00Z"),
DateTime.parse("2016-05-01T00:00:00Z"));
assertThat(actual).containsExactlyElementsIn(expected);
assertThat(timeOfYear.getInstancesInRange(Range.closed(startDate, endDate)))
.containsExactlyElementsIn(expected);
}
@Test
@ -86,14 +85,13 @@ public class TimeOfYearTest {
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.openClosed(startDate, endDate));
ImmutableSet<DateTime> expected = ImmutableSet.<DateTime>of(
DateTime.parse("2013-05-01T00:00:00Z"),
DateTime.parse("2014-05-01T00:00:00Z"),
DateTime.parse("2015-05-01T00:00:00Z"),
DateTime.parse("2016-05-01T00:00:00Z"));
assertThat(actual).containsExactlyElementsIn(expected);
assertThat(timeOfYear.getInstancesInRange(Range.openClosed(startDate, endDate)))
.containsExactlyElementsIn(expected);
}
@Test
@ -101,14 +99,13 @@ public class TimeOfYearTest {
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.closedOpen(startDate, endDate));
ImmutableSet<DateTime> expected = ImmutableSet.<DateTime>of(
DateTime.parse("2012-05-01T00:00:00Z"),
DateTime.parse("2013-05-01T00:00:00Z"),
DateTime.parse("2014-05-01T00:00:00Z"),
DateTime.parse("2015-05-01T00:00:00Z"));
assertThat(actual).containsExactlyElementsIn(expected);
assertThat(timeOfYear.getInstancesInRange(Range.closedOpen(startDate, endDate)))
.containsExactlyElementsIn(expected);
}
@Test
@ -116,37 +113,34 @@ public class TimeOfYearTest {
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z");
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z"));
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.open(startDate, endDate));
ImmutableSet<DateTime> expected = ImmutableSet.<DateTime>of(
DateTime.parse("2013-05-01T00:00:00Z"),
DateTime.parse("2014-05-01T00:00:00Z"),
DateTime.parse("2015-05-01T00:00:00Z"));
assertThat(actual).containsExactlyElementsIn(expected);
assertThat(timeOfYear.getInstancesInRange(Range.open(startDate, endDate)))
.containsExactlyElementsIn(expected);
}
@Test
public void testSuccess_getInstancesInRange_normalizedLowerBound() {
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(START_OF_TIME);
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.atMost(START_OF_TIME.plusYears(2)));
ImmutableSet<DateTime> expected = ImmutableSet.<DateTime>of(
START_OF_TIME,
START_OF_TIME.plusYears(1),
START_OF_TIME.plusYears(2));
assertThat(actual).containsExactlyElementsIn(expected);
assertThat(timeOfYear.getInstancesInRange(Range.atMost(START_OF_TIME.plusYears(2))))
.containsExactlyElementsIn(expected);
}
@Test
public void testSuccess_getInstancesInRange_normalizedUpperBound() {
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(END_OF_TIME);
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.atLeast(END_OF_TIME.minusYears(2)));
ImmutableSet<DateTime> expected = ImmutableSet.<DateTime>of(
END_OF_TIME.minusYears(2),
END_OF_TIME.minusYears(1),
END_OF_TIME);
assertThat(actual).containsExactlyElementsIn(expected);
assertThat(timeOfYear.getInstancesInRange(Range.atLeast(END_OF_TIME.minusYears(2))))
.containsExactlyElementsIn(expected);
}
@Test
@ -154,8 +148,6 @@ public class TimeOfYearTest {
DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z");
DateTime endDate = DateTime.parse("2013-02-01T00:00:00Z");
TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-03-01T00:00:00Z"));
ImmutableSet<DateTime> actual =
timeOfYear.getInstancesInRange(Range.closed(startDate, endDate));
assertThat(actual).isEmpty();
assertThat(timeOfYear.getInstancesInRange(Range.closed(startDate, endDate))).isEmpty();
}
}