diff --git a/tada/perf_benchmark.py b/tada/perf_benchmark.py index 3f0a59a5..f88f900a 100644 --- a/tada/perf_benchmark.py +++ b/tada/perf_benchmark.py @@ -41,6 +41,7 @@ current_experiment_name = configuration.get_experiment_name( tada_configuration_dict, chosen_size ) + doubling_strategy = configuration.get_doubling_strategy(tada_configuration_dict) # set the name of the experiment for perf runner.metadata[constants.DESCRIPTION_METANAME] = current_experiment_name # read the chosen types @@ -69,7 +70,7 @@ position = configuration.get_position(tada_configuration_dict) # generate data data = generate.generate_data( - func_type, chosen_size, level, position, path, gen_func + func_type, chosen_size, level, position, path, gen_func, doubling_strategy ) # run benchmark if configuration.get_sortinput(tada_configuration_dict): diff --git a/tada/tada_a_bigoh.py b/tada/tada_a_bigoh.py index 08b061d6..5d210359 100644 --- a/tada/tada_a_bigoh.py +++ b/tada/tada_a_bigoh.py @@ -193,9 +193,10 @@ def tada(tada_arguments): # noqa: C901 meanlastround = mean current_runningtime = time.time() - start_time if current_runningtime > tada_arguments.runningtime: + runtime_str = str(current_runningtime) dis.output_message( "\nQuit due to exceeding the max time limit: " - + current_runningtime, + + runtime_str, to_print, ) constants.QUIT_BY_MAX_RUNTIME = 1 diff --git a/tada/util/arguments.py b/tada/util/arguments.py index a0d1718c..5e650e3d 100644 --- a/tada/util/arguments.py +++ b/tada/util/arguments.py @@ -137,6 +137,13 @@ def parse(args: List[str]) -> Namespace: default=False, help="Show log/debug/diagnostic output", ) + parser.add_argument( + "--twovar", + required=False, + action="store_true", + default=False, + help="Double both variables in doubling experiments", + ) parser.add_argument( "--md", required=False, diff --git a/tada/util/configuration.py b/tada/util/configuration.py index b074e294..b6fd797e 100644 --- a/tada/util/configuration.py +++ b/tada/util/configuration.py @@ -19,6 +19,7 @@ LEVEL = "level" SORTED = "sorted" POSITION = "position" +DOUBLES = "twovar" def save(configuration_filename: str, tada_configuration: Dict[str, Any]) -> None: @@ -90,6 +91,11 @@ def get_types(current_dictionary): return current_dictionary[TYPES] +def get_doubling_strategy(current_dictionary): + """Return the doubling strategy argument from the provided dictionary""" + return current_dictionary[DOUBLES] + + def get_schema_path(current_dictionary): """Return the schema path argument from the provided dictionary""" return current_dictionary[SCHEMA] diff --git a/tada/util/generate.py b/tada/util/generate.py index 99d3c4ff..b57f921b 100644 --- a/tada/util/generate.py +++ b/tada/util/generate.py @@ -32,7 +32,7 @@ # pylint: disable=W0102 -def store_data_to_global(path, chosen_size, level=1, position=[0]): +def store_data_to_global(path, chosen_size, level=1, position=[0], doubling_strategy=False): """Generate data through global variable""" def store_global(a): @@ -42,7 +42,7 @@ def store_global(a): global_data = global_data + (a,) strategies = generate_experiment_strategy( - path, chosen_size, level, position + path, chosen_size, level, position, doubling_strategy ) # store data based on the amount of parameters for st in strategies: @@ -52,7 +52,7 @@ def store_global(a): def generate_experiment_strategy( - path, size, level=1, position=[0] + path, size, level=1, position=[0], doubling_strategy=False ): # pylint: disable=W0102 """generate strategies from a schema path and current input size""" json_schema = read.read_schema(path) @@ -75,8 +75,12 @@ def detect_level_and_position( subschema, level - 1, position, index_position + 1 ) - js = detect_level_and_position(json_schema, level, position) - double_experiment_size(js, size) + if doubling_strategy is True: + for js in json_schema: + double_experiment_size(js, size) + else: + js = detect_level_and_position(json_schema, level, position) + double_experiment_size(js, size) strategy = [] for j in json_schema: strategy.append(from_schema(j)) @@ -133,9 +137,9 @@ def generate_func_from_single_st(function, strategy): return function -# pylint: disable=W0102, R0913 +# pylint: disable=W0102, R0913, line-too-long def generate_data( - chosen_types, chosen_size, level=1, position=[0], path=None, gen_func=None + chosen_types, chosen_size, level=1, position=[0], path=None, gen_func=None, doubling_strategy=False ): """Generate a list of data values""" generated_values = () @@ -149,7 +153,7 @@ def generate_data( generated_values = generated_values + (generated_value,) elif chosen_types[0] == "hypothesis": generated_values = store_data_to_global( - path, chosen_size, level, position + path, chosen_size, level, position, doubling_strategy ) elif chosen_types[0] == "custom": generated_values = gen_func(chosen_size) diff --git a/tests/test_generate.py b/tests/test_generate.py index 09df2965..e5f40472 100644 --- a/tests/test_generate.py +++ b/tests/test_generate.py @@ -163,6 +163,23 @@ def test_generate_data_with_hypothesis(tmpdir): assert generated_data is not None +# pylint: disable=W0102, R0913 +def test_generate_data_with_hypothesis_doubling_both(tmpdir): + """Checks that requesting a generated hypothesis data returns one""" + path = tmpdir.mkdir("sub").join("hello.txt") + path.write('[{"type": "array", "items": {"type": "integer"}}]') + # assume the doubling experiment is at 100 + current_size = 100 + level = 1 + position = [0] + requested_types = ["hypothesis"] + requested_oath = str(path) + generated_data = generate.generate_data( + requested_types, current_size, level, position, requested_oath, True + ) + assert generated_data is not None + + # pylint: disable=W0621 def test_generate_data_with_gen_func(generate_int_test): """Checks that requesting a generated hypothesis data returns one"""