@Test public void testUnaryFunctions() { for (int i = 0; i < this.iterations; i++) { ArbitraryInteger proband = ArbitraryInteger.valueOf(this.randomizer.nextInt()); assertTrue(proband.signum() * -1 == proband.negate().signum()); BigInteger t = proband.toNumber(); assertEquals(t.pow(2), proband.square().toNumber()); assertTrue( proband.isNegativ() && proband.abs().isPositiv() || proband.isPositiv() && proband.abs().isPositiv()); if (!proband.isZero()) { ArbitraryRational ratProband = proband.reciprocal(); if (proband.isPositiv()) { assertTrue(ArbitraryInteger.ONE == ratProband.numerator()); assertTrue(proband == ratProband.denominator()); } else { assertTrue(ArbitraryInteger.MINUS_ONE == ratProband.numerator()); assertEquals(proband.negate().toNumber(), ratProband.denominator().toNumber()); } } assertEquals(proband.toNumber().add(BigInteger.ONE), proband.increment().toNumber()); assertEquals(proband.toNumber().subtract(BigInteger.ONE), proband.decrement().toNumber()); } try { ArbitraryRational ratProband = ArbitraryInteger.ZERO.reciprocal(); fail("Reciprocal of zero should yield an ArithmeticException"); } catch (ArithmeticException e) { // thats good } assertTrue(ArbitraryInteger.ONE == ArbitraryInteger.ZERO.increment()); assertTrue(ArbitraryInteger.TWO == ArbitraryInteger.ONE.increment()); assertTrue(ArbitraryInteger.MINUS_ONE == ArbitraryInteger.ZERO.decrement()); assertTrue(ArbitraryInteger.ONE == ArbitraryInteger.TWO.decrement()); }