import random
random.seed("something")

class TestGen:
    def __init__(self):
        self.test_number = 0

    def generate_samples(self):
        self.print_test(3, "101")

    def generate_min_tests(self):
        self.print_test(1, "0")
        self.print_test(1, "1")
        self.print_test(2, "00")
        self.print_test(2, "01")
        self.print_test(2, "10")
        self.print_test(2, "11")
        self.print_test(6, "101111")
        self.print_test(6, "111111")
        self.print_test(6, "000000")
        self.print_test(6, "001000")
        self.print_test(6, "000001")
                                                              
    def generate_hand_tests(self):
        pass

    def generate_random_test(self, maxn):
        n = maxn
        s = ""
        for i in range(n):
            if random.randint(1, 2) == 1:
                s += "0"
            else:
                s += "1"
        self.print_test(n, s)

    def generate_max_tests(self, maxn):
        n = maxn
        s = ""
        for i in range(n // 2):
            s += "01"
        self.print_test(n, s)

        n = maxn
        s = ""
        for i in range(n // 2):
            s += "10"
        self.print_test(n, s)

        n = maxn
        s = ""
        for i in range(n):
            s += "0"
        self.print_test(n, s)

        n = maxn
        s = ""
        for i in range(n):
            s += "1"
        self.print_test(n, s)

        n = maxn
        s = "0"
        for i in range(n - 1):
            s += "1"
        self.print_test(n, s)

        n = maxn
        s = "1"
        for i in range(n - 1):
            s += "0"
        self.print_test(n, s)

        for it in range(5):
            n = maxn
            s = ""
            add = random.randint(1, 20) * 2
            for i in range((n - add) // 2):
                s += "10"
            for i in range(add):
                index = random.randint(0, len(s))
                lefts = ""
                rights = ""
                if index > 0:
                    lefts = s[:index]
                if index < len(s):
                    rights = s[index:]
                if random.randint(1, 2) == 1:
                    s = lefts + "0" + rights
                else:
                    s = lefts + "1" + rights
            self.print_test(n, s)

        n = maxn
        s = ""
        for i in range(n // 2):
            s += "0"
        for i in range(n // 2):
            s += "1"
        self.print_test(n, s)
        
        n = maxn
        s = ""
        for i in range(n // 2):
            s += "1"
        for i in range(n // 2):
            s += "0"
        self.print_test(n, s)
        
    def print_test(self, n, s):
        self.test_number += 1
        test_name = "../tests/" + "{0:0=2d}".format(self.test_number)
        test_file = open(test_name, "w")
        print(n, file=test_file)
        print(s, file=test_file)
        test_file.close()

    def generate_all_tests(self):
        smalln = 10
        midn = 100
        maxn = 1000

        self.generate_samples()                            #1 tests
        self.generate_min_tests()                          #11 tests
        self.generate_hand_tests()                         #0 tests

        for i in range(5):                                #5 tests
            self.generate_random_test(smalln)
        for i in range(5):                                #5 tests
            self.generate_random_test(midn)
        for i in range(5):                                #5 tests
            self.generate_random_test(maxn)
        self.generate_max_tests(maxn)                     # tests

import os, shutil
if os.path.exists('../tests'):
    print('Directory tests is already exists')
    shutil.rmtree('../tests', ignore_errors=False, onerror=None)
try:
    os.makedirs('../tests')
except OSError:
    pass

import time
start = time.time()
writer = TestGen()
writer.generate_all_tests()
finish = time.time()
print('All tests were generated. Elapsed time: ', finish - start)