Skip to content

Commit

Permalink
Add unit tests for the intersection of time windows, #130
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-brown committed Dec 26, 2024
1 parent 9a5c00f commit e0bf850
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions wres-datamodel/test/wres/datamodel/time/TimeWindowSlicerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,103 @@ void testIntersectionOnLeadDurationsOnly()
assertEquals( expected, actual );
}

@Test
void testIntersectionOnValidTimeOnly()
{
TimeWindow one = MessageFactory.getTimeWindow( Instant.parse( INSTANT_ONE ),
Instant.parse( INSTANT_TWO ) );
TimeWindow two = MessageFactory.getTimeWindow( Instant.parse( INSTANT_FOUR ),
Instant.parse( INSTANT_THREE ) );
TimeWindow three = MessageFactory.getTimeWindow( Instant.parse( INSTANT_ONE ),
Instant.parse( INSTANT_THREE ) );
TimeWindow four = MessageFactory.getTimeWindow( Instant.parse( INSTANT_ELEVEN ),
Instant.parse( INSTANT_TEN ) );
Set<TimeWindowOuter> first = Set.of( TimeWindowOuter.of( one ),
TimeWindowOuter.of( two ) );
Set<TimeWindowOuter> second = Set.of( TimeWindowOuter.of( three ),
TimeWindowOuter.of( four ) );

Set<TimeWindowOuter> actual = TimeWindowSlicer.intersection( first, second );
Set<TimeWindowOuter> expected = Set.of( TimeWindowOuter.of( one ),
TimeWindowOuter.of( two ),
TimeWindowOuter.of( three ) );

assertEquals( expected, actual );
}

@Test
void testIntersectionOnReferenceTimeOnly()
{
TimeWindow one = MessageFactory.getTimeWindow( Instant.parse( INSTANT_ONE ),
Instant.parse( INSTANT_TWO ),
Instant.MIN,
Instant.MAX );
TimeWindow two = MessageFactory.getTimeWindow( Instant.parse( INSTANT_FOUR ),
Instant.parse( INSTANT_THREE ),
Instant.MIN,
Instant.MAX );
TimeWindow three = MessageFactory.getTimeWindow( Instant.parse( INSTANT_ONE ),
Instant.parse( INSTANT_THREE ),
Instant.MIN,
Instant.MAX );
TimeWindow four = MessageFactory.getTimeWindow( Instant.parse( INSTANT_ELEVEN ),
Instant.parse( INSTANT_TEN ),
Instant.MIN,
Instant.MAX );
Set<TimeWindowOuter> first = Set.of( TimeWindowOuter.of( one ),
TimeWindowOuter.of( two ) );
Set<TimeWindowOuter> second = Set.of( TimeWindowOuter.of( three ),
TimeWindowOuter.of( four ) );

Set<TimeWindowOuter> actual = TimeWindowSlicer.intersection( first, second );
Set<TimeWindowOuter> expected = Set.of( TimeWindowOuter.of( one ),
TimeWindowOuter.of( two ),
TimeWindowOuter.of( three ) );

assertEquals( expected, actual );
}

@Test
void testIntersectionOnLeadDurationValidTimeAndReferenceTime()
{
TimeWindow one = MessageFactory.getTimeWindow( Instant.parse( "1934-01-01T00:00:00Z" ),
Instant.parse( "1934-01-02T00:00:00Z" ),
Instant.parse( "1935-01-01T00:00:00Z" ),
Instant.parse( "1935-01-02T00:00:00Z" ),
Duration.ofHours( 1 ),
Duration.ofHours( 2 ) );
TimeWindow two = MessageFactory.getTimeWindow( Instant.parse( "1933-01-01T00:00:00Z" ),
Instant.parse( "1934-01-02T00:00:00Z" ),
Instant.parse( "1934-01-01T00:00:00Z" ),
Instant.parse( "1935-01-02T00:00:00Z" ),
Duration.ofHours( 1 ),
Duration.ofHours( 2 ) );
TimeWindow three = MessageFactory.getTimeWindow( Instant.parse( "1934-01-01T00:00:00Z" ),
Instant.parse( "1934-01-04T00:00:00Z" ),
Instant.parse( "1935-01-01T00:00:00Z" ),
Instant.parse( "1935-01-03T00:00:00Z" ),
Duration.ofHours( 2 ),
Duration.ofHours( 5 ) );
TimeWindow four = MessageFactory.getTimeWindow( Instant.parse( "1934-01-01T00:00:00Z" ),
Instant.parse( "1934-01-02T00:00:00Z" ),
Instant.parse( "1935-01-01T00:00:00Z" ),
Instant.parse( "1935-01-02T00:00:00Z" ),
Duration.ofHours( 3 ),
Duration.ofHours( 4 ) );

Set<TimeWindowOuter> first = Set.of( TimeWindowOuter.of( one ),
TimeWindowOuter.of( two ) );
Set<TimeWindowOuter> second = Set.of( TimeWindowOuter.of( three ),
TimeWindowOuter.of( four ) );

Set<TimeWindowOuter> actual = TimeWindowSlicer.intersection( first, second );
Set<TimeWindowOuter> expected = Set.of( TimeWindowOuter.of( one ),
TimeWindowOuter.of( two ),
TimeWindowOuter.of( three ) );

assertEquals( expected, actual );
}

@Test
void testAdjustByTimeScalePeriodWhenTimeScaleIsInstantaneous()
{
Expand Down

0 comments on commit e0bf850

Please sign in to comment.