public void testCount() { assertThat(emptyAccumulator.count()).isEqualTo(0); assertThat(emptyAccumulatorByAddAllEmptyPairedStats.count()).isEqualTo(0); assertThat(oneValueAccumulator.count()).isEqualTo(1); assertThat(oneValueAccumulatorByAddAllEmptyPairedStats.count()).isEqualTo(1); assertThat(twoValuesAccumulator.count()).isEqualTo(2); assertThat(twoValuesAccumulatorByAddAllPartitionedPairedStats.count()).isEqualTo(2); assertThat(manyValuesAccumulator.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllPartitionedPairedStats.count()) .isEqualTo(MANY_VALUES_COUNT); }
public void testCount() { assertThat(EMPTY_STATS_VARARGS.count()).isEqualTo(0); assertThat(EMPTY_STATS_ITERABLE.count()).isEqualTo(0); assertThat(ONE_VALUE_STATS.count()).isEqualTo(1); assertThat(TWO_VALUES_STATS.count()).isEqualTo(2); assertThat(MANY_VALUES_STATS_VARARGS.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERABLE.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERATOR.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_SNAPSHOT.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.count()).isEqualTo(INTEGER_MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.count()).isEqualTo(INTEGER_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.count()).isEqualTo(LONG_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.count()).isEqualTo(LONG_MANY_VALUES_COUNT); }
public void testComputeIfAbsentEviction() { // b/80241237 Cache<String, String> c = CacheBuilder.newBuilder().maximumSize(1).build(); assertThat(c.asMap().computeIfAbsent("hash-1", k -> "")).isEqualTo(""); assertThat(c.asMap().computeIfAbsent("hash-1", k -> "")).isEqualTo(""); assertThat(c.asMap().computeIfAbsent("hash-1", k -> "")).isEqualTo(""); assertThat(c.size()).isEqualTo(1); assertThat(c.asMap().computeIfAbsent("hash-2", k -> "")).isEqualTo(""); }
public void testCount() { assertThat(emptyAccumulator.count()).isEqualTo(0); assertThat(emptyAccumulatorByAddAllEmptyIterable.count()).isEqualTo(0); assertThat(emptyAccumulatorByAddAllEmptyStats.count()).isEqualTo(0); assertThat(oneValueAccumulator.count()).isEqualTo(1); assertThat(oneValueAccumulatorByAddAllEmptyStats.count()).isEqualTo(1); assertThat(twoValuesAccumulator.count()).isEqualTo(2); assertThat(twoValuesAccumulatorByAddAllStats.count()).isEqualTo(2); assertThat(manyValuesAccumulatorByAddAllIterable.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllIterator.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllVarargs.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByRepeatedAdd.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAndAddAll.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllStats.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(integerManyValuesAccumulatorByAddAllIterable.count()) .isEqualTo(StatsTesting.INTEGER_MANY_VALUES_COUNT); assertThat(longManyValuesAccumulatorByAddAllIterator.count()) .isEqualTo(StatsTesting.LONG_MANY_VALUES_COUNT); assertThat(longManyValuesAccumulatorByAddAllVarargs.count()) .isEqualTo(StatsTesting.LONG_MANY_VALUES_COUNT); }
public void testComputeEviction() { // b/80241237 Cache<String, String> c = CacheBuilder.newBuilder().maximumSize(1).build(); assertThat(c.asMap().compute("hash-1", (k, v) -> "a")).isEqualTo("a"); assertThat(c.asMap().compute("hash-1", (k, v) -> "b")).isEqualTo("b"); assertThat(c.asMap().compute("hash-1", (k, v) -> "c")).isEqualTo("c"); assertThat(c.size()).isEqualTo(1); assertThat(c.asMap().computeIfAbsent("hash-2", k -> "")).isEqualTo(""); }
/** Asserts that the cache is empty. */ public static void assertCacheEmpty(Cache cache) { assertThat(cache.getCacheSpace()).isEqualTo(0); assertThat(cache.getKeys()).isEmpty(); }
@Test public void standaloneResetPosition_getPositionShouldReturnSameValue() throws Exception { mediaClock.resetPosition(TEST_POSITION_US); assertThat(mediaClock.syncAndGetPositionUs()).isEqualTo(TEST_POSITION_US); }
private void assertClockIsStopped() { long positionAtStartUs = mediaClock.syncAndGetPositionUs(); fakeClock.advanceTime(SLEEP_TIME_MS); assertThat(mediaClock.syncAndGetPositionUs()).isEqualTo(positionAtStartUs); }
/** * If there's a bug in builder growth, we wouldn't know how to expose it. So, brute force the hell * out of it for a while and see what happens. */ public void testBuilder_bruteForce() { for (int i = 0; i < reduceIterationsIfGwt(100); i++) { ImmutableLongArray.Builder builder = ImmutableLongArray.builder(RANDOM.nextInt(20)); AtomicLong counter = new AtomicLong(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); op.doIt(builder, counter); } ImmutableLongArray iia = builder.build(); for (int j = 0; j < iia.length(); j++) { assertThat(iia.get(j)).isEqualTo((long) j); } } }
public void testForEach() { ImmutableLongArray.of().forEach(i -> fail()); ImmutableLongArray.of(0, 1, 3).subArray(1, 1).forEach(i -> fail()); AtomicLong count = new AtomicLong(0); ImmutableLongArray.of(0, 1, 2, 3) .forEach(i -> assertThat(i).isEqualTo(count.getAndIncrement())); assertEquals(4, count.get()); }
@Test public void testClippingToEndOfSourceWithUnsetDurationDoesNotSetDuration() throws IOException { // Create a child timeline that has an unknown duration. Timeline timeline = new SinglePeriodTimeline( /* durationUs= */ C.TIME_UNSET, /* isSeekable= */ true, /* isDynamic= */ false); // When clipping to the end, the clipped timeline should also have an unset duration. Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, C.TIME_END_OF_SOURCE); assertThat(clippedTimeline.getWindow(/* windowIndex= */ 0, window).getDurationUs()) .isEqualTo(C.TIME_UNSET); }
@Test public void put_withExistingItem_updatesSizeCorrectly() { PutWithExistingEntryHarness harness = new PutWithExistingEntryHarness(); harness.cache.put(harness.key, harness.first); harness.cache.put(harness.key, harness.second); assertThat(harness.cache.getCurrentSize()).isEqualTo(harness.second.getSize()); }
@Test public void enableRendererMediaClock_usesRendererClockPosition() throws ExoPlaybackException { MediaClockRenderer mediaClockRenderer = new MediaClockRenderer(); mediaClock.start(); mediaClock.onRendererEnabled(mediaClockRenderer); mediaClockRenderer.positionUs = TEST_POSITION_US; assertThat(mediaClock.syncAndGetPositionUs()).isEqualTo(TEST_POSITION_US); // We're not advancing the renderer media clock. Thus, the clock should appear to be stopped. assertClockIsStopped(); }
public void testEquivalentStreams() { // For datasets of many double values created from an array, we test many combinations of finite // and non-finite values: for (ManyValues values : ALL_MANY_VALUES) { double[] array = values.asArray(); Stats stats = Stats.of(array); // instance methods on Stats vs on instance methods on DoubleStream assertThat(stats.count()).isEqualTo(stream(array).count()); assertEquivalent(stats.mean(), stream(array).average().getAsDouble()); assertEquivalent(stats.sum(), stream(array).sum()); assertEquivalent(stats.max(), stream(array).max().getAsDouble()); assertEquivalent(stats.min(), stream(array).min().getAsDouble()); // static method on Stats vs on instance method on DoubleStream assertEquivalent(Stats.meanOf(array), stream(array).average().getAsDouble()); // instance methods on Stats vs instance methods on DoubleSummaryStatistics DoubleSummaryStatistics streamStats = stream(array).summaryStatistics(); assertThat(stats.count()).isEqualTo(streamStats.getCount()); assertEquivalent(stats.mean(), streamStats.getAverage()); assertEquivalent(stats.sum(), streamStats.getSum()); assertEquivalent(stats.max(), streamStats.getMax()); assertEquivalent(stats.min(), streamStats.getMin()); } }
public void testEqual() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path fooPath = fs.getPath("foo"); Path barPath = fs.getPath("bar"); MoreFiles.asCharSink(fooPath, UTF_8).write("foo"); MoreFiles.asCharSink(barPath, UTF_8).write("barbar"); assertThat(MoreFiles.equal(fooPath, barPath)).isFalse(); assertThat(MoreFiles.equal(fooPath, fooPath)).isTrue(); assertThat(MoreFiles.asByteSource(fooPath).contentEquals(MoreFiles.asByteSource(fooPath))) .isTrue(); Path fooCopy = Files.copy(fooPath, fs.getPath("fooCopy")); assertThat(Files.isSameFile(fooPath, fooCopy)).isFalse(); assertThat(MoreFiles.equal(fooPath, fooCopy)).isTrue(); MoreFiles.asCharSink(fooCopy, UTF_8).write("boo"); assertThat(MoreFiles.asByteSource(fooPath).size()) .isEqualTo(MoreFiles.asByteSource(fooCopy).size()); assertThat(MoreFiles.equal(fooPath, fooCopy)).isFalse(); // should also assert that a Path that erroneously reports a size 0 can still be compared, // not sure how to do that with the Path API } }
@Test public void testReadVarintExceedsMaximumAllowedLength() throws IOException, InterruptedException { VarintReader reader = new VarintReader(); ExtractorInput input = new FakeExtractorInput.Builder() .setData(DATA_8_BYTE_0) .setSimulateUnknownLength(true) .build(); long result = reader.readUnsignedVarint(input, false, true, 4); assertThat(result).isEqualTo(RESULT_MAX_LENGTH_EXCEEDED); }