diff --git a/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java b/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java index d416134f3..e99fa1dd5 100644 --- a/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java +++ b/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java @@ -97,14 +97,22 @@ public void testMaxSize() { bs[0]=-128; // set sign bit for max sized negative number ABlob blob=Blob.wrap(bs); CVMBigInteger b=CVMBigInteger.create(blob); + + assertEquals(b,Samples.MIN_BIGINT); + assertTrue(b.isCanonical()); assertEquals(Constants.MAX_BIG_INTEGER_LENGTH,b.blob().count()); + assertNull(b.negate()); assertNull(b.dec()); // overflow assertNull(b.multiply(CVMLong.create(2))); // overflow - assertNotNull(b.inc().negate()); + + // Negate to get maximum possible bigint + CVMBigInteger bn=(CVMBigInteger) b.inc().negate(); + assertNotNull(bn); doBigTest(b); + doBigTest(bn); } @Test @@ -163,7 +171,10 @@ public static void doBigTest(CVMBigInteger bi) { assertEquals(bi.getEncoding(),bi2.getEncoding()); assertEquals(bi,bi2); - assertEquals(bi,bi.inc().dec()); + AInteger biplus=bi.inc(); + if (biplus!=null) { + assertEquals(bi,biplus.dec()); + } if (bi.isCanonical()) { assertTrue(bi.byteLength()>8); diff --git a/convex-core/src/test/java/convex/core/lang/CoreTest.java b/convex-core/src/test/java/convex/core/lang/CoreTest.java index c1008ed87..8a07230c1 100644 --- a/convex-core/src/test/java/convex/core/lang/CoreTest.java +++ b/convex-core/src/test/java/convex/core/lang/CoreTest.java @@ -3295,7 +3295,12 @@ public void testQuot() { @Test public void testDiv() { assertEquals(0L, evalL("(div 4 10)")); + assertEquals(0L, evalL("(div 0 -1)")); assertEquals(-4L, evalL("(div -10 3)")); + + assertArgumentError(step("(div 3 0)")); + assertArgumentError(step("(div 0 0)")); + assertArgumentError(step("(div -1567567567567564756767586786785688 0)")); // TODO: more tests } diff --git a/convex-core/src/test/java/convex/test/Samples.java b/convex-core/src/test/java/convex/test/Samples.java index a09925d93..70eb7d27c 100644 --- a/convex-core/src/test/java/convex/test/Samples.java +++ b/convex-core/src/test/java/convex/test/Samples.java @@ -10,6 +10,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; +import convex.core.Constants; import convex.core.crypto.AKeyPair; import convex.core.crypto.ASignature; import convex.core.crypto.Ed25519Signature; @@ -47,6 +48,7 @@ import convex.core.data.VectorLeaf; import convex.core.data.VectorTree; import convex.core.data.Vectors; +import convex.core.data.prim.CVMBigInteger; import convex.core.data.prim.CVMBool; import convex.core.data.prim.CVMChar; import convex.core.data.prim.CVMDouble; @@ -156,12 +158,24 @@ public class Samples { public static final Blob SMALL_BLOB = Blob.fromHex("cafebabe"); + public static final CVMBigInteger MAX_BIGINT; + public static final CVMBigInteger MIN_BIGINT; + static { // we should be able to actually build these, thanks to structural sharing. DIABOLICAL_VECTOR_30_30 = createNastyNestedVector(30, 30); DIABOLICAL_VECTOR_2_10000 = createNastyNestedVector(2, 10000); DIABOLICAL_MAP_30_30 = createNastyNestedMap(30, 30); DIABOLICAL_MAP_2_10000 = createNastyNestedMap(2, 10000); + + { + byte [] bs=new byte[Constants.MAX_BIG_INTEGER_LENGTH]; + bs[0]=-128; // set sign bit for max sized negative number + ABlob blob=Blob.wrap(bs); + CVMBigInteger b=CVMBigInteger.create(blob); + MIN_BIGINT=b; + MAX_BIGINT=(CVMBigInteger) b.inc().negate(); + } } /**