Select Git revision
      
  Fuzzer.java
        Forked from
        Toby Murray / swen90006-a2-2020 
 Source project has a limited visibility.
  Fuzzer.java  12.18 KiB 
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Random;
/* a stub for your team's fuzzer */
public class Fuzzer {
    // Blah - Test 1
    private static final String OUTPUT_FILE = "fuzz.txt";
    
    // The percentage of outputs that will start with a full stack
    private static final int STACK_FULL_PERCENTAGE = 10;
    // The percentage of inputs that will be incorrect
    private static final int INPUT_ERROR_PERCENTAGE = 5;
    // The percentage of instructions that will be incorrect
    private static final int LINE_ERROR_PERCENTAGE = 2;
    // Limit on generation of inputs
    private static final int NUMBER_TO_GENERATE = 10;
    // Instruction number range for each input
    private static final int INSTRUCTION_MIN = 0;
    private static final int INSTRUCTION_MAX = 500;
    // Maximum variable name length
    private static final int VAR_NAME_LENGTH_MAX = 100;
    private static final int VAR_ASCII_MIN = 33;
    private static final int VAR_ASCII_MAX = 127;
    // Variable range
    private static final int VAR_MIN = -2147483648;
    private static final int VAR_MAX = 2147483647;
    // Maximum number of items in stack
    private static final int MAX_STACK_SIZE = 512;
    // Random number generator
    private static Random rand = new Random(System.currentTimeMillis());
    private static ArrayList<String> vars = new ArrayList<>();
    public static void main(String[] args) throws IOException {
        System.out.println(Instruction.getBNF());
        FileOutputStream out = null;
        PrintWriter pw = null;
        try {
            out = new FileOutputStream(OUTPUT_FILE);
            pw = new PrintWriter(out);
            
            /* We just print one instruction.
               Hint: you might want to make use of the instruction
               grammar which is effectively encoded in Instruction.java */
            // pw.print(getStaticTests());
            pw.println(generateMultipleInputs());
            
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(1);
        }finally{
            if (pw != null){
                pw.flush();
            }
            if (out != null){
                out.close();
            }
        }
    }