Skip to content

Commit

Permalink
Better test for Address equality
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 1, 2024
1 parent d78c629 commit fb30352
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
15 changes: 6 additions & 9 deletions convex-core/src/main/java/convex/core/cvm/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import convex.core.data.AExtensionValue;
import convex.core.data.AString;
import convex.core.data.Blob;
import convex.core.data.Cells;
import convex.core.data.Format;
import convex.core.data.Strings;
import convex.core.data.prim.CVMLong;
Expand Down Expand Up @@ -94,18 +95,14 @@ public AType getType() {
return Types.ADDRESS;
}

@Override
public boolean equals(Object a) {
if (a==this) return true; // Fast path, avoids cast
if (!(a instanceof Address)) return false; // Handles null
return equals((Address)a);
}

@Override
public boolean equals(ACell o) {
if (o==this) return true;
if (!(o instanceof Address)) return false;
return value==((Address) o).value;
if (o instanceof Address) {
return value==((Address) o).value;
} else {
return Cells.equalsGeneric(this, o);
}
}

public final boolean equals(Address o) {
Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/data/ACell.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public int hashCode() {
}

@Override
public boolean equals(Object a) {
public final boolean equals(Object a) {
if (a==this) return true; // Fast path, avoids cast
if (!(a instanceof ACell)) return false; // Handles null
return equals((ACell)a);
Expand Down
7 changes: 7 additions & 0 deletions convex-core/src/test/java/convex/core/data/CAD3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public class CAD3Test extends ACVMTest {
assertSame(Core.VECTOR,Reader.read("#["+Utils.toHexString(CVMTag.CORE_DEF)+"01]"));
}

@Test public void testAddressExtension() {
Address a=Address.create(127);
ExtensionValue e=ExtensionValue.create((byte) CVMTag.ADDRESS, 127);
assertEquals(a,e);
assertEquals(e,a);
}

@Test public void testReadEncodings() {
assertSame(Address.ZERO,Reader.read("#[EA00]"));
assertSame(CVMLong.ZERO,Reader.read("#[10]"));
Expand Down

0 comments on commit fb30352

Please sign in to comment.