SparseRectFArrayTestpublic class SparseRectFArrayTest extends android.test.InstrumentationTestCase
Fields Summary |
---|
private static final android.graphics.RectF[] | MANY_RECTS |
Methods Summary |
---|
private static void | assertEqualRects(android.view.inputmethod.SparseRectFArray a, android.view.inputmethod.SparseRectFArray b)
assertEquals(a, b);
if (a != null && b != null) {
assertEquals(a.hashCode(), b.hashCode());
}
| private static void | assertNotEqualRects(android.view.inputmethod.SparseRectFArray a, android.view.inputmethod.SparseRectFArray b)
assertFalse(Objects.equals(a, b));
| private static android.view.inputmethod.SparseRectFArray | cloneViaParcel(android.view.inputmethod.SparseRectFArray src)
Parcel parcel = null;
try {
parcel = Parcel.obtain();
src.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
return new SparseRectFArray(parcel);
} finally {
if (parcel != null) {
parcel.recycle();
}
}
| public void | testBuilder()
final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
final int TEMP_FLAGS = 0x1234;
final SparseRectFArrayBuilder builder = new SparseRectFArrayBuilder();
builder.append(100, TEMP_RECT.left, TEMP_RECT.top, TEMP_RECT.right, TEMP_RECT.bottom,
TEMP_FLAGS);
assertNull(builder.build().get(-1));
assertNull(builder.build().get(0));
assertNull(builder.build().get(99));
assertEquals(0, builder.build().getFlags(99, 0 /* valueIfKeyNotFound */));
assertEquals(1, builder.build().getFlags(99, 1 /* valueIfKeyNotFound */));
assertEquals(TEMP_RECT, builder.build().get(100));
assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 0 /* valueIfKeyNotFound */));
assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 1 /* valueIfKeyNotFound */));
assertNull(builder.build().get(101));
assertEquals(0, builder.build().getFlags(101, 0 /* valueIfKeyNotFound */));
assertEquals(1, builder.build().getFlags(101, 1 /* valueIfKeyNotFound */));
// Test if {@link SparseRectFArrayBuilder#reset} resets its internal state.
builder.reset();
assertNull(builder.build().get(100));
builder.reset();
for (int i = 0; i < MANY_RECTS.length; i++) {
final RectF rect = MANY_RECTS[i];
if (rect != null) {
builder.append(i, rect.left, rect.top, rect.right, rect.bottom, i);
}
}
final SparseRectFArray array = builder.build();
for (int i = 0; i < MANY_RECTS.length; i++) {
final RectF expectedRect = MANY_RECTS[i];
assertEquals(expectedRect, array.get(i));
if (expectedRect != null) {
assertEquals(i, array.getFlags(i, 0x1234 /* valueIfKeyNotFound */));
assertEquals(i, array.getFlags(i, 0x4321 /* valueIfKeyNotFound */));
} else {
assertEquals(0x1234, array.getFlags(i, 0x1234 /* valueIfKeyNotFound */));
assertEquals(0x4321, array.getFlags(i, 0x4321 /* valueIfKeyNotFound */));
}
}
// Make sure the builder reproduces an equivalent object.
final SparseRectFArray array2 = builder.build();
for (int i = 0; i < MANY_RECTS.length; i++) {
final RectF expectedRect = MANY_RECTS[i];
assertEquals(expectedRect, array2.get(i));
if (expectedRect != null) {
assertEquals(i, array2.getFlags(i, 0x1234 /* valueIfKeyNotFound */));
assertEquals(i, array2.getFlags(i, 0x4321 /* valueIfKeyNotFound */));
} else {
assertEquals(0x1234, array2.getFlags(i, 0x1234 /* valueIfKeyNotFound */));
assertEquals(0x4321, array2.getFlags(i, 0x4321 /* valueIfKeyNotFound */));
}
}
assertEqualRects(array, array2);
// Make sure the instance can be marshaled via {@link Parcel}.
final SparseRectFArray array3 = cloneViaParcel(array);
for (int i = 0; i < MANY_RECTS.length; i++) {
final RectF expectedRect = MANY_RECTS[i];
assertEquals(expectedRect, array3.get(i));
if (expectedRect != null) {
assertEquals(i, array3.getFlags(i, 0x1234 /* valueIfKeyNotFound */));
assertEquals(i, array3.getFlags(i, 0x4321 /* valueIfKeyNotFound */));
} else {
assertEquals(0x1234, array3.getFlags(i, 0x1234 /* valueIfKeyNotFound */));
assertEquals(0x4321, array3.getFlags(i, 0x4321 /* valueIfKeyNotFound */));
}
}
assertEqualRects(array, array3);
// Make sure the builder can be reset.
builder.reset();
assertNull(builder.build().get(0));
| public void | testBuilderAppend()
// Key should be appended in ascending order.
try {
new SparseRectFArrayBuilder()
.append(10, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.append(0, 1.0f, 2.0f, 3.0f, 4.0f, 0);
} catch (IllegalArgumentException ex) {
assertTrue(true);
}
try {
new SparseRectFArrayBuilder()
.append(10, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.append(10, 1.0f, 2.0f, 3.0f, 4.0f, 0);
} catch (IllegalArgumentException ex) {
assertTrue(true);
}
| public void | testEquality()
// Empty array should be equal.
assertEqualRects(new SparseRectFArrayBuilder().build(),
new SparseRectFArrayBuilder().build());
assertEqualRects(
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build(),
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build());
assertEqualRects(
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build(),
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build());
assertNotEqualRects(
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build(),
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build());
assertNotEqualRects(
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build(),
new SparseRectFArrayBuilder().append(100, 2.0f, 2.0f, 3.0f, 4.0f, 1).build());
assertNotEqualRects(
new SparseRectFArrayBuilder().append(100, 1.0f, 2.0f, 3.0f, 4.0f, 1).build(),
new SparseRectFArrayBuilder().append(101, 1.0f, 2.0f, 3.0f, 4.0f, 1).build());
assertEqualRects(
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(),
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build(),
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(),
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0).build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(),
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 1.0f, 0.0f, 0.0f, 0.0f, 0).build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 1.0f, 0.0f, 0.0f, 0.0f, 0).build(),
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(101, 0.0f, 0.0f, 0.0f, 0.0f, 0).build(),
new SparseRectFArrayBuilder()
.append(100, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(102, 0.0f, 0.0f, 0.0f, 0.0f, 0).build());
assertEqualRects(
new SparseRectFArrayBuilder()
.append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.build(),
new SparseRectFArrayBuilder()
.append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.build(),
new SparseRectFArrayBuilder()
.append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.build());
assertNotEqualRects(
new SparseRectFArrayBuilder()
.append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(1000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.build(),
new SparseRectFArrayBuilder()
.append(1, 1.0f, 2.0f, 3.0f, 4.0f, 0)
.append(1000, 1.0f, 0.0f, 0.0f, 0.0f, 0)
.append(100000000, 0.0f, 0.0f, 0.0f, 0.0f, 0)
.build());
|
|