publicclass CompareToTests { privatestaticint compareToTests() { int failures = 0;
final BigInteger MINUS_ONE = BigInteger.ONE.negate(); final BigInteger TWO_POW_126 = ONE.shiftLeft(126); final BigInteger TWO_POW_127 = ONE.shiftLeft(127); final BigInteger TWO_POW_128 = ONE.shiftLeft(128);
// First operand, second operand, expected compareTo result
BigInteger [][] testCases = { // Basics
{valueOf(0), valueOf(0), ZERO},
{valueOf(0), valueOf(1), MINUS_ONE},
{valueOf(1), valueOf(2), MINUS_ONE},
{valueOf(2), valueOf(1), ONE},
{valueOf(10), valueOf(10), ZERO},
// Various relative lengths of internal mag array.
{TWO_POW_127, TWO_POW_127, ZERO},
{TWO_POW_127.negate(), TWO_POW_127, MINUS_ONE},
// Long boundary and near boundary values
{valueOf(Long.MAX_VALUE), valueOf(Long.MAX_VALUE), ZERO},
{valueOf(Long.MAX_VALUE).negate(), valueOf(Long.MAX_VALUE), MINUS_ONE},
privatestaticint compareToTest(BigInteger a, BigInteger b, int expected) { int result = a.compareTo(b); int failed = (result==expected) ? 0 : 1; if (failed == 1) {
System.err.println("(" + a + ").compareTo(" + b + ") => " + result + "\n\tExpected " + expected);
} return failed;
}
publicstaticvoid main(String argv[]) { int failures = 0;
failures += compareToTests();
if (failures > 0) { thrownew RuntimeException("Incurred " + failures + " failures while testing exact compareTo.");
}
}
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.25Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.