/**
 * Created by Grigorii Shovkoplias on 1.12.2015.
 */

import java.io.*;
import java.util.*;

public class TestGen {

    private void gen() throws Exception {
        new File("../tests").mkdir();
        done = 0;
        genSamples();
        genSimples();
        genEven(10);
        genOdd(7);
        genSame(8);
        genRand(13);

        int testLimits[] = new int[]{100, 500, MAXN / 10, MAXN / 5, MAXN};
        for (int i = 0; i < testLimits.length; i++) {
            genEven(gand(testLimits[i]));
            genSame(gand(testLimits[i]));
            genRand(gand(testLimits[i]));
            genRand(rand(testLimits[i]) + 1);
        }

        genEven(MAXN);
        genOdd(26);
        genSame(MAXN);
        genRand(MAXN);
        genRand(MAXN);

    }

    public static void main(String[] args) throws Exception {
        new TestGen().gen();
    }

    private int done = 0;
    private final Random rnd = new Random(3289214075201L);
    private final int MAXN = 100_000;

    private int rand(int n) {
        if (n < 1)
            return 0;
        return rnd.nextInt(n);
    }

    private int gand(int n) {
        return rand(n / 2) + n / 2 + 1;
    }

    private char randChar() {
        return (char) (rand(26) + 'a');
    }

    private String randString(int n) {
        char c[] = new char[n];
        for (int i = 0; i < n; i++) {
            c[i] = randChar();
        }
        return String.valueOf(c);
    }

    private char zeroOrOne() {
        return (char) ('0' + rnd.nextInt(2));
    }

    private long rand(long n) {
        if (n < 1)
            return 0;
        long res = rand(Integer.MAX_VALUE);
        res <<= 32;
        res += rand(Integer.MAX_VALUE);
        res %= n;
        return res;
    }

    private void print(String test) throws IOException {
        done++;
        System.err.println("Generation test #" + done);
        PrintWriter out = new PrintWriter(String.format("../tests/%02d", done));
        out.println(test);
        out.close();
    }

    private void shuffle(char[] a) {
        for (int i = 0; i < a.length; i++) {
            int j = rand(i + 1);
            char t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }

    //begin generators

    private void genSamples() throws IOException {
        print("abc");
        print("aba");
    }

    private void genSimples() throws IOException {
        print("abacaba");
        print("a");
        print("aa");
    }

    private void genRand(int n) throws IOException {
        print(randString(n));
    }

    private void genOdd(int n) throws IOException {
        n = Math.min(26, n);
        char c[] = new char[n];
        for (int i = 0; i < n; i++) {
            c[i] = (char) (i + 'a');
        }
        shuffle(c);
        print(String.valueOf(c));
    }

    private void genSame(int n) throws IOException {
        char ch = randChar();
        char c[] = new char[n];
        for (int i = 0; i < n; i++) {
            c[i] = ch;
        }
        print(String.valueOf(c));
    }

    private void genEven(int n) throws IOException {
        n = (n / 2) * 2;
        char c[] = new char[n];
        for (int i = 0; i < n; i += 2) {
            c[i] = (char) randChar();
            c[i + 1] = c[i];
        }
        shuffle(c);
        print(String.valueOf(c));
    }

    //end generators

}
