Skip to content

Commit

Permalink
Generative testing for CAD3 coded values
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 22, 2024
1 parent 2292512 commit eff4899
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
9 changes: 3 additions & 6 deletions convex-core/src/main/java/convex/core/cpos/Belief.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public class Belief extends ARecordGeneric {

// private final long timeStamp;

Belief(Index<AccountKey,SignedData<Order>> orders) {
private Belief(Index<AccountKey,SignedData<Order>> orders) {
super(CVMTag.BELIEF,BELIEF_FORMAT,Vectors.create(orders));
}

public Belief(AVector<ACell> newValues) {
private Belief(AVector<ACell> newValues) {
super(CVMTag.BELIEF,BELIEF_FORMAT,newValues);
}

Expand Down Expand Up @@ -273,13 +273,10 @@ public Belief proposeBlock(AKeyPair kp, SignedData<Block>... signedBlocks) {
return newBelief;
}

@SuppressWarnings("unchecked")
@Override
protected ARecordGeneric withValues(AVector<ACell> newValues) {
if (values==newValues) return this;
return new Belief((Index<AccountKey, SignedData<Order>>) newValues.get(0));
return new Belief(newValues);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Belief merge(Belief... beliefs) throws InvalidDataException {

// update my belief with the resulting Orders
if (initialBelief.getOrders() == resultOrders) return initialBelief;
final Belief result = new Belief(resultOrders);
final Belief result = Belief.create(resultOrders);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package convex.test.generators;

import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;

import convex.core.data.ACell;
import convex.core.data.CodedValue;
import convex.core.data.Tag;

/**
* Generator for CAD3 dense records
*
*/
public class CodedValueGen extends AGenerator<CodedValue> {
public CodedValueGen() {
super(CodedValue.class);
}

@Override
public CodedValue generate(SourceOfRandomness r, GenerationStatus status) {

byte type = (byte)(r.nextInt(16)+Tag.CODE_BASE);

ACell code=r.nextBoolean()?Gen.BYTE_FLAG.generate(r, status):Gen.VALUE.generate(r, status);
ACell value=Gen.VALUE.generate(r, status);

return CodedValue.create(type, code, value);
}
}
2 changes: 2 additions & 0 deletions convex-core/src/test/java/convex/test/generators/Gen.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public class Gen {
public static final OpGen OP = new OpGen();

public static final ExtensionValueGen EXTENSION_VALUE = new ExtensionValueGen();

public static final CodedValueGen CODED_VALUE = new CodedValueGen();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public ACell generate(SourceOfRandomness r, GenerationStatus status) {
return Gen.EXTENSION_VALUE.generate(r, status);
case 16:
return Gen.CHAR.generate(r, status);
case 17:
return Gen.CODED_VALUE.generate(r, status);

default:
return Gen.LONG.generate(r, status);
Expand Down

0 comments on commit eff4899

Please sign in to comment.