Skip to content

Commit

Permalink
Add a unit test for event detection with default parameters, #130
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-brown committed Dec 24, 2024
1 parent 38c78e4 commit b5c19aa
Showing 1 changed file with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ void testDetectWithTrendAndThreeEvents()
Instant endOne = Instant.parse( "2018-01-29T00:00:00Z" );

TimeWindow expectedInnerOne = MessageFactory.getTimeWindow()
.toBuilder()
.setEarliestValidTime( MessageFactory.getTimestamp( startOne ) )
.setLatestValidTime( MessageFactory.getTimestamp( endOne ) )
.build();
.toBuilder()
.setEarliestValidTime( MessageFactory.getTimestamp( startOne ) )
.setLatestValidTime( MessageFactory.getTimestamp( endOne ) )
.build();

Instant startTwo = Instant.parse( "2018-03-04T18:00:00Z" );
Instant endTwo = Instant.parse( "2018-03-11T16:00:00Z" );
Expand All @@ -184,18 +184,52 @@ void testDetectWithTrendAndThreeEvents()
Instant endThree = Instant.parse( "2018-04-22T08:00:00Z" );

TimeWindow expectedInnerThree = MessageFactory.getTimeWindow()
.toBuilder()
.setEarliestValidTime( MessageFactory.getTimestamp( startThree ) )
.setLatestValidTime( MessageFactory.getTimestamp( endThree ) )
.build();
.toBuilder()
.setEarliestValidTime( MessageFactory.getTimestamp( startThree ) )
.setLatestValidTime( MessageFactory.getTimestamp( endThree ) )
.build();

Set<TimeWindowOuter> expected = Set.of( TimeWindowOuter.of( expectedInnerOne),
Set<TimeWindowOuter> expected = Set.of( TimeWindowOuter.of( expectedInnerOne ),
TimeWindowOuter.of( expectedInnerTwo ),
TimeWindowOuter.of( expectedInnerThree ) );

assertEquals( expected, actual );
}

@Test
void testDetectWithTrendAndThreeEventsAndDefaultParametersProducesCorrectEventCount()
{
TimeSeries<Double> testSeries = this.createTestSeries( false );

// Duplicate the series three times
Instant start = testSeries.getEvents()
.first()
.getTime();
TimeSeries.Builder<Double> builder = new TimeSeries.Builder<Double>().setMetadata( testSeries.getMetadata() );
for ( int i = 0; i < 3; i++ )
{
for ( Event<Double> nextEvent : testSeries.getEvents() )
{
Event<Double> adjusted = Event.of( start, nextEvent.getValue() );
builder.addEvent( adjusted );
start = start.plus( Duration.ofHours( 1 ) );
}
}

testSeries = builder.build();

// Default parameters
EventDetectionParameters parameters = EventDetectionParametersBuilder.builder()
.build();

ReginaOgdenEventDetector detector = ReginaOgdenEventDetector.of( parameters );

Set<TimeWindowOuter> actual = detector.detect( testSeries );

// Assert event count only as the default parameters are merely best guesses
assertEquals( 3, actual.size() );
}

@Test
void testDetectWithTrendAndOneEventAndNoise()
{
Expand Down

0 comments on commit b5c19aa

Please sign in to comment.