Skip to content

Commit 122bdfb

Browse files
committed
Test updates
1 parent fd53626 commit 122bdfb

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

convex-core/src/test/java/convex/core/data/BlobsTest.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import java.io.IOException;
1313
import java.nio.ByteBuffer;
14-
import java.util.Arrays;
1514
import java.util.Random;
1615

1716
import org.junit.jupiter.api.Test;
@@ -31,7 +30,7 @@
3130

3231
public class BlobsTest {
3332
@Test public void testConstants() {
34-
assertEquals(4096,Blob.CHUNK_LENGTH);
33+
assertEquals(4096,Blob.CHUNK_LENGTH); // verify expected constant value of 4k
3534
assertEquals(Blob.CHUNK_LENGTH,1<<Blobs.CHUNK_SHIFT);
3635
}
3736

@@ -340,6 +339,20 @@ public void testBlobSlice() {
340339
doBlobTests(blob);
341340
}
342341

342+
@Test
343+
public void testSliceInvalidRanges() {
344+
Blob b = Blob.fromHex("0123456789");
345+
346+
// start > end
347+
assertNull(b.slice(3, 2));
348+
349+
// negative length implicitly
350+
assertNull(b.slice(5, 4));
351+
352+
// valid edge case
353+
assertEquals(Blob.EMPTY, b.slice(3, 3));
354+
}
355+
343356
@Test
344357
public void testBlobAppendSmall() {
345358
ABlob src = Blob.fromHex("cafebabedeadbeef");
@@ -433,29 +446,42 @@ public void testBlobTreeDepthLimits() {
433446
assertEquals(1000, result.count());
434447
}
435448

449+
@Test
450+
public void testInstanceReuseOptimizations() {
451+
Blob b = Blob.fromHex("0123456789abcdef");
452+
453+
// Full slice should return same instance
454+
assertSame(b, b.slice(0));
455+
assertSame(b, b.slice(0, b.count()));
456+
457+
// Empty slices should return empty singleton
458+
assertSame(Blob.EMPTY, b.slice(5, 5));
459+
assertSame(Blob.EMPTY, b.slice(b.count()));
460+
461+
462+
}
463+
436464
@Test
437465
public void testCompareConsistency() {
438466
// Ensure compareTo is consistent with equals
439-
java.util.List<Blob> blobs = Arrays.asList(
467+
Blob[] blobs = new Blob[] {
440468
Blob.EMPTY,
441469
Blob.fromHex("00"),
442470
Blob.fromHex("01"),
443471
Blob.fromHex("FF"),
444472
Blob.fromHex("0000"),
445473
Blob.fromHex("0001"),
446474
Blob.fromHex("FFFF")
447-
);
475+
};
448476

449477
for (Blob b1 : blobs) {
450478
for (Blob b2 : blobs) {
451479
// If equal, compareTo should return 0
452-
if (b1.equals(b2)) {
453-
assertEquals(0, b1.compareTo(b2));
454-
}
455480

456481
// compareTo should be antisymmetric
457482
assertEquals(-Integer.signum(b1.compareTo(b2)), Integer.signum(b2.compareTo(b1)));
458483
}
484+
doBlobTests(b1);
459485
}
460486
}
461487

convex-core/src/test/java/convex/core/util/EconomicsTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import org.junit.jupiter.api.Test;
1111

12-
import convex.core.util.Economics;
13-
1412
public class EconomicsTest {
1513

1614
@Test

convex-core/src/test/java/convex/core/util/GenTestEconomics.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
import com.pholser.junit.quickcheck.Property;
1111
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
1212

13-
import convex.core.util.Economics;
14-
import convex.core.util.Utils;
15-
1613
@RunWith(JUnitQuickcheck.class)
1714
public class GenTestEconomics {
1815

0 commit comments

Comments
 (0)