package cz.cuni.mff.d3s.spl.core.data.segment;

import static cz.cuni.mff.d3s.spl.test.TestUtils.assertStatisticsEqual;

import org.junit.Before;
import org.junit.Test;

import cz.cuni.mff.d3s.spl.core.data.PrecomputedStatistics;
import cz.cuni.mff.d3s.spl.core.data.SampleBasedDataSource;

public class SlidingTimeSlotDataSourceTest {

	private final static double EPSILON = 0.0001;
	
	private SlidingTimeSlotDataSource source;
	
	@Before
	public void prepareSamples() {
		source = new SlidingTimeSlotDataSource(0, 10);
		
		for (int i = 0; i < 100; i++) {
			source.newSample(i, i);
		}
	}
	
	@Test
	public void emptySourceProducesEmptyStatistics() {
		SampleBasedDataSource empty = new SlidingTimeSlotDataSource(0, 10);
		assertStatisticsEqual(PrecomputedStatistics.empty, empty.get(), EPSILON);
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void invalidIntervalThrowsException() {
		new SlidingTimeSlotDataSource(15, 10);
	}
	
	@Test
	public void testStatisticsComputedCorrectly() {
		/* 0 + 1 + .. + 9 */
		assertStatisticsEqual(PrecomputedStatistics.create(4.5, 10), source.get(), EPSILON);
	}
	
	@Test
	public void statisticsRecomputedAfterShift() {
		source.shift(5);
		/* 5 + 6 + .. + 14 */
		assertStatisticsEqual(PrecomputedStatistics.create(9.5, 10), source.get(), EPSILON);
	}
}

@@ -1206,10 +1206,9 @@
 . + 
-14
+9
  */%0A
@@ -1264,15 +1264,265 @@
 ate(
-9.5, 10
+7.0, 5), source.get(), EPSILON);%0A%09%7D%0A%09%0A%09@Test%0A%09public void shiftCapturesInDifferentInterval() %7B%0A%09%09source.shift(5);%0A%09%09source.newSample(1, 12);%0A%09%09source.newSample(1, 9999);%0A%09%09/* 5 + 6 + .. + 9 + 15 */%0A%09%09assertStatisticsEqual(PrecomputedStatistics.create(6.0, 6
 ), s

Fix test for SlidingTimeSlot source