import os, shutil
from random import *
import random
seed("linn1024@gmail.com")

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

    def generate_random_array(self, n, maxvalue):
        a = []
        for i in range(n):
            a.append(random.randint(1, maxvalue))
        return a

    def generate_samples(self):
        self.print_test(3, 4, [1, 3, 2])
        self.print_test(3, 2, [1, 2, 3])

    def generate_min_tests(self):
        self.print_test(1, 1, [1])
        self.print_test(1, 1, [2])
        self.print_test(1, 2, [2])
        self.print_test(2, 1, [4, 1])
        self.print_test(2, 2, [1, 3])
        self.print_test(2, 2, [3, 1])
        self.print_test(2, 4, [2, 2])
        self.print_test(2, 5, [2, 2])

    def generate_max_tests(self, maxn, maxk, maxvalue):
        a = []
        for i in range(maxn):
            a.append(1)
        self.print_test(maxn, maxk, a)
        self.print_test(maxn, 2 * maxn, a)

        for i in range(5):
            a = self.generate_random_array(maxn, maxvalue)
            self.print_test(maxn, maxk, a)
            self.print_test(maxn, 2 * maxn, a)
        

    def generate_hand_tests(self):
        pass
                                 
    def generate_random_test(self, k, m, mn, mx):
        rest = m
        a = []
        n = 0
        for i in range(1000):
           o = randint(mn, mx)
           n+=1
           a.append(min(o, rest))
           rest = rest - a[n - 1]
           if (rest == 0):
              break
           if (n>1000):
              break
        if (rest != 0):
           self.print_test(1,1,[1])
        self.print_test(k, n, a)

                             
    def print_test(self, k, n, a):
        self.test_number += 1
        test_name = "../tests/" + "{0:0=2d}".format(self.test_number)
        test_file = open(test_name, "w")
        print(k, file=test_file)
        print(n, file=test_file)
        for i in range(len(a) - 1):
           print(a[i], end = " ", file=test_file)
        print(a[len(a) - 1], file=test_file)	
        test_file.close()

    def generate_all_tests(self):
        #for i in range(15):
        #  self.generate_medium_test()
        #self.print_test(0, 0, 1)
        #self.print_test(2, 0, 1)
        self.print_test(169, 2, [200, 100])
        self.print_test(169, 1, [300])        
#self.print_test(0, 0, 0)
        self.generate_random_test(4, 8, 1, 2)
        self.generate_random_test(10, 25, 1, 4)
        self.generate_random_test(10, 20, 1, 5)
        self.generate_random_test(10, 15, 1, 5)
        self.generate_random_test(20, 10, 1, 5)
        self.generate_random_test(2000, 2000, 100, 500)
        self.generate_random_test(20, 15, 1, 5)
        self.generate_random_test(20, 50, 1, 5)
        self.generate_random_test(20, 12, 1, 5)
        self.generate_random_test(5000, 10001, 10, 50)
        self.generate_random_test(5000, 10000, 10, 50)
        self.generate_random_test(1000, 5001, 1, 1000)
        self.generate_random_test(2000, 4100, 25, 25)
        self.generate_random_test(2200, 4100, 20, 25)
                
        self.generate_random_test(1000000000, 1000000, 1000, 1000)
        self.generate_random_test(100000000, 1000, 1000, 1000)
        self.generate_random_test(1000000000, 1000, 1, 1)





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

writer = SandwichesTestGen()
writer.generate_all_tests()
