QuickCheck class
class QuickCheck extends Check { static const MAX_INT = ((1 << 32) - 1); final int seed; final int maxSize; QuickCheck({seed: 0, maxSuccesses: 100, maxSize: 100, quiet: false}) : this.seed = seed , this.maxSize = maxSize , super(quiet); void check(Property property) { final random = new Random(seed); final nonEmptyParts = <Pair<int,Finite>>[]; int counter = 0; final iterator = property.enumeration.parts.iterator; while (counter <= maxSize && iterator.moveNext()) { final part = iterator.current; if (part.length > 0) { nonEmptyParts.add(new Pair(counter, part)); } counter++; } int numParts = nonEmptyParts.length; for (int i = 0; i < numParts; i++) { final pair = nonEmptyParts[i]; final size = pair.fst; final part = pair.snd; display("${i+1}/$numParts (size $size)"); // TODO: replace by randInt when it handles bigints int maxIndex = part.length - 1; int index; if (maxIndex == 0) { index = 0; } else if (maxIndex < MAX_INT) { index = random.nextInt(maxIndex); } else { // poor resolution, would need real bigint rng int numerator = random.nextInt(MAX_INT); index = ((part.length-1) * numerator) ~/ MAX_INT; } _Product arg = part[index]; if (!property.property(arg)) { clear(); throw Check._errorMessage(i + 1, arg); } } clear(); } }
Extends
Check > QuickCheck
Static Properties
const MAX_INT #
static const MAX_INT = ((1 << 32) - 1)
Constructors
new QuickCheck({seed: 0, maxSuccesses: 100, maxSize: 100, quiet: false}) #
Creates a new Object instance.
Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.
docs inherited from Object
QuickCheck({seed: 0, maxSuccesses: 100, maxSize: 100, quiet: false}) : this.seed = seed , this.maxSize = maxSize , super(quiet);
Properties
Methods
void check(Property property) #
void check(Property property) { final random = new Random(seed); final nonEmptyParts = <Pair<int,Finite>>[]; int counter = 0; final iterator = property.enumeration.parts.iterator; while (counter <= maxSize && iterator.moveNext()) { final part = iterator.current; if (part.length > 0) { nonEmptyParts.add(new Pair(counter, part)); } counter++; } int numParts = nonEmptyParts.length; for (int i = 0; i < numParts; i++) { final pair = nonEmptyParts[i]; final size = pair.fst; final part = pair.snd; display("${i+1}/$numParts (size $size)"); // TODO: replace by randInt when it handles bigints int maxIndex = part.length - 1; int index; if (maxIndex == 0) { index = 0; } else if (maxIndex < MAX_INT) { index = random.nextInt(maxIndex); } else { // poor resolution, would need real bigint rng int numerator = random.nextInt(MAX_INT); index = ((part.length-1) * numerator) ~/ MAX_INT; } _Product arg = part[index]; if (!property.property(arg)) { clear(); throw Check._errorMessage(i + 1, arg); } } clear(); }