#!/usr/bin/python3

from script_utils import *

'''
(0) example
'''

groupsHandler = GroupsHandler()


def limited_sum():
    addScript(mode="dual", A="choose_random", B="choose_random", m=1000, max_val=10, flags=["list_small_nm"])

    for n in [1, 2, 3]:
        addScript(mode="dual", A="choose_random", B="choose_random", n=n, m=1000, max_val=10)

    addScript(mode="pattern", n=2, flags=["many_tests"], max_T=10)

    addScript(mode="pattern", flags=["many_tests"], n=2)
    addScript(mode="pattern", flags=["many_tests"])
    addScript(mode="pattern", flags=["many_tests"], seed="1234")
    addScript(mode="pattern", flags=["many_tests"], max_T=7)

    addScript(mode="dual", A="choose_random", B="choose_random", m=1000, max_val=1)
    addScript(mode="dual", A="choose_random", B="choose_random", m=1000, max_val=3)

    addScript(mode="dual", A="random", B="random", max_val=3, stretch_from_max=10, stretch_prob=0.5, flags=["many_tests"])
    addScript(mode="dual", A="random", B="random", max_val=3, stretch_from_max=10, stretch_prob=0.8, flags=["many_tests"])
    addScript(mode="dual", A="random", B="random", max_val=3, stretch_from_max=10, stretch_prob=1.0, flags=["many_tests"])

    addScript(mode="dual", A="choose_random", B="choose_random", m=1000, max_val=10000)

    addScript(mode="dual", A="random", B="random", max_val=100)
    addScript(mode="dual", A="random_by_one", B="random_by_one")

    addScript(mode="chain_1", flags=["many_tests"])
    addScript(mode="chain_1", segments=-2)

    addScript(mode="chain_1", flags=["many_tests", "shifted"], max_T=10)
    addScript(mode="chain_1", segments=-2, flags=["shifted"])

    addScript(mode="max_ans")


def limited_cnt():
    addScript(mode="dual", A="choose_random", B="choose_random", flags=["list_small_nm"])
    addScript(mode="dual", A="choose_random", B="choose_random", flags=["many_tests"])

    for n in [1, 2, 3]:
        addScript(mode="dual", A="choose_random", B="choose_random", n=n, m=1001)

    addScript(mode="dual", A="random", B="random",  stretch_from_max=10, stretch_prob=0.5, flags=["many_tests"])
    addScript(mode="dual", A="random", B="random",  stretch_from_max=10, stretch_prob=0.8, flags=["many_tests"])
    addScript(mode="dual", A="random", B="random",  stretch_from_max=10, stretch_prob=1.0, flags=["many_tests"])

    addScript(mode="pattern", flags=["many_tests"], n=2)
    addScript(mode="pattern", flags=["many_tests"])
    addScript(mode="pattern", flags=["many_tests"], seed="1234")
    addScript(mode="pattern", flags=["exact_tests"], max_T=7)

    addScript(mode="dual", A="random", B="random")
    addScript(mode="dual", A="sorted_random", B="random")
    addScript(mode="dual", A="sorted_random", B="sorted_random")
    addScript(mode="dual", A="sorted_random", B="r_sorted_random")

    addScript(mode="chain_1", flags=["many_tests"])
    addScript(mode="chain_1", segments=-2)

    addScript(mode="chain_1", flags=["many_tests", "shifted"], max_T=10)
    addScript(mode="chain_1", segments=-2, flags=["shifted"])

    addScript(mode="max_ans")


