RangeTestpublic class RangeTest extends TestCase
adb shell am instrument \
-e class 'com.android.mediaframeworktest.unit.RangeTest' \
-w com.android.mediaframeworktest/.MediaFrameworkUnitTestRunner
|
Methods Summary |
---|
private static void | assertAction(java.lang.String action, T object, T2 needle, boolean expected, boolean actual)
String expectedMessage = expected ? action : ("not " + action);
assertEquals("Expected " + needle + " to be " + expectedMessage + " of " + object,
expected, actual);
| private static void | assertAction(java.lang.String action, T object, T2 expected, T2 actual)
assertEquals("Expected " + object + " " + action + " to be ",
expected, actual);
| private static void | assertHashCodeEquals(android.util.Range left, android.util.Range right)
assertEquals("Left hash code for " + left +
" expected to be equal to right hash code for " + right,
left.hashCode(), right.hashCode());
| private static void | assertInRange(android.util.Range object, T needle)
assertAction("in-range", object, needle, true, object.contains(needle));
| private static void | assertLower(android.util.Range object, T expected)
assertAction("lower", object, expected, object.getLower());
| private static void | assertOutOfRange(android.util.Range object, T needle)
assertAction("out-of-range", object, needle, false, object.contains(needle));
| private static void | assertUpper(android.util.Range object, T expected)
assertAction("upper", object, expected, object.getUpper());
| public void | testConstructor()
// Trivial, same range
Range<Integer> intRange = new Range<Integer>(1, 1);
assertLower(intRange, 1);
assertUpper(intRange, 1);
// Different values in range
Range<Integer> intRange2 = new Range<Integer>(100, 200);
assertLower(intRange2, 100);
assertUpper(intRange2, 200);
Range<Float> floatRange = new Range<Float>(Float.NEGATIVE_INFINITY,
Float.POSITIVE_INFINITY);
assertLower(floatRange, Float.NEGATIVE_INFINITY);
assertUpper(floatRange, Float.POSITIVE_INFINITY);
| public void | testEquals()
Range<Float> oneHalf = Range.create(1.0f, 2.0f);
Range<Float> oneHalf2 = new Range<Float>(1.0f, 2.0f);
assertEquals(oneHalf, oneHalf2);
assertHashCodeEquals(oneHalf, oneHalf2);
Range<Float> twoThirds = new Range<Float>(2.0f, 3.0f);
Range<Float> twoThirds2 = Range.create(2.0f, 3.0f);
assertEquals(twoThirds, twoThirds2);
assertHashCodeEquals(twoThirds, twoThirds2);
Range<Rational> negativeOneTenthPositiveOneTenth =
new Range<Rational>(new Rational(-1, 10), new Rational(1, 10));
Range<Rational> negativeOneTenthPositiveOneTenth2 =
Range.create(new Rational(-1, 10), new Rational(1, 10));
assertEquals(negativeOneTenthPositiveOneTenth, negativeOneTenthPositiveOneTenth2);
assertHashCodeEquals(negativeOneTenthPositiveOneTenth, negativeOneTenthPositiveOneTenth2);
| public void | testIllegalValues()
// Test NPEs
try {
new Range<Integer>(null, null);
fail("Expected exception to be thrown for (null, null)");
} catch (NullPointerException e) {
// OK: both args are null
}
try {
new Range<Integer>(null, 0);
fail("Expected exception to be thrown for (null, 0)");
} catch (NullPointerException e) {
// OK: left arg is null
}
try {
new Range<Integer>(0, null);
fail("Expected exception to be thrown for (0, null)");
} catch (NullPointerException e) {
// OK: right arg is null
}
// Test IAEs
try {
new Range<Integer>(50, -50);
fail("Expected exception to be thrown for (50, -50)");
} catch (IllegalArgumentException e) {
// OK: 50 > -50 so it fails
}
try {
new Range<Float>(0.0f, Float.NEGATIVE_INFINITY);
fail("Expected exception to be thrown for (0.0f, -Infinity)");
} catch (IllegalArgumentException e) {
// OK: 0.0f is > NEGATIVE_INFINITY, so it fails
}
| public void | testInRange()
Range<Integer> hundredOneTwo = Range.create(100, 200);
assertInRange(hundredOneTwo, 100);
assertInRange(hundredOneTwo, 200);
assertInRange(hundredOneTwo, 150);
assertOutOfRange(hundredOneTwo, 99);
assertOutOfRange(hundredOneTwo, 201);
assertOutOfRange(hundredOneTwo, 100000);
Range<Float> infinities = Range.create(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
assertInRange(infinities, Float.NEGATIVE_INFINITY);
assertInRange(infinities, Float.POSITIVE_INFINITY);
assertInRange(infinities, 0.0f);
assertOutOfRange(infinities, Float.NaN);
Range<Rational> negativeOneTenthPositiveOneTenth =
new Range<Rational>(new Rational(-1, 10), new Rational(1, 10));
assertInRange(negativeOneTenthPositiveOneTenth, new Rational(-1, 10));
assertInRange(negativeOneTenthPositiveOneTenth, new Rational(1, 10));
assertInRange(negativeOneTenthPositiveOneTenth, Rational.ZERO);
assertOutOfRange(negativeOneTenthPositiveOneTenth, new Rational(-100, 1));
assertOutOfRange(negativeOneTenthPositiveOneTenth, new Rational(100, 1));
|
|