from random import *
from os import path, mkdir
import string

seed('names')

tests_dir = '../tests'
test = 0

MAXN = 1000
MAXW = 20

alpha = string.ascii_letters

randWord = lambda m = MAXW: "".join(choice(alpha) for i in range(m))

randTest = lambda n, w = MAXW: [[randWord(w), randWord(w), randWord(w)] for _ in range(n)]

def equalizeNamesPairs(test):
    for i in range(0, len(test), 2):
        test[i][1] = test[i + 1][1]
    test[-1][1] = test[-2][1]
    return test

# FIO -> IOF
petyaToVasya = lambda fio: [fio[1], fio[2], fio[0]]

shufVasyaPetya = lambda test, prob = 0.5: [fio if random() < prob else petyaToVasya(fio) for fio in test]

def shuf(a):
    b = a[:]
    shuffle(b)
    return b

def print_test(lst):
    global test
    if not path.exists(tests_dir):
        print('Creating dir ' + tests_dir)
        mkdir(tests_dir)
    test += 1
    ouf = open(tests_dir + "/%02d" % test, 'w')
    print('Printing test {}'.format(test))
    print(len(lst), file=ouf)
    for fio in lst:
        print(' '.join(s.capitalize() for s in fio), file=ouf)
    ouf.close()

sample = [["Ivanov", "Ivan", "Ivanovich"], ["Ivan", "Borisovich", "Petrov"],
    ["Sergey", "Ivanovich", "Sidorov"], ["Pavlov", "Sergey", "Borisovich"]]

print_test(sample)
print_test(["FIO", "GIO"])
print_test(["FIO", "GIU"])
print_test(["IOF", "IOG"])
print_test(["IOF", "IUG"])
print_test(equalizeNamesPairs(randTest(10)))
print_test(shufVasyaPetya(equalizeNamesPairs(randTest(10))))
print_test(shuf(shufVasyaPetya(equalizeNamesPairs(randTest(MAXN)))))

tx = [
    [[randWord(), "I", "O"] for i in range(MAXN)],
    [[randWord(), "I", randWord()] for i in range(MAXN)],
    equalizeNamesPairs([[randWord(), randWord(), randWord()] for i in range(MAXN)])
]

for t1 in tx:
    for t2 in tx:
        for p in [0, 0.3, 1]:
            print_test(shuf(shufVasyaPetya(t1[:MAXN//2] + t2[MAXN//2:], p)))