def general_group(max_n=3):
    addScript(mode="dual", A="choose_random", B="choose_random", flags=["list_small_nm"])
    addScript(mode="dual", A="choose_random", B="choose_random", flags=["many_tests"])

    addScript(mode="dual", A="random", B="random", noise=10, intensity=20, stretch_from_max=10, stretch_prob=0.5, flags=["many_tests"])
    addScript(mode="dual", A="random", B="random", noise=10, intensity=20, stretch_from_max=10, stretch_prob=0.8, flags=["many_tests"])
    addScript(mode="dual", A="random", B="random", noise=10, intensity=20, stretch_from_max=10, stretch_prob=1.0, flags=["many_tests"])

    addScript(mode="pattern", noise=10, intensity=20, flags=["many_tests"])

    if max_n >= 2:
        addScript(mode="pattern", noise=10, intensity=20, flags=["many_tests"], n=2)
        addScript(mode="pattern", noise=10, intensity=20, flags=["many_tests"], seed="1234")
        addScript(mode="pattern", noise=10, intensity=20, flags=["many_tests"], max_T=10)
        addScript(mode="pattern", noise=10, intensity=20, flags=["exact_tests"], max_T=5)
        addScript(mode="pattern", noise=10, intensity=20)

    if max_n >= 3:
        addScript(mode="chain_1", noise_d=10, dist=2, intensity=20, segments=-2, width=1, flags=["shifted", "exact_tests"], m=400)
        addScript(mode="chain_1", noise_d=10, dist=2, intensity=20, segments=-2, width=1, flags=["shifted", "many_tests"])
        addScript(mode="chain_1", noise_d=10, dist=2, intensity=20, segments=-2, width=1, flags=["shifted", "exact_tests"], max_T=5)
        addScript(mode="chain_1", noise_d=10, dist=2, intensity=20, segments=-2, width=1, flags=["shifted"])

    addScript(mode="dual", A="random", B="random_b_move", max_val_a=10**7, max_ans=1)
    addScript(mode="dual", A="random", B="random_b_move", max_val_a=10**7, max_ans=5)

    addScript(mode="dual", A="choose_random", B="random_b_move", max_val_a=10**7, max_ans=0,   flags=["many_tests"])
    addScript(mode="dual", A="choose_random", B="random_b_move", max_val_a=10**7, max_ans=1,   flags=["many_tests"])
    addScript(mode="dual", A="choose_random", B="random_b_move", max_val_a=10**7, max_ans=5,   flags=["many_tests"])
    addScript(mode="dual", A="choose_random", B="random_b_move", max_val_a=10**7, max_ans=100, flags=["many_tests"])

    addScript(mode="dual", A="sorted_random", B="choose_random", flags=["many_tests"])
    addScript(mode="dual", A="choose_random", B="choose_random", flags=["many_tests"], seed="meow")

    addScript(mode="dual", A="random", B="random")
    addScript(mode="dual", A="sorted_random", B="random")
    addScript(mode="dual", A="sorted_random", B="sorted_random")
    addScript(mode="dual", A="sorted_random", B="r_sorted_random")

    if max_n >= 2:
        addScript(mode="chain_1", noise=10, intensity=20, flags=["many_tests"])
        addScript(mode="chain_1", noise=10, intensity=20, segments=-2, width=10, flags=["high"])
        addScript(mode="chain_1", noise=10, intensity=20, segments=-2, width=1000, flags=["high"])

    if max_n >= 3:
        addScript(mode="chain_1", noise=10, intensity=20, flags=["many_tests", "shifted"])
        addScript(mode="chain_1", noise=10, intensity=20, flags=["many_tests", "shifted"], max_T=10)
        addScript(mode="chain_1", noise=10, intensity=20, segments=-2, flags=["shifted"])

        addScript(mode="chain_1", noise_d=10, dist=10, intensity=20, segments=-2, width=12, flags=["shifted"])
        addScript(mode="chain_1", noise_d=10, dist=53, intensity=20, segments=-2, width=52, flags=["shifted"])

    addScript(mode="dual", A="uniform", B="uniform")
    addScript(mode="max_ans", noise=10, intensity=20)


@groupsHandler.registerGroup(group=1, depends=[], score=8)
def group1():
    limited_sum()

    addScript(mode="dual", A="random", B="random", max_val=0)


@groupsHandler.registerGroup(group=2, depends=[1], score=9)
def group2():
    limited_sum()


@groupsHandler.registerGroup(group=3, depends=[1], score=8)
def group3():
    limited_cnt()


@groupsHandler.registerGroup(group=4, depends=[1, 3], score=7)
def group4():
    limited_cnt()


@groupsHandler.registerGroup(group=5, depends=[], score=6)
def group5():
    general_group()

    addScript(mode="dual", A="random", B="random", max_val=0)


@groupsHandler.registerGroup(group=6, depends=[5], score=10)
def group6():
    general_group()

    T = 5
    for i in range(60 // T):
        addScript(mode="pattern", pattern_skips=T * i, noise=10, intensity=20, flags=["exact_tests"], max_T=T)


@groupsHandler.registerGroup(group=7, depends=[], score=8)
def group7():
    general_group(max_n=1)
    addScript(mode="dual", A="random", B="random", max_val=0)


@groupsHandler.registerGroup(group=8, depends=[7], score=11)
def group8():
    general_group(max_n=2)
    addScript(mode="dual", A="random", B="random", max_val=0)


def limited_ans():
    addScript(mode="dual", A="choose_random", B="random_b_move", m=500, max_val_a=10**7)
    addScript(mode="dual", A="random", B="random_b_move", max_val_a=10**7)
    addScript(mode="dual", A="sorted_random", B="random_b_move", max_val_a=10**7)
    addScript(mode="dual", A="uniform", B="uniform")


@groupsHandler.registerGroup(group=9, depends=[], score=5)
def group9():
    addScript(mode="dual", A="choose_random", B="random_b_move", max_val_a=10**7, flags=["list_small_nm"])

    addScript(mode="dual", A="choose_random", B="random_b_move", m=500, max_val_a=10**7, max_ans=0)
    addScript(mode="dual", A="choose_random", B="random_b_move", m=500, max_val_a=10**7, max_ans=1)

    limited_ans()

    addScript(mode="pattern", noise_d=10, intensity=20, dist=0, flags=["many_tests", "fixed"])
    addScript(mode="pattern", noise_d=10, intensity=20, dist=1, flags=["many_tests", "fixed"])
    addScript(mode="pattern", noise_d=10, intensity=20, dist=1, flags=["exact_tests", "fixed"], max_T=10)

    addScript(mode="chain_1", noise_d=10, intensity=20, dist=1, flags=["many_tests"], max_T=10)
    addScript(mode="chain_1", noise_d=10, intensity=20, dist=1, segments=-2, width=1, flags=["high"])

    addScript(mode="dual", A="random", B="random", max_val=0)


@groupsHandler.registerGroup(group=10, depends=[9], score=6)
def group10():
    addScript(mode="dual", A="choose_random", B="random_b_move", max_val_a=10**7, flags=["list_small_nm"])
    addScript(mode="dual", A="choose_random", B="random_b_move", m=500, max_val_a=10**7, max_ans=2)

    limited_ans()

    addScript(mode="pattern", noise_d=10, intensity=20, dist=1, flags=["many_tests", "fixed"])
    addScript(mode="pattern", noise_d=10, intensity=20, dist=2, flags=["many_tests", "fixed"])
    addScript(mode="pattern", noise_d=10, intensity=20, dist=2, flags=["exact_tests", "fixed"], max_T=10)

    addScript(mode="chain_1", noise_d=10, intensity=20, dist=2, segments=-2, width=1, flags=["shifted", "many_tests"])
    addScript(mode="chain_1", noise_d=10, intensity=20, dist=2, segments=-2, width=1, flags=["shifted", "exact_tests"], m=400)

    addScript(mode="chain_1", noise_d=10, intensity=20, dist=2, flags=["many_tests"], max_T=10)
    addScript(mode="chain_1", noise_d=10, intensity=20, dist=2, segments=-2, width=2, flags=["high"])

    addScript(mode="chain_1", noise_d=10, intensity=20, dist=2, width=1, flags=["many_tests", "shifted"], max_T=10)
    addScript(mode="chain_1", noise_d=10, intensity=20, dist=2, segments=-2, width=1, flags=["shifted"])


@groupsHandler.registerGroup(group=11, depends=[*range(5, 11)], score=12)
def group11():
    general_group()


@groupsHandler.registerGroup(group=12, depends=[*range(1, 12)], score=10)
def group12():
    general_group()


if __name__ == '__main__':
    groupsHandler.execute()
