/** * Creates a new instance of <code>{@link LongAssert}</code>. * @param actual the actual value. * @return the created assertion object. */ public static LongAssert assertThat(Long actual) { return new LongAssert(actual); }
@Test public void marshal_long_strings_to_long() throws Exception { String validInput = String.valueOf(Long.MAX_VALUE); long expectedOutput = Long.MAX_VALUE; assertThat(longBodyMarshaller.marshal(validInput)).isEqualTo(expectedOutput); }
@Test public void testFilterPerformance() throws Exception { // Apply a filter operation and measure the elapsed time. long begin = System.nanoTime(); int lookupTimes = 1000; for (int i = 0; i < lookupTimes; i++) { dataSetOpEngine.execute(EXPENSE_REPORTS, filterByCityAndDept.getOperationList()); } long time = System.nanoTime()-begin; // Check out the resulting stats DataSetIndex dataSetIndex = dataSetOpEngine.getIndexRegistry().get(EXPENSE_REPORTS); DataSetIndexStats stats = dataSetIndex.getStats(); DataSet dataSet = dataSetIndex.getDataSet(); System.out.println(stats.toString("\n")); // Assert reuse is working. assertThat(stats.getNumberOfFilterOps()).isEqualTo(2); // The build time should be shorter than the overall lookup time. assertThat(stats.getBuildTime()).isLessThan(time); // The reuse rate must reflect the number of times the lookups are being reused. assertThat(stats.getReuseRate()).isGreaterThanOrEqualTo(lookupTimes-1); // The index size must not be greater than the 20% of the dataset's size assertThat(stats.getIndexSize()).isLessThan(dataSet.getEstimatedSize()/5); }
@Test public void testElapsedTime() throws Exception { chronometer.start(); Thread.sleep(100); chronometer.stop(); assertThat(chronometer.elapsedTime()).isLessThanOrEqualTo(110000000); } }
@Test public void givenActViewedForFirstTimeWhenDurationCalculatedThenCalculatedDurationIsCurrentDuration() throws Exception { long currentDuration = 50L; long duration = calc.calculateNewDuration(mockViscosity, 0, currentDuration); assertThat(duration).isEqualTo(currentDuration); }
assertThat(stats.getBuildTime()).isLessThan(time); assertThat(stats.getIndexSize()).isLessThan(dataSet.getEstimatedSize()/5);
@Test public void givenActHasDurationZeroWhenDurationCalculatedThenCalculatedDurationIsZero() throws Exception { long currentDuration = 0L; long duration = calc.calculateNewDuration(mockViscosity, 0, currentDuration); assertThat(duration).isEqualTo(0L); }
@Test public void testGroupPerformance() throws Exception { // Apply two different group operations and measure the elapsed time. long begin = System.nanoTime(); int lookupTimes = 1000; for (int i = 0; i < lookupTimes; i++) { dataSetOpEngine.execute(EXPENSE_REPORTS, groupByDeptAndCount.getOperationList()); dataSetOpEngine.execute(EXPENSE_REPORTS, groupByDeptAndSum.getOperationList()); } long time = System.nanoTime()-begin; // Check out the resulting stats DataSetIndex dataSetIndex = dataSetOpEngine.getIndexRegistry().get(EXPENSE_REPORTS); DataSetIndexStats stats = dataSetIndex.getStats(); DataSet dataSet = dataSetIndex.getDataSet(); System.out.println(stats.toString("\n")); // Assert the reuse of group operations and aggregate calculations is working. assertThat(stats.getNumberOfGroupOps()).isEqualTo(1); assertThat(stats.getNumberOfAggFunctions()).isEqualTo(10); // The build time should be shorter than the overall lookup time. assertThat(stats.getBuildTime()).isLessThan(time); // The reuse rate must reflect the number of times the lookups are being reused. assertThat(stats.getReuseRate()).isGreaterThanOrEqualTo(lookupTimes-1); // The index size must not be greater than the 20% of the dataset's size assertThat(stats.getIndexSize()).isLessThan(dataSet.getEstimatedSize()/5); }
/** * Creates a new instance of <code>{@link LongAssert}</code>. * @param actual the actual value. * @return the created assertion object. */ public static LongAssert assertThat(long actual) { return new LongAssert(actual); }
@Test public void marshal_integer_strings_to_long() throws Exception { String validInput = "5"; long expectedOutput = 5; assertThat(longBodyMarshaller.marshal(validInput)).isEqualTo(expectedOutput); }
@Test public void testWhenMaxViewsReachedDurationIsZero() throws Exception { int maxViews = 2; ViscosityInterpolator viscosity = new AllOrNothingViscosityInterpolator(maxViews); long duration = viscosity.calculateDuration(ANY_LONG, ++maxViews); assertThat(duration).isEqualTo(0); }
@Test public void testWhenStepThresholdReachedDurationIsHalved() throws Exception { int stepThreshold = 2; ViscosityInterpolator viscosity = new TwoStepViscosityInterpolator(stepThreshold); long duration = viscosity.calculateDuration(ANY_LONG, stepThreshold); assertThat(duration).isEqualTo(ANY_LONG / 2); }
@Test public void testWhenMaxViewsReachedDurationIsZero() throws Exception { int maxViews = 2; ViscosityInterpolator viscosity = new LinearChangeViscosityInterpolator(maxViews); long duration = viscosity.calculateDuration(ANY_LONG, maxViews); assertThat(duration).isEqualTo(0); }
@Test public void testWhenViewCountIs1DurationEqualsCurrentDuration() throws Exception { ViscosityInterpolator viscosity = new LinearChangeViscosityInterpolator(10); int viewCount = 1; long currentDuration = ANY_LONG; long duration = viscosity.calculateDuration(currentDuration, viewCount); assertThat(duration).isEqualTo(currentDuration); }
@Test public void testWhenViewCountIs10of20AndCurrentDuration500DurationEquals250() throws Exception { ViscosityInterpolator viscosity = new LinearChangeViscosityInterpolator(20); int viewCount = 10; long currentDuration = 500; long duration = viscosity.calculateDuration(currentDuration, viewCount); assertThat(duration).isEqualTo(250); } }
@Test public void testWhenViewCountIsOverMaxViewsDurationIsZero() throws Exception { int maxViews = 2; ViscosityInterpolator viscosity = new LinearChangeViscosityInterpolator(maxViews); long duration = viscosity.calculateDuration(ANY_LONG, ++maxViews); assertThat(duration).isEqualTo(0); }
@Test public void testWhenViewCountIs10of10AndCurrentDuration100DurationEquals0() throws Exception { ViscosityInterpolator viscosity = new LinearChangeViscosityInterpolator(10); int viewCount = 10; long currentDuration = 100; long duration = viscosity.calculateDuration(currentDuration, viewCount); assertThat(duration).isEqualTo(0); }
@Test public void testWhenViewCountIsUnderStepThresholdDurationIsNotChanged() throws Exception { int stepThreshold = 2; ViscosityInterpolator viscosity = new TwoStepViscosityInterpolator(stepThreshold); long duration = viscosity.calculateDuration(ANY_LONG, --stepThreshold); assertThat(duration).isEqualTo(ANY_LONG); }
@Test public void givenPlayerIsSeeking_whenGettingPlayheadPosition_thenReturnsSeekPosition() { long seekPositionInMillis = TEN_SECONDS; player.seekTo(seekPositionInMillis); long videoPositionInMillis = player.playheadPositionInMillis(); assertThat(videoPositionInMillis).isEqualTo(seekPositionInMillis); }
@Test public void testWhenViewCountIs2of10AndCurrentDuration100DurationEquals80() throws Exception { ViscosityInterpolator viscosity = new LinearChangeViscosityInterpolator(10); int viewCount = 2; long currentDuration = 100; long duration = viscosity.calculateDuration(currentDuration, viewCount); assertThat(duration).isEqualTo(80); }