diff --git a/archive.py b/archive.py index 33e467c..3d640f7 100644 --- a/archive.py +++ b/archive.py @@ -67,7 +67,4 @@ class Archive: branch not in self.false_branches): branches.append((branch, False)) - if len(branches) > 0: - print(list(test_case.items()), branches) - return branches diff --git a/fuzzer.py b/fuzzer.py index c72abd9..6b8c5fc 100644 --- a/fuzzer.py +++ b/fuzzer.py @@ -1,6 +1,7 @@ import argparse import os -from random import randrange, choice, random, sample, seed +from random import randrange, choice, random, seed +from typing import Tuple, Dict, List, Set, Callable from frozendict import frozendict from tqdm import tqdm @@ -10,7 +11,6 @@ import operators from archive import Archive from instrument import (Arg, Params, invoke, call_statement, BranchTransformer, module_of, load_benchmark, get_benchmark, functions) -from typing import Tuple, Dict, List, Set, Callable Range = Tuple[int, int] @@ -102,10 +102,11 @@ def add_to_pool(arguments: List[Arg], params: Params): param_list: List[any] = [None] * len(arg_names) for i, name in enumerate(arg_names): param_list[i] = params[name] + pools[arg_types].add(tuple(param_list)) -def get_pool(arguments: List[Arg]) -> List[Params]: +def extract_from_pool(arguments: List[Arg]) -> Params: arg_types = tuple([arg_type for _, arg_type in arguments]) arg_names = [arg_name for arg_name, _ in arguments] @@ -124,13 +125,22 @@ def get_pool(arguments: List[Arg]) -> List[Params]: pools[arg_types] = new_pool - return [frozendict({arg_names[i]: p for i, p in enumerate(param)}) for param in pools[arg_types]] + i = randrange(0, len(pools[arg_types])) + + for e in pools[arg_types]: + if i == 0: + return frozendict({arg_names[i]: p for i, p in enumerate(e)}) + i -= 1 + + raise RuntimeError("unreachable statement") def mutate(test_case: Params, arguments: List[Arg]) -> Params: arg_name = choice(list(test_case.keys())) # choose name to mutate types: Dict[str, str] = {arg_name: arg_type for arg_name, arg_type in arguments} - return test_case.set(arg_name, random_mutate(types[arg_name], test_case[arg_name])) + mutated = test_case.set(arg_name, random_mutate(types[arg_name], test_case[arg_name])) + add_to_pool(arguments, mutated) + return mutated def crossover(chosen_test: Params, other_chosen_test: Params, arguments: List[Arg]) -> Tuple[Params, Params]: @@ -149,31 +159,12 @@ def crossover(chosen_test: Params, other_chosen_test: Params, arguments: List[Ar t1 = chosen_test.set(arg_name, i1) t2 = other_chosen_test.set(arg_name, i2) + add_to_pool(arguments, t1) + add_to_pool(arguments, t2) + return t1, t2 -def generate_test_case(f_name: str, arguments: List[Arg], archive: Archive, bias_unseen=True) -> Params: - pool: List[Params] = get_pool(arguments) - - attempts = 20 # attempts to generate a random test that satisfies a new branch - - while True: - test = sample(pool, 1)[0] - is_new = [] if not bias_unseen else archive.satisfies_unseen_branches(test) - - attempts -= 1 - - if bias_unseen and len(is_new) == 0 and attempts > 0: - # print(f"Not new: {test}") - continue - - try: - invoke(f_name, test) - return test # return only test cases that satisfy assertions - except AssertionError: - pass - - def str_crossover(parent1: str, parent2: str): if len(parent1) > 1 and len(parent2) > 1: pos = randrange(1, len(parent1)) @@ -218,13 +209,13 @@ def get_test_class(orig_f_name: str, cases: Set[Params]) -> str: "\n") -def generate_tests(files: List[str], seed_num: int, generation_fn: Callable[[str], Set[Params]]): +def generate_tests(files: List[str], seed_num: int, generation_fn: Callable[[str], Set[Params]], out_dir: str): load_benchmark(save_instrumented=False, files=files) seed(seed_num) # init random seed for file_name, f_names in tqdm(get_benchmark().items(), desc="Generating tests"): suite = [(name, generation_fn(name)) for name in f_names] - with open(os.path.join(OUT_DIR, f"test_{file_name}.py"), "w") as f: + with open(os.path.join(out_dir, f"test_{file_name}.py"), "w") as f: f.write(get_test_import_stmt(f_names)) f.write("\n\n") f.write("\n\n".join([get_test_class(name, cases) for name, cases in suite])) @@ -237,19 +228,17 @@ def fuzzer_generate(f_name: str) -> Set[Params]: archive = Archive(instrumented) for _ in tqdm(range(FUZZER_REPS), desc=f"fuzzer [{f_name}]"): - test = generate_test_case(instrumented, args, archive, bias_unseen=False) + test = extract_from_pool(args) alteration_choice = randrange(3) if alteration_choice == 1: test = mutate(test, args) elif alteration_choice == 2: - test2 = generate_test_case(instrumented, args, archive, bias_unseen=False) + test2 = extract_from_pool(args) test, test2 = crossover(test, test2, args) archive.consider_test(test2) - add_to_pool(args, test2) archive.consider_test(test) - add_to_pool(args, test) return archive.build_suite() @@ -264,7 +253,7 @@ def main(): nargs="?", default=0) args = parser.parse_args() - generate_tests(args.file, args.seed, fuzzer_generate) + generate_tests(args.file, args.seed, fuzzer_generate, OUT_DIR) if __name__ == "__main__": diff --git a/genetic.py b/genetic.py index f8dd21a..d919d51 100644 --- a/genetic.py +++ b/genetic.py @@ -1,25 +1,23 @@ import argparse +import math import os -import random from functools import partial -from typing import Tuple, List, Set +from typing import Tuple, Set import frozendict -import tqdm from deap import creator, base, tools, algorithms import fuzzer import instrument import operators -from fuzzer import generate_test_case, get_test_class from archive import Archive INDMUPROB = 0.05 MUPROB = 0.33 CXPROB = 0.33 TOURNSIZE = 3 -NPOP = 1000 -NGEN = 200 +NPOP = 200 +NGEN = 30 REPS = 10 OUT_DIR = os.path.join(os.path.dirname(__file__), "tests") @@ -43,7 +41,7 @@ def generate(orig_name: str) -> Set[instrument.Params]: archive = Archive(f_name) toolbox = base.Toolbox() - toolbox.register("attr_test_case", lambda: list(generate_test_case(f_name, args, archive).items())) + toolbox.register("attr_test_case", lambda: list(fuzzer.extract_from_pool(args).items())) toolbox.register("individual", tools.initIterate, creator.Individual, lambda: toolbox.attr_test_case()) toolbox.register("population", tools.initRepeat, list, toolbox.individual) toolbox.register("evaluate", partial(compute_fitness, f_name, archive)) @@ -52,12 +50,14 @@ def generate(orig_name: str) -> Set[instrument.Params]: t1, t2 = frozendict.frozendict(tc1), frozendict.frozendict(tc2) o1, o2 = fuzzer.crossover(t1, t2, args) i1, i2 = creator.Individual(o1.items()), creator.Individual(o2.items()) + # print("mate", tc1, tc2, i1, i2) return i1, i2 def mutate(tc): t = frozendict.frozendict(tc) o = fuzzer.mutate(t, args) i1 = creator.Individual(o.items()) + # print("mutate", tc, i1) return i1, toolbox.register("mate", mate) @@ -102,10 +102,11 @@ def compute_fitness(f_name: str, archive: Archive, individual: list) -> Tuple[fl try: out = instrument.invoke(f_name, x) except AssertionError: - # print(f_name, x, "=", "[FAILS] fitness = 100.0") - return 100.0, + print(f_name, x, "=", "[FAILS] fitness = inf") + return math.inf, fitness = 0.0 + no_branches_hit = True # Sum up branch distances for branch in range(range_start, range_end): @@ -113,16 +114,21 @@ def compute_fitness(f_name: str, archive: Archive, individual: list) -> Tuple[fl if branch not in archive.true_branches: fitness += normalize(operators.distances_true[branch]) else: - fitness += 10 + fitness += 2 + no_branches_hit = False for branch in range(range_start, range_end): if branch in operators.distances_false: if branch not in archive.false_branches: fitness += normalize(operators.distances_false[branch]) else: - fitness += 10 + fitness += 2 + no_branches_hit = False - # print(f_name, x, "=", out, "fitness =", fitness) + if no_branches_hit: + fitness = 1000000 + + print(f_name, x, "=", out, "fitness =", fitness) return fitness, @@ -137,7 +143,7 @@ def main(): args = parser.parse_args() init_deap() - fuzzer.generate_tests(args.file, args.seed, generate) + fuzzer.generate_tests(args.file, args.seed, generate, OUT_DIR) if __name__ == '__main__': diff --git a/muttest.py b/muttest.py index ec63e3a..40663dc 100644 --- a/muttest.py +++ b/muttest.py @@ -83,7 +83,12 @@ def compute_stats(df_gen: pd.DataFrame, df_fuz: pd.DataFrame, output_file: str, def run_mutpy(test_path: str, source_path: str) -> float: output = subprocess.check_output( - [sys.executable, MUT_PY_PATH, '-t', source_path, '-u', test_path]).decode('utf-8') + [sys.executable, + MUT_PY_PATH, + '-t', source_path, + '-u', test_path, + '--hom-strategy', 'RANDOM', + '--percentage', '75']).decode('utf-8') score = re.search('Mutation score \\[.*]: (\\d+\\.\\d+)%', output).group(1) return float(score) diff --git a/out/mutation_results_fuzzer.csv b/out/mutation_results_fuzzer.csv index 4d31830..2555b3f 100644 --- a/out/mutation_results_fuzzer.csv +++ b/out/mutation_results_fuzzer.csv @@ -1,101 +1,101 @@ ,file,score -0,anagram_check,23.1 -1,anagram_check,23.1 -2,anagram_check,23.1 -3,anagram_check,23.1 -4,anagram_check,23.1 -5,anagram_check,23.1 -6,anagram_check,23.1 -7,anagram_check,23.1 -8,anagram_check,23.1 -9,anagram_check,23.1 -10,caesar_cipher,58.8 -11,caesar_cipher,58.8 -12,caesar_cipher,58.8 -13,caesar_cipher,58.8 -14,caesar_cipher,58.8 -15,caesar_cipher,58.8 -16,caesar_cipher,58.8 -17,caesar_cipher,58.8 -18,caesar_cipher,58.8 -19,caesar_cipher,58.8 -20,check_armstrong,90.3 -21,check_armstrong,90.3 -22,check_armstrong,90.3 -23,check_armstrong,90.3 -24,check_armstrong,90.3 -25,check_armstrong,90.3 -26,check_armstrong,90.3 -27,check_armstrong,90.3 -28,check_armstrong,90.3 -29,check_armstrong,90.3 -30,common_divisor_count,72.3 -31,common_divisor_count,72.3 -32,common_divisor_count,72.3 -33,common_divisor_count,72.3 -34,common_divisor_count,72.3 -35,common_divisor_count,72.3 -36,common_divisor_count,72.3 -37,common_divisor_count,72.3 -38,common_divisor_count,72.3 -39,common_divisor_count,72.3 -40,exponentiation,71.4 -41,exponentiation,71.4 -42,exponentiation,71.4 -43,exponentiation,71.4 -44,exponentiation,71.4 -45,exponentiation,71.4 -46,exponentiation,71.4 -47,exponentiation,71.4 +0,anagram_check,16.7 +1,anagram_check,9.1 +2,anagram_check,25.0 +3,anagram_check,20.0 +4,anagram_check,33.3 +5,anagram_check,12.5 +6,anagram_check,30.0 +7,anagram_check,25.0 +8,anagram_check,30.0 +9,anagram_check,30.0 +10,caesar_cipher,61.5 +11,caesar_cipher,60.9 +12,caesar_cipher,60.0 +13,caesar_cipher,58.1 +14,caesar_cipher,67.9 +15,caesar_cipher,56.0 +16,caesar_cipher,58.3 +17,caesar_cipher,61.5 +18,caesar_cipher,70.0 +19,caesar_cipher,47.6 +20,check_armstrong,88.0 +21,check_armstrong,88.9 +22,check_armstrong,90.9 +23,check_armstrong,94.1 +24,check_armstrong,87.0 +25,check_armstrong,88.9 +26,check_armstrong,88.9 +27,check_armstrong,91.7 +28,check_armstrong,88.5 +29,check_armstrong,88.5 +30,common_divisor_count,71.4 +31,common_divisor_count,71.0 +32,common_divisor_count,71.4 +33,common_divisor_count,75.0 +34,common_divisor_count,65.5 +35,common_divisor_count,71.4 +36,common_divisor_count,75.0 +37,common_divisor_count,63.9 +38,common_divisor_count,78.1 +39,common_divisor_count,69.4 +40,exponentiation,66.7 +41,exponentiation,67.9 +42,exponentiation,74.1 +43,exponentiation,72.0 +44,exponentiation,65.4 +45,exponentiation,61.5 +46,exponentiation,67.7 +47,exponentiation,70.8 48,exponentiation,71.4 -49,exponentiation,71.4 -50,gcd,47.8 -51,gcd,47.8 -52,gcd,47.8 -53,gcd,47.8 -54,gcd,47.8 -55,gcd,47.8 -56,gcd,47.8 -57,gcd,47.8 -58,gcd,47.8 -59,gcd,47.8 -60,longest_substring,82.6 -61,longest_substring,82.6 -62,longest_substring,82.6 -63,longest_substring,82.6 -64,longest_substring,82.6 -65,longest_substring,82.6 -66,longest_substring,82.6 -67,longest_substring,82.6 -68,longest_substring,82.6 -69,longest_substring,82.6 -70,rabin_karp,64.9 -71,rabin_karp,64.9 -72,rabin_karp,64.9 -73,rabin_karp,64.9 -74,rabin_karp,64.9 -75,rabin_karp,64.9 -76,rabin_karp,64.9 -77,rabin_karp,64.9 -78,rabin_karp,64.9 -79,rabin_karp,64.9 -80,railfence_cipher,89.4 -81,railfence_cipher,89.4 -82,railfence_cipher,89.4 -83,railfence_cipher,89.4 -84,railfence_cipher,89.4 -85,railfence_cipher,89.4 -86,railfence_cipher,89.4 -87,railfence_cipher,89.4 -88,railfence_cipher,89.4 -89,railfence_cipher,89.4 -90,zellers_birthday,68.3 -91,zellers_birthday,68.3 -92,zellers_birthday,68.3 -93,zellers_birthday,68.3 -94,zellers_birthday,68.3 -95,zellers_birthday,68.3 -96,zellers_birthday,68.3 -97,zellers_birthday,68.3 -98,zellers_birthday,68.3 -99,zellers_birthday,68.3 +49,exponentiation,72.4 +50,gcd,53.3 +51,gcd,60.0 +52,gcd,37.5 +53,gcd,52.9 +54,gcd,47.4 +55,gcd,45.0 +56,gcd,62.5 +57,gcd,55.6 +58,gcd,43.8 +59,gcd,50.0 +60,longest_substring,85.7 +61,longest_substring,88.2 +62,longest_substring,82.4 +63,longest_substring,85.7 +64,longest_substring,75.0 +65,longest_substring,86.7 +66,longest_substring,76.5 +67,longest_substring,75.0 +68,longest_substring,94.4 +69,longest_substring,90.0 +70,rabin_karp,61.4 +71,rabin_karp,70.0 +72,rabin_karp,65.0 +73,rabin_karp,60.5 +74,rabin_karp,68.4 +75,rabin_karp,71.8 +76,rabin_karp,67.6 +77,rabin_karp,63.9 +78,rabin_karp,72.5 +79,rabin_karp,60.4 +80,railfence_cipher,88.6 +81,railfence_cipher,86.8 +82,railfence_cipher,93.8 +83,railfence_cipher,90.6 +84,railfence_cipher,88.6 +85,railfence_cipher,90.0 +86,railfence_cipher,91.0 +87,railfence_cipher,90.4 +88,railfence_cipher,91.0 +89,railfence_cipher,92.0 +90,zellers_birthday,68.1 +91,zellers_birthday,73.0 +92,zellers_birthday,70.7 +93,zellers_birthday,68.5 +94,zellers_birthday,71.0 +95,zellers_birthday,65.6 +96,zellers_birthday,67.4 +97,zellers_birthday,67.8 +98,zellers_birthday,68.8 +99,zellers_birthday,70.1 diff --git a/out/mutation_results_genetic.csv b/out/mutation_results_genetic.csv index 3385962..c769705 100644 --- a/out/mutation_results_genetic.csv +++ b/out/mutation_results_genetic.csv @@ -1,101 +1,101 @@ ,file,score -0,anagram_check,38.5 -1,anagram_check,38.5 -2,anagram_check,38.5 -3,anagram_check,38.5 -4,anagram_check,38.5 -5,anagram_check,38.5 -6,anagram_check,38.5 -7,anagram_check,38.5 -8,anagram_check,38.5 -9,anagram_check,38.5 -10,caesar_cipher,64.7 -11,caesar_cipher,64.7 -12,caesar_cipher,64.7 -13,caesar_cipher,64.7 -14,caesar_cipher,64.7 -15,caesar_cipher,64.7 -16,caesar_cipher,64.7 -17,caesar_cipher,64.7 -18,caesar_cipher,64.7 -19,caesar_cipher,64.7 -20,check_armstrong,93.5 -21,check_armstrong,93.5 -22,check_armstrong,93.5 -23,check_armstrong,93.5 -24,check_armstrong,93.5 -25,check_armstrong,93.5 -26,check_armstrong,93.5 -27,check_armstrong,93.5 -28,check_armstrong,93.5 -29,check_armstrong,93.5 -30,common_divisor_count,80.9 -31,common_divisor_count,80.9 -32,common_divisor_count,80.9 -33,common_divisor_count,80.9 -34,common_divisor_count,80.9 -35,common_divisor_count,80.9 -36,common_divisor_count,80.9 -37,common_divisor_count,80.9 -38,common_divisor_count,80.9 -39,common_divisor_count,80.9 -40,exponentiation,71.4 -41,exponentiation,71.4 -42,exponentiation,71.4 -43,exponentiation,71.4 -44,exponentiation,71.4 -45,exponentiation,71.4 -46,exponentiation,71.4 -47,exponentiation,71.4 -48,exponentiation,71.4 -49,exponentiation,71.4 -50,gcd,60.9 -51,gcd,60.9 -52,gcd,60.9 -53,gcd,60.9 -54,gcd,60.9 -55,gcd,60.9 -56,gcd,60.9 -57,gcd,60.9 -58,gcd,60.9 -59,gcd,60.9 -60,longest_substring,69.6 -61,longest_substring,69.6 -62,longest_substring,69.6 -63,longest_substring,69.6 -64,longest_substring,69.6 -65,longest_substring,69.6 -66,longest_substring,69.6 -67,longest_substring,69.6 -68,longest_substring,69.6 -69,longest_substring,69.6 -70,rabin_karp,50.9 -71,rabin_karp,50.9 -72,rabin_karp,50.9 -73,rabin_karp,50.9 -74,rabin_karp,50.9 -75,rabin_karp,50.9 -76,rabin_karp,50.9 -77,rabin_karp,50.9 -78,rabin_karp,50.9 -79,rabin_karp,50.9 -80,railfence_cipher,86.2 -81,railfence_cipher,86.2 -82,railfence_cipher,86.2 -83,railfence_cipher,86.2 -84,railfence_cipher,86.2 -85,railfence_cipher,86.2 -86,railfence_cipher,86.2 -87,railfence_cipher,86.2 -88,railfence_cipher,86.2 -89,railfence_cipher,86.2 -90,zellers_birthday,65.0 -91,zellers_birthday,65.0 -92,zellers_birthday,65.0 -93,zellers_birthday,65.0 -94,zellers_birthday,65.0 -95,zellers_birthday,65.0 -96,zellers_birthday,65.0 -97,zellers_birthday,65.0 -98,zellers_birthday,65.0 -99,zellers_birthday,65.0 +0,anagram_check,16.7 +1,anagram_check,0.0 +2,anagram_check,22.2 +3,anagram_check,18.2 +4,anagram_check,14.3 +5,anagram_check,18.2 +6,anagram_check,30.0 +7,anagram_check,20.0 +8,anagram_check,18.2 +9,anagram_check,27.3 +10,caesar_cipher,61.5 +11,caesar_cipher,60.0 +12,caesar_cipher,66.7 +13,caesar_cipher,61.5 +14,caesar_cipher,60.9 +15,caesar_cipher,66.7 +16,caesar_cipher,61.5 +17,caesar_cipher,63.0 +18,caesar_cipher,59.1 +19,caesar_cipher,63.0 +20,check_armstrong,85.0 +21,check_armstrong,91.7 +22,check_armstrong,92.3 +23,check_armstrong,91.7 +24,check_armstrong,85.7 +25,check_armstrong,87.5 +26,check_armstrong,92.9 +27,check_armstrong,90.0 +28,check_armstrong,87.5 +29,check_armstrong,87.5 +30,common_divisor_count,65.6 +31,common_divisor_count,74.3 +32,common_divisor_count,73.7 +33,common_divisor_count,67.6 +34,common_divisor_count,77.1 +35,common_divisor_count,75.0 +36,common_divisor_count,76.5 +37,common_divisor_count,72.2 +38,common_divisor_count,70.3 +39,common_divisor_count,70.3 +40,exponentiation,68.0 +41,exponentiation,68.8 +42,exponentiation,70.0 +43,exponentiation,78.3 +44,exponentiation,78.6 +45,exponentiation,65.4 +46,exponentiation,60.0 +47,exponentiation,65.0 +48,exponentiation,69.2 +49,exponentiation,61.5 +50,gcd,47.4 +51,gcd,47.4 +52,gcd,50.0 +53,gcd,43.8 +54,gcd,44.4 +55,gcd,45.0 +56,gcd,43.8 +57,gcd,36.8 +58,gcd,44.4 +59,gcd,43.8 +60,longest_substring,88.2 +61,longest_substring,77.8 +62,longest_substring,93.8 +63,longest_substring,84.2 +64,longest_substring,87.5 +65,longest_substring,77.8 +66,longest_substring,84.2 +67,longest_substring,76.5 +68,longest_substring,81.2 +69,longest_substring,78.9 +70,rabin_karp,63.9 +71,rabin_karp,60.9 +72,rabin_karp,65.0 +73,rabin_karp,68.9 +74,rabin_karp,64.4 +75,rabin_karp,66.7 +76,rabin_karp,63.0 +77,rabin_karp,64.4 +78,rabin_karp,63.6 +79,rabin_karp,64.3 +80,railfence_cipher,90.0 +81,railfence_cipher,87.3 +82,railfence_cipher,89.6 +83,railfence_cipher,90.0 +84,railfence_cipher,88.4 +85,railfence_cipher,86.5 +86,railfence_cipher,92.5 +87,railfence_cipher,89.9 +88,railfence_cipher,90.8 +89,railfence_cipher,91.2 +90,zellers_birthday,63.6 +91,zellers_birthday,69.1 +92,zellers_birthday,68.6 +93,zellers_birthday,66.3 +94,zellers_birthday,71.4 +95,zellers_birthday,69.9 +96,zellers_birthday,67.4 +97,zellers_birthday,68.4 +98,zellers_birthday,65.2 +99,zellers_birthday,68.7 diff --git a/out/mutation_scores.png b/out/mutation_scores.png index cc82e2f..87f9497 100644 Binary files a/out/mutation_scores.png and b/out/mutation_scores.png differ diff --git a/out/mutation_scores_mean.png b/out/mutation_scores_mean.png index bb87989..22cfff0 100644 Binary files a/out/mutation_scores_mean.png and b/out/mutation_scores_mean.png differ diff --git a/out/stats.csv b/out/stats.csv index b4b01a7..18ad930 100644 --- a/out/stats.csv +++ b/out/stats.csv @@ -1,11 +1,11 @@ file,fuzzer,genetic,cohen-d,interpretation,wilcoxon -anagram_check,23.1,38.5,inf,Huge,0.001953125 -caesar_cipher,58.8,64.7,inf,Huge,0.001953125 -check_armstrong,90.3,93.5,inf,Huge,0.001953125 -common_divisor_count,72.3,80.9,inf,Huge,0.001953125 -exponentiation,71.4,71.4,inf,Huge,1.0 -gcd,47.8,60.9,inf,Huge,0.001953125 -longest_substring,82.6,69.6,inf,Huge,0.001953125 -rabin_karp,64.9,50.9,inf,Huge,0.001953125 -railfence_cipher,89.4,86.2,inf,Huge,0.001953125 -zellers_birthday,68.3,65.0,inf,Huge,0.001953125 +anagram_check,23.16,18.509999999999998,-0.569029291867328,Very small,0.05263321233144818 +caesar_cipher,60.17999999999999,62.39,0.4672462236206022,Medium,0.35895143585262634 +check_armstrong,89.53999999999999,89.17999999999999,-0.14272435323355917,Very small,0.625 +common_divisor_count,71.21000000000001,72.26,0.25955481074139225,Medium,0.556640625 +exponentiation,68.99,68.47999999999999,-0.09904987594430334,Very small,0.76953125 +gcd,50.8,44.67999999999999,-1.0306023047883075,Very small,0.06654572134371614 +longest_substring,83.96000000000001,83.01,-0.15469347200289738,Very small,0.845703125 +rabin_karp,66.15,64.51,-0.45973880268318706,Very small,0.3080632299071987 +railfence_cipher,90.28,89.62,-0.3514153148238166,Very small,0.375 +zellers_birthday,69.1,67.86,-0.5598449297371694,Very small,0.18514372415787317 diff --git a/tests/test_anagram_check.py b/tests/test_anagram_check.py index f74f0d6..820cfe5 100644 --- a/tests/test_anagram_check.py +++ b/tests/test_anagram_check.py @@ -3,17 +3,12 @@ from benchmark.anagram_check import anagram_check class Test_anagram_check(TestCase): - # distances_true = {1: [0], 2: [0]} - # distances_false = {1: [1], 2: [1]} - def test_anagram_check_1(self): - assert anagram_check(s1='/', s2='6') == False - - # distances_true = {1: [1], 3: [1], 4: [0]} - # distances_false = {1: [0], 3: [0], 4: [1]} - def test_anagram_check_2(self): - assert anagram_check(s1='', s2='') == True - # distances_true = {1: [1], 3: [0]} # distances_false = {1: [0], 3: [1]} - def test_anagram_check_3(self): - assert anagram_check(s1='md', s2='p') == False + def test_anagram_check_1(self): + assert anagram_check(s1='/O', s2='#') == False + + # distances_true = {1: [0], 2: [0]} + # distances_false = {1: [1], 2: [1]} + def test_anagram_check_2(self): + assert anagram_check(s1='G', s2='2') == False diff --git a/tests/test_caesar_cipher.py b/tests/test_caesar_cipher.py index ac2c7fb..b7bb31c 100644 --- a/tests/test_caesar_cipher.py +++ b/tests/test_caesar_cipher.py @@ -4,14 +4,14 @@ from benchmark.caesar_cipher import decrypt class Test_encrypt(TestCase): - # distances_true = {1: [0, 0, 0, 0, 40, 0, 31, 22]} - # distances_false = {1: [33, 14, 23, 29, 0, 28, 0, 0]} + # distances_true = {1: [0, 19, 0, 0, 0, 0]} + # distances_false = {1: [66, 0, 3, 31, 33, 53]} def test_encrypt_1(self): - assert encrypt(strng='vclr.q7@', key=41) == '@-6