All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.berkeley.cs.jqf.examples.trees.RedBlackBSTGenerator Maven / Gradle / Ivy

Go to download

JQF: Feedback-directed Quickcheck for Java - Sample generators and benchmark tests

There is a newer version: 2.0
Show newest version
package edu.berkeley.cs.jqf.examples.trees;

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

import static com.pholser.junit.quickcheck.internal.Reflection.defaultValueOf;

/**
 * Created by clemieux on 9/18/17.
 */
public class RedBlackBSTGenerator extends Generator {
    private int min = (Integer) defaultValueOf(InRange.class, "minInt");
    private int max = (Integer) defaultValueOf(InRange.class, "maxInt");

    private static final GenerationStatus.Key SUBTREE_SIZE = new GenerationStatus.Key<>("treesize", Integer.class);

    public RedBlackBSTGenerator() {
        super(RedBlackBST.class);
    }

    /**
     * Tells this generator to produce values within a specified minimum and/or
     * maximum, inclusive, with uniform distribution.
     *
     * {@link InRange#min} and {@link InRange#max} take precedence over
     * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty.
     *
     * @param range annotation that gives the range's constraints
     */
    public void configure(InRange range) {
        min = range.min().isEmpty() ? range.minInt() : Integer.parseInt(range.min());
        max = range.max().isEmpty() ? range.maxInt() : Integer.parseInt(range.max());
    }

    @Override
    public RedBlackBST generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
        Integer size = sourceOfRandomness.nextInt(min,max);
       // System.out.println("size: " + size.toString());
        generationStatus.setValue(SUBTREE_SIZE, size);
        RedBlackBSTNodeGenerator generator = new RedBlackBSTNodeGenerator();
        return new RedBlackBST<>(generator.generate(sourceOfRandomness, generationStatus));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy