from random import *
import os
from collections import Counter
import string

seed("typewriter")

d = Counter()
def testFactory(folder):
    try:
        print ("Creating directory:", folder)
        os.mkdir(folder)
    except:
        print ("Directory already exists")
    return lambda t : printTest(folder, t)

def printTest(folder, t):
    d[folder] += 1
    test = d[folder]
    print ("Creating test %s/%02d"%(folder, test))
    out = open(folder + "/%02d"%d[folder], 'w')
    print (len(t), file = out)
    for s in t:
        print (s, file = out)

def shuffled(a):
    shuffle(a)
    return a

def small():
    res = []
    res.append(["a"])
    res.append(["aa", "aa"])
    res.append(["aa", "aaaaa", "aa"])
    res.append(["aaaaa", "aa", "aaaaa"])
    res.append(["a" * randint(1, 10) for i in range(20000)])
    res.append(["a" * randint(1, 10000) for i in range(20)])
    res.append(["a" * 200000])
    res.append(["a" * i for i in range(1, 600)])
    res.append(shuffled(["a" * i for i in range(1, 600)]))
    res.append(["a"] * 200000)
    return res

def large():
    alpha = string.ascii_letters
    res = []
    res.append(["a", "b"])
    res.append(list(alpha) + ["aaaaaa", "aaaa", "aaaaaa"])
    randstr = lambda alpha, n : "".join(choice(alpha) for i in range(n))
    res.append([randstr(alpha[:2], 20) for i in range(10000)])
    common = randstr(alpha, 10)
    res.append([common + randstr(alpha, randint(1, 10)) for i in range(10000)])
    res.append(randstr(alpha, 200000))
    common = randstr(alpha, 10000)
    res.append([common + randstr(alpha, randint(1, 15000)) for i in range(8)] + 
            ["aaaaaa", "aaaaa", "aaaaaaaaaa" ])
    res.append([randstr(alpha[:i], i) for i in range(1, 600)])
    res.append([randstr(alpha, 2) for i in range(100000)])
    common = randstr(alpha, 9)
    res.append([common + randstr(alpha, 1) for i in range(20000)])
    res.append([common + randstr(alpha[:2], 11) for i in range(10000)])
    return res


prelim = testFactory("../preliminary")
prelim(["aaaa", "aaac", "CD"])

tests = testFactory("../tests")
for t in small():
    tests(t)
for t in large():
    tests(t)
