import random
random.seed("something")

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

    def generate_samples(self):
        #3 tests
        self.print_test(2, [(0, -1), (0, 1)])
        self.print_test(1, [(0, 0), (1, 1)])
        self.print_test(1, [(0, 0), (0, 1)])

    def generate_min_tests(self):
        #3 tests
        self.print_test(1, [(-1, 0), (0, 1)])
        self.print_test(1, [(-1, 1), (0, 0)])
        self.print_test(1, [(1, 0), (2, -1)])
                                                                            
    def generate_hand_tests(self):
        #14 tests
        self.print_test(4, [(0, 0), (2, 2)])
        self.print_test(4, [(-1, -1), (1, 1)])
        self.print_test(4, [(-3, -2), (-1, 0)])
        self.print_test(4, [(-1, 1), (1, -1)])
        self.print_test(4, [(0, 0), (2, -2)])
        self.print_test(4, [(-2, 3), (0, 1)])
        self.print_test(2, [(0, 2), (0, 0)])
        self.print_test(2, [(15, 17), (15, 15)])
        self.print_test(2, [(17, 15), (19, 15)])
        self.print_test(2, [(17, 15), (15, 15)])
        self.print_test(3, [(0, 2), (0, 0)])
        self.print_test(1, [(0, 2), (0, 0)])
        self.print_test(8, [(2, 1), (4, 5)])
        self.print_test(8, [(4, 5), (2, 1)])

    def generate_random_test(self, maxc):
        c = maxc
        x1 = random.randint(-c, c)
        y1 = random.randint(-c, c)
        x2 = random.randint(-c, c)
        y2 = random.randint(-c, c)
        
        while x1 == x2 and y1 == y2:
            x1 = random.randint(-c, c)
            y1 = random.randint(-c, c)
            x2 = random.randint(-c, c)
            y2 = random.randint(-c, c)
        a = []
        a.append((x1, y1))
        a.append((x2, y2))
        return a

    def generate_max_tests(self, maxs, maxc):
        #9 tests
        self.print_test(4 * maxc * maxc, [(-maxc, -maxc), (maxc, maxc)])
        self.print_test(4 * maxc * maxc, [(-maxc, maxc), (maxc, -maxc)])
        self.print_test(2 * maxc * maxc, [(0, maxc), (0, -maxc)])
        self.print_test(2 * maxc * maxc - 1, [(0, maxc), (0, -maxc)])
        
        for it in range(5):
            a = self.generate_random_test(maxc)
            self.print_test(random.randint(1, maxs * 10**6) / 10**6, a)


    def generate_small_test(self):
        a = self.generate_random_test(10)
        self.print_test(random.randint(1, 100 * 10**6) / 10**6, a)

    #def generate_medium_test(self):
    #    self.generate_random_test(random.randint(500, 1000), random.randint(500, 2000))

    def print_test(self, s, p):
        self.test_number += 1
        test_name = "../tests/" + "{0:0=2d}".format(self.test_number)
        test_file = open(test_name, "w")
        print(s, file=test_file)
        print('\n'.join(' '.join(str(coordinate) for coordinate in point) for point in p), file=test_file)
        test_file.close()

    def generate_all_tests(self):
        maxs = 10**9
        maxc = 10**4
        self.generate_samples()                       #3 tests
        self.generate_min_tests()                     #3 tests
        self.generate_hand_tests()                    #14 tests
        for i in range(10):                           #10 tests
          self.generate_small_test()
        #for i in range(10):                          #10 tests
        #  self.generate_medium_test()
        #for i in range(10):                          #10 tests
        #  self.generate_random_test(maxn, maxm)
        self.generate_max_tests(maxs, maxc)           #9 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)
