/** Asserts that the subject is {@link Double#NEGATIVE_INFINITY}. */ public final void isNegativeInfinity() { isEqualTo(Double.NEGATIVE_INFINITY); }
/** Asserts that the subject is {@link Double#POSITIVE_INFINITY}. */ public final void isPositiveInfinity() { isEqualTo(Double.POSITIVE_INFINITY); }
/** Asserts that the subject is {@link Double#NaN}. */ public final void isNaN() { isEqualTo(NaN); }
@Test public void returnsZeroWhenGettingDoubleFromNullColumn() { assertThat(singleColumnSingleNullValueMatrixCursor.getDouble(0)).isEqualTo(0.0); } }
@Test public void testGetDouble() throws Exception { assertThat(cursor.moveToFirst()).isTrue(); assertThat(cursor.getDouble(4)).isEqualTo(3.14159); }
@Test public void testDoubleExtra() throws Exception { Intent intent = new Intent(); assertSame(intent, intent.putExtra("foo", 2d)); assertEquals(2d, intent.getExtras().get("foo")); assertThat(intent.getDoubleExtra("foo", -1)).isEqualTo(2d); }
@Test public void testGetNumbersFromBlobField() throws Exception { database.execSQL("update table_name set name = '1.2'"); assertThat(cursor.moveToFirst()).isTrue(); assertThat(cursor.getInt(1)).isEqualTo(1); assertThat(cursor.getDouble(1)).isEqualTo(1.2d); assertThat(cursor.getFloat(1)).isEqualTo(1.2f); }
@Test public void testGetNumbersFromStringField() throws Exception { database.execSQL("update table_name set name = '1.2'"); assertThat(cursor.moveToFirst()).isTrue(); assertThat(cursor.getInt(1)).isEqualTo(1); assertThat(cursor.getDouble(1)).isEqualTo(1.2d); assertThat(cursor.getFloat(1)).isEqualTo(1.2f); }
/** * 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++) { ImmutableDoubleArray.Builder builder = ImmutableDoubleArray.builder(RANDOM.nextInt(20)); AtomicInteger counter = new AtomicInteger(0); while (counter.get() < 1000) { BuilderOp op = BuilderOp.randomOp(); op.doIt(builder, counter); } ImmutableDoubleArray iia = builder.build(); for (int j = 0; j < iia.length(); j++) { assertThat(iia.get(j)).isEqualTo((double) j); } } }
public void testForEach() { ImmutableDoubleArray.of().forEach(i -> fail()); ImmutableDoubleArray.of(0, 1, 3).subArray(1, 1).forEach(i -> fail()); AtomicInteger count = new AtomicInteger(0); ImmutableDoubleArray.of(0, 1, 2, 3) .forEach(i -> assertThat(i).isEqualTo((double) count.getAndIncrement())); assertEquals(4, count.get()); }
@Test public void testGetNullNumberValues() throws Exception { String sql = "UPDATE table_name set long_value=NULL, float_value=NULL, double_value=NULL"; database.execSQL(sql); assertThat(cursor.moveToFirst()).isTrue(); assertThat(cursor.getType(2)).isEqualTo(Cursor.FIELD_TYPE_NULL); assertThat(cursor.getLong(2)).isEqualTo(0); assertThat(cursor.getType(3)).isEqualTo(Cursor.FIELD_TYPE_NULL); assertThat(cursor.getFloat(3)).isEqualTo(0f); assertThat(cursor.getType(4)).isEqualTo(Cursor.FIELD_TYPE_NULL); assertThat(cursor.getDouble(4)).isEqualTo(0d); }
private void assertDataCursor1() throws Exception { assertThat(cursor.getInt(0)).isEqualTo(1234); assertThat(cursor.getString(1)).isEqualTo("Chuck"); assertThat(cursor.getInt(2)).isEqualTo(3463); assertThat(cursor.getFloat(3)).isEqualTo(1.5f); assertThat(cursor.getDouble(4)).isEqualTo(3.14159); cursor.moveToNext(); assertThat(cursor.getInt(0)).isEqualTo(1235); assertThat(cursor.getString(1)).isEqualTo("Julie"); cursor.moveToNext(); assertThat(cursor.getInt(0)).isEqualTo(1236); assertThat(cursor.getString(1)).isEqualTo("Chris"); }
private void assertDataCursor2() throws Exception { assertThat(cursor.getInt(0)).isEqualTo(4321); assertThat(cursor.getString(1)).isEqualTo("Mary"); assertThat(cursor.getInt(2)).isEqualTo(3245); assertThat(cursor.getFloat(3)).isEqualTo(5.4f); assertThat(cursor.getDouble(4)).isEqualTo(2.7818); cursor.moveToNext(); assertThat(cursor.getInt(0)).isEqualTo(4322); assertThat(cursor.getString(1)).isEqualTo("Elizabeth"); cursor.moveToNext(); assertThat(cursor.getInt(0)).isEqualTo(4323); assertThat(cursor.getString(1)).isEqualTo("Chester"); }
public void testSum() { assertThat(EMPTY_STATS_VARARGS.sum()).isEqualTo(0.0); assertThat(EMPTY_STATS_ITERABLE.sum()).isEqualTo(0.0); assertThat(ONE_VALUE_STATS.sum()).isWithin(ALLOWED_ERROR).of(ONE_VALUE); assertThat(TWO_VALUES_STATS.sum()).isWithin(ALLOWED_ERROR).of(TWO_VALUES_MEAN * 2); assertThat(MANY_VALUES_STATS_VARARGS.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERABLE.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERATOR.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_SNAPSHOT.sum()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_MEAN * MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.sum()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN * INTEGER_MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.sum()) .isWithin(ALLOWED_ERROR) .of(INTEGER_MANY_VALUES_MEAN * INTEGER_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.sum()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MEAN * LONG_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.sum()) .isWithin(ALLOWED_ERROR) .of(LONG_MANY_VALUES_MEAN * LONG_MANY_VALUES_COUNT); }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 200000, listener); Location location1 = new Location(GPS_PROVIDER); location1.setLatitude(1); location1.setLongitude(2); location1.setTime(0); Location location2 = new Location(GPS_PROVIDER); location2.setLatitude(1.5); location2.setLongitude(2.5); location2.setTime(1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getLatitude()).isEqualTo(1.0d); assertThat(listener.location.getLongitude()).isEqualTo(2.0d); }
@Test public void shouldAllowTypeFlexibility() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{42, 3.3, 'a'}); assertTrue(cursor.moveToFirst()); assertThat(cursor.getString(0)).isEqualTo("42"); assertThat(cursor.getShort(0)).isEqualTo((short) 42); assertThat(cursor.getInt(0)).isEqualTo(42); assertThat(cursor.getLong(0)).isEqualTo(42L); assertThat(cursor.getFloat(0)).isEqualTo(42.0F); assertThat(cursor.getDouble(0)).isEqualTo(42.0); assertThat(cursor.getString(1)).isEqualTo("3.3"); assertThat(cursor.getShort(1)).isEqualTo((short) 3); assertThat(cursor.getInt(1)).isEqualTo(3); assertThat(cursor.getLong(1)).isEqualTo(3L); assertThat(cursor.getFloat(1)).isEqualTo(3.3F); assertThat(cursor.getDouble(1)).isEqualTo(3.3); assertThat(cursor.getString(2)).isEqualTo("a"); }
@Test public void testZeroCanBeCasted_4ByteTypesCanBeReadAs8Bytes() { parcel.writeByte((byte) 0); parcel.writeByte((byte) 0); parcel.writeInt(0); parcel.writeInt(0); parcel.writeFloat(0.0f); parcel.writeByteArray(new byte[0]); assertThat(parcel.dataSize()).named("total size").isEqualTo(24); parcel.setDataPosition(0); assertThat(parcel.readLong()).isEqualTo(0L); assertWithMessage("long consumes 8B").that(parcel.dataPosition()).isEqualTo(8); assertThat(parcel.readDouble()).isEqualTo(0.0); assertWithMessage("double consumes 8B").that(parcel.dataPosition()).isEqualTo(16); assertThat(parcel.readString()).isEqualTo(""); assertWithMessage("empty string 8B").that(parcel.dataPosition()).isEqualTo(24); }
@Test public void get_shouldReturnColumnValue() throws Exception { cursor.setResults(new Object[][]{new Object[]{ "aString", 1234L, 42, new byte[]{1, 2, 3}, 255, 1.25f, 2.5d, null }}); assertThat(cursor.getCount()).isEqualTo(1); assertThat(cursor.moveToNext()).isTrue(); assertThat(cursor.getString(indexOf(STRING_COLUMN))).isEqualTo("aString"); assertThat(cursor.getLong(indexOf(LONG_COLUMN))).isEqualTo(1234L); assertThat(cursor.getInt(indexOf(INT_COLUMN))).isEqualTo(42); assertThat(cursor.getBlob(indexOf(BLOB_COLUMN))).asList().containsExactly((byte) 1, (byte) 2, (byte) 3); assertThat(cursor.getShort(indexOf(SHORT_COLUMN))).isEqualTo((short) 255); assertThat(cursor.getFloat(indexOf(FLOAT_COLUMN))).isEqualTo(1.25f); assertThat(cursor.getDouble(indexOf(DOUBLE_COLUMN))).isEqualTo(2.5d); assertThat(cursor.isNull(indexOf(NULL_COLUMN))).isTrue(); }