From b76e252f3c99ccf0ee03b3e85d59a1c8631b1dba Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Sat, 9 Dec 2023 11:56:23 +0100 Subject: [PATCH] cose --- benchmark/railfence_cipher.py | 1 - fuzzer.py | 91 ++-- genetic.py | 138 ++++++ instrument.py | 131 +----- tests/anagram_check_instrumented.py | 203 ++++---- tests/cd_count_instrumented.py | 203 ++++---- tests/check_armstrong_instrumented.py | 496 ++++++++++---------- tests/decrypt_instrumented.py | 200 ++++---- tests/encrypt_instrumented.py | 200 ++++---- tests/exponentiation_instrumented.py | 200 ++++---- tests/gcd_instrumented.py | 200 ++++---- tests/longest_sorted_substr_instrumented.py | 200 ++++---- tests/rabin_karp_search_instrumented.py | 203 ++++---- tests/raildecrypt_instrumented.py | 200 ++++---- tests/railencrypt_instrumented.py | 200 ++++---- tests/zeller_instrumented.py | 200 ++++---- 16 files changed, 1559 insertions(+), 1507 deletions(-) create mode 100644 genetic.py diff --git a/benchmark/railfence_cipher.py b/benchmark/railfence_cipher.py index 56dedd7..0408ae3 100644 --- a/benchmark/railfence_cipher.py +++ b/benchmark/railfence_cipher.py @@ -1,6 +1,5 @@ # Based on https://github.com/AllAlgorithms, python/algorithms/math/railfence_cipher.py - def railencrypt(st: str, k: int) -> str: assert k > 1 c = 0 diff --git a/fuzzer.py b/fuzzer.py index 489a491..cc5b42f 100644 --- a/fuzzer.py +++ b/fuzzer.py @@ -1,7 +1,9 @@ -from random import randrange, choice, random import os -from frozendict import frozendict +from random import randrange, choice, random +from typing import Callable + import tqdm +from frozendict import frozendict from instrument import load_benchmark, Arg, Params, functions, invoke, call_statement, BranchTransformer, module_of @@ -60,11 +62,14 @@ def random_mutate(arg_type: str, arg_value: any) -> any: prob = 1.0 / len(arg_value) for pos in range(len(arg_value)): if random() < prob: + arg_value = list(arg_value) arg_value[pos] = random_chr() + arg_value = "".join(arg_value) return arg_value elif arg_type == 'int': - return random_int() # TODO: ask what to do here + delta = randrange(-10, 10) + return arg_value + delta else: raise ValueError(f"Arg type '{arg_type}' not supported") @@ -103,20 +108,43 @@ def get_pool(arguments: list[Arg]) -> set[Params]: return set([frozendict({arg_names[i]: p for i, p in enumerate(param)}) for param in pools[arg_types]]) -def get_test_cases(f_name: str, arguments: list[Arg], n: int) -> set[Params]: +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])) + + +def crossover(chosen_test: Params, other_chosen_test: Params, arguments: list[Arg]) -> tuple[Params, Params]: + # Select a property at random and swap properties + arg_name = choice(list(chosen_test.keys())) + types: dict[str, str] = {arg_name: arg_type for arg_name, arg_type in arguments} + if types[arg_name] == 'str': + # Crossover for strings intermingles the strings of the two chosen tests + s1, s2 = str_crossover(chosen_test[arg_name], other_chosen_test[arg_name]) + t1 = chosen_test.set(arg_name, s1) + t2 = other_chosen_test.set(arg_name, s2) + + else: # types[arg_name] == 'int' + # Crossover for integers swaps the values from the two tests + i1, i2 = chosen_test[arg_name], other_chosen_test[arg_name] + t1 = chosen_test.set(arg_name, i1) + t2 = other_chosen_test.set(arg_name, i2) + + return t1, t2 + + +def get_test_cases(f_name: str, arguments: list[Arg], n: int, enable_bar=True) -> set[Params]: assert n >= 1 pool: set[Params] = get_pool(arguments) pool_list = list(pool) tests: set[Params] = set() - types: dict[str, str] = {arg_name: arg_type for arg_name, arg_type in arguments} n = min(n, max_cases(arguments) // 3) # bound n by 1/3rd of the max possible number of tests - with ((tqdm.tqdm(total=n, desc=f"Tests for {BranchTransformer.to_original_name(f_name)}") as pbar)): - def consider_test_case(params: dict[str, any]): - t = frozendict(params) - + with tqdm.tqdm(total=n, desc=f"Tests for {BranchTransformer.to_original_name(f_name)}", + disable=not enable_bar) as pbar: + def consider_test_case(t: Params): if t not in pool: pool.add(t) pool_list.append(t) @@ -131,34 +159,21 @@ def get_test_cases(f_name: str, arguments: list[Arg], n: int) -> set[Params]: pbar.update() while len(tests) < n: - chosen_test: dict[str, any] = dict(choice(pool_list)) + chosen_test: Params = choice(pool_list) kind = choice(['pool', 'mutation', 'crossover']) if kind == 'mutation': - arg_name = choice(list(chosen_test.keys())) # choose name to mutate - chosen_test[arg_name] = random_mutate(types[arg_name], chosen_test[arg_name]) - - consider_test_case(chosen_test) + consider_test_case(mutate(chosen_test, arguments)) elif kind == 'crossover': - # Select a property at random and swap properties - arg_name = choice(list(chosen_test.keys())) - # pick other distinct sample - other_chosen_test: dict[str, any] = chosen_test - while frozendict(chosen_test) == frozendict(other_chosen_test): - other_chosen_test = dict(choice(pool_list)) + while True: + other_chosen_test: Params = choice(pool_list) + if frozendict(chosen_test) != frozendict(other_chosen_test): + break - if types[arg_name] == 'str': - # Crossover for strings intermingles the strings of the two chosen tests - chosen_test[arg_name], other_chosen_test[arg_name] = \ - str_crossover(chosen_test[arg_name], other_chosen_test[arg_name]) - else: # types[arg_name] == 'int' - # Crossover for integers swaps the values from the two tests - chosen_test[arg_name], other_chosen_test[arg_name] = \ - other_chosen_test[arg_name], chosen_test[arg_name] - - consider_test_case(chosen_test) - consider_test_case(other_chosen_test) + t1, t2 = crossover(chosen_test, other_chosen_test, arguments) + consider_test_case(t1) + consider_test_case(t2) else: consider_test_case(chosen_test) @@ -167,7 +182,7 @@ def get_test_cases(f_name: str, arguments: list[Arg], n: int) -> set[Params]: def str_crossover(parent1: str, parent2: str): if len(parent1) > 1 and len(parent2) > 1: - pos = randrange(1, len(parent1) - 1) + pos = randrange(1, len(parent1)) offspring1 = parent1[:pos] + parent2[pos:] offspring2 = parent2[:pos] + parent1[pos:] return offspring1, offspring2 @@ -177,7 +192,9 @@ def str_crossover(parent1: str, parent2: str): def get_test_case_source(f_name: str, test_case: Params, i: int, indent: int): f_name_orig = BranchTransformer.to_original_name(f_name) - space = " " * (4 * indent) + + single_indent = " " * 4 + space = single_indent * indent output = invoke(f_name, test_case) @@ -185,15 +202,14 @@ def get_test_case_source(f_name: str, test_case: Params, i: int, indent: int): output = f"'{output}'" return f"""{space}def test_{f_name_orig}_{i}(self): -{space} assert {call_statement(f_name_orig, test_case)} == {output}""" +{space}{single_indent}assert {call_statement(f_name_orig, test_case)} == {output}""" -def get_test_class(f_name: str, n_tests: int) -> str: +def get_test_class(f_name: str, case: set[Params]) -> str: f_name_orig = BranchTransformer.to_original_name(f_name) test_class = (f"from unittest import TestCase\n\nfrom {module_of[f_name]} import {f_name_orig}\n\n\n" f"class Test_{f_name_orig}(TestCase):\n") - cases = get_test_cases(f_name, functions[f_name], n_tests) test_class += "\n\n".join([get_test_case_source(f_name, case, i + 1, 1) for i, case in enumerate(cases)]) return test_class @@ -206,7 +222,8 @@ def main(): for f_name in functions.keys(): with open(os.path.join(OUT_DIR, f_name + ".py"), "w") as f: - f.write(get_test_class(f_name, 100)) + cases = get_test_cases(f_name, functions[f_name], 100) + f.write(get_test_class(f_name, cases)) if __name__ == '__main__': diff --git a/genetic.py b/genetic.py new file mode 100644 index 0000000..a1728e5 --- /dev/null +++ b/genetic.py @@ -0,0 +1,138 @@ +import os +from typing import Callable + +from deap import creator, base, tools, algorithms + +import fuzzer +import instrument +from fuzzer import get_test_cases, get_test_class +import frozendict + +INDMUPROB = 0.05 +MUPROB = 0.1 +CXPROB = 0.5 +TOURNSIZE = 3 +NPOP = 300 +NGEN = 200 +REPS = 10 + +to_test: str = "" + +OUT_DIR = os.path.join(os.path.dirname(__file__), "tests") + + +def normalize(x): + return x / (1.0 + x) + + +def get_test_case_generator(f_name: str, arguments: list[instrument.Arg]) -> Callable[[], list]: + return lambda: list(list(get_test_cases(f_name, arguments, 1, enable_bar=False))[0].items()) + + +def generate(f_name: str): + global to_test + to_test = f_name + + creator.create("Fitness", base.Fitness, weights=(-1.0,)) + creator.create("Individual", list, fitness=creator.Fitness) + + n_initial = 10 + + args = instrument.functions[f_name] + + toolbox = base.Toolbox() + toolbox.register("attr_test_case", get_test_case_generator(to_test, instrument.functions[to_test])) + toolbox.register("individual", + tools.initRepeat, + creator.Individual, + toolbox.attr_test_case, + n=n_initial) + toolbox.register("population", + tools.initRepeat, + list, + toolbox.individual) + toolbox.register("evaluate", fitness) + + def mate(tc1, tc2): + t1, t2 = frozendict.frozendict(tc1), frozendict.frozendict(tc2) + + print("ticino", tc1, tc2) + o1, o2 = fuzzer.crossover(t1, t2, args) + i1, i2 = creator.Individual(o1.items()), creator.Individual(o2.items()) + print("mate", i1, i2) + return i1, i2 + + def mutate(tc): + t = frozendict.frozendict(tc) + o = fuzzer.mutate(t, args) + i1 = creator.Individual(o.items()) + print("mutate", i1) + return i1, + + toolbox.register("mate", mate) + toolbox.register("mutate", mutate) + toolbox.register("select", tools.selTournament, tournsize=TOURNSIZE) + + coverage = [] + for i in range(REPS): + instrument.archive_true_branches = {} + instrument.archive_false_branches = {} + population = toolbox.population(n=NPOP) + print("population", population) + algorithms.eaSimple(population, toolbox, CXPROB, MUPROB, NGEN, verbose=False) + cov = len(instrument.archive_true_branches) + len(instrument.archive_false_branches) + print(cov, instrument.archive_true_branches, instrument.archive_false_branches) + coverage.append(cov) + + print(coverage) + + +def fitness(individuals: list[list]) -> tuple[float]: + range_start, range_end = instrument.n_of_branches[to_test] + + # Reset any distance values from previous executions + instrument.distances_true = {} + instrument.distances_false = {} + + fitness = 0.0 + for individual in individuals: + x = frozendict.frozendict(individual) + + # Run the function under test + try: + out = instrument.invoke(to_test, x) + except AssertionError: + print(to_test, x, "=", "[FAILS]") + return 10000, + + # Sum up branch distances + for branch in range(range_start, range_end): + if branch in instrument.distances_true: + if instrument.distances_true[branch] == 0 and branch not in instrument.archive_true_branches: + instrument.archive_true_branches[branch] = x + if branch not in instrument.archive_true_branches: + fitness += normalize(instrument.distances_true[branch]) + for branch in range(range_start, range_end): + if branch in instrument.distances_false: + if instrument.distances_false[branch] == 0 and branch not in instrument.archive_false_branches: + instrument.archive_false_branches[branch] = x + if branch not in instrument.archive_false_branches: + fitness += normalize(instrument.distances_false[branch]) + print(to_test, x, "=", out) + + print("fitness", fitness) + print() + return fitness, + + +def main(): + instrument.load_benchmark(save_instrumented=False) # instrument all files in benchmark + f_name = "railencrypt_instrumented" + generate(f_name) + with open(os.path.join(OUT_DIR, f_name + ".py"), "w") as f: + cases = get_test_cases(f_name, instrument.functions[f_name], 100) + f.write(get_test_class(f_name, cases)) + + +if __name__ == '__main__': + main() diff --git a/instrument.py b/instrument.py index e4823dc..227b3d2 100644 --- a/instrument.py +++ b/instrument.py @@ -8,21 +8,9 @@ import ast import astunparse import sys import random -from deap import creator, base, tools, algorithms from operators import compute_distances # hyperparameters -NPOP = 300 -NGEN = 200 -INDMUPROB = 0.05 -MUPROB = 0.1 -CXPROB = 0.5 -TOURNSIZE = 3 -LOW = -1000 -UP = 1000 -REPS = 10 -MAX_STRING_LENGTH = 10 - ROOT_DIR: str = os.path.dirname(__file__) IN_DIR: str = os.path.join(ROOT_DIR, 'benchmark') OUT_DIR: str = os.path.join(ROOT_DIR, 'instrumented') @@ -30,12 +18,14 @@ SUFFIX: str = "_instrumented" distances_true: dict[int, int] = {} distances_false: dict[int, int] = {} -branches: list[int] = [1, 2, 3, 4, 5] -archive_true_branches: dict[int, str] = {} -archive_false_branches: dict[int, str] = {} + +# Archive of solutions +archive_true_branches: dict[int, any] = {} +archive_false_branches: dict[int, any] = {} class BranchTransformer(ast.NodeTransformer): + branches_range: dict[str, tuple[int, int]] branch_num: int instrumented_name: Optional[str] in_assert: bool @@ -46,6 +36,7 @@ class BranchTransformer(ast.NodeTransformer): self.instrumented_name = None self.in_assert = False self.in_return = False + self.branches_range = {} @staticmethod def to_instrumented_name(name: str): @@ -70,8 +61,10 @@ class BranchTransformer(ast.NodeTransformer): def visit_FunctionDef(self, ast_node): self.instrumented_name = ast_node.name + b_start = self.branch_num ast_node.name = BranchTransformer.to_instrumented_name(ast_node.name) inner_node = self.generic_visit(ast_node) + self.branches_range[ast_node.name] = (b_start, self.branch_num) self.instrumented_name = None return inner_node @@ -130,122 +123,30 @@ def evaluate_condition(num, op, lhs, rhs): # type: ignore return distance_true == 0 -def normalize(x): - return x / (1.0 + x) - - -def get_fitness_cgi(individual): - x = individual[0] - # Reset any distance values from previous executions - global distances_true, distances_false - global branches, archive_true_branches, archive_false_branches - distances_true = {} - distances_false = {} - - # TODO: fix this - # Run the function under test - # try: - # cgi_decode_instrumented(x) - # except BaseException: - # pass - - # Sum up branch distances - fitness = 0.0 - for branch in branches: - if branch in distances_true: - if distances_true[branch] == 0 and branch not in archive_true_branches: - archive_true_branches[branch] = x - if branch not in archive_true_branches: - fitness += normalize(distances_true[branch]) - for branch in branches: - if branch in distances_false: - if distances_false[branch] == 0 and branch not in archive_false_branches: - archive_false_branches[branch] = x - if branch not in archive_false_branches: - fitness += normalize(distances_false[branch]) - - return fitness, - - -def random_string(): - length = random.randint(0, MAX_STRING_LENGTH) - s = "" - for i in range(length): - random_character = chr(random.randrange(32, 127)) - s = s + random_character - return s - - -def crossover(individual1, individual2): - parent1 = individual1[0] - parent2 = individual2[0] - if len(parent1) > 1 and len(parent2) > 1: - pos = random.randint(1, len(parent1)) - offspring1 = parent1[:pos] + parent2[pos:] - offspring2 = parent2[:pos] + parent1[pos:] - individual1[0] = offspring1 - individual2[0] = offspring2 - - return individual1, individual2 - - -def mutate(individual): - chromosome = individual[0] - mutated = chromosome[:] - if len(mutated) > 0: - prob = 1.0 / len(mutated) - for pos in range(len(mutated)): - if random.random() < prob: - new_c = chr(random.randrange(32, 127)) - mutated = mutated[:pos] + new_c + mutated[pos + 1:] - individual[0] = mutated - return individual, - - -def generate(): - global archive_true_branches, archive_false_branches - - creator.create("Fitness", base.Fitness, weights=(-1.0,)) - creator.create("Individual", list, fitness=creator.Fitness) - - toolbox = base.Toolbox() - toolbox.register("attr_str", random_string) - toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_str, n=1) - toolbox.register("population", tools.initRepeat, list, toolbox.individual) - toolbox.register("evaluate", get_fitness_cgi) - toolbox.register("mate", crossover) - toolbox.register("mutate", mutate) - toolbox.register("select", tools.selTournament, tournsize=TOURNSIZE) - - coverage = [] - for i in range(REPS): - archive_true_branches = {} - archive_false_branches = {} - population = toolbox.population(n=NPOP) - algorithms.eaSimple(population, toolbox, CXPROB, MUPROB, NGEN, verbose=False) - cov = len(archive_true_branches) + len(archive_false_branches) - print(cov, archive_true_branches, archive_false_branches) - coverage.append(cov) - - ArgType = str Arg = tuple[str, ArgType] Params = frozendict[str, any] SignatureDict = dict[str, list[Arg]] +n_of_branches: dict[str, tuple[int, int]] = {} functions: SignatureDict = {} module_of: dict[str, str] = {} def instrument(source_path: str, target_path: str, save_instrumented=True): - global functions + global functions, n_of_branches with open(source_path, "r") as f: source = f.read() node = ast.parse(source) # print(ast.dump(node, indent=2)) - BranchTransformer().visit(node) + b = BranchTransformer() + b.visit(node) + + for f_name, limits in b.branches_range.items(): + n_of_branches[f_name] = limits + node = ast.fix_missing_locations(node) # Make sure the line numbers are ok before printing if save_instrumented: diff --git a/tests/anagram_check_instrumented.py b/tests/anagram_check_instrumented.py index 7556f23..670ef65 100644 --- a/tests/anagram_check_instrumented.py +++ b/tests/anagram_check_instrumented.py @@ -5,301 +5,304 @@ from benchmark.anagram_check import anagram_check class Test_anagram_check(TestCase): def test_anagram_check_1(self): - assert anagram_check(s1='yplc', s2='ycq') == False + assert anagram_check(s1='', s2='3Q%H8e') == False def test_anagram_check_2(self): - assert anagram_check(s1='ecw', s2='oyhf') == False + assert anagram_check(s1='V>tI-vq', s2='2UFU.J@W1') == False def test_anagram_check_3(self): - assert anagram_check(s1='zldep', s2='zhjknjbzs') == False + assert anagram_check(s1='F'', s2='W>5') == False def test_anagram_check_4(self): - assert anagram_check(s1='vhvz', s2='ai') == False + assert anagram_check(s1='(E7/~', s2='k\*'k+w|W') == False def test_anagram_check_5(self): - assert anagram_check(s1='c', s2='') == False + assert anagram_check(s1='{.HDvB;K', s2='U]') == False def test_anagram_check_6(self): - assert anagram_check(s1='zuampazf', s2='kfmaiwhko') == False + assert anagram_check(s1='o', s2=';_~E,') == False def test_anagram_check_7(self): - assert anagram_check(s1='evsvfovko', s2='hauhpmt') == False + assert anagram_check(s1='P2Q', s2='') == False def test_anagram_check_8(self): - assert anagram_check(s1='gqkbyu', s2='gjeg') == False + assert anagram_check(s1='"G', s2=',+IY/') == False def test_anagram_check_9(self): - assert anagram_check(s1='y', s2='yduqc') == False + assert anagram_check(s1='CD[,W^"{M', s2='DYpw') == False def test_anagram_check_10(self): - assert anagram_check(s1='pgllzt', s2='hjq') == False + assert anagram_check(s1='1', s2='GKGn') == False def test_anagram_check_11(self): - assert anagram_check(s1='grxyqmu', s2='e') == False + assert anagram_check(s1='8B=zA9TN,', s2='~') == False def test_anagram_check_12(self): - assert anagram_check(s1='', s2='jp') == False + assert anagram_check(s1='p,', s2='') == False def test_anagram_check_13(self): - assert anagram_check(s1='rbqs', s2='khdwq') == False + assert anagram_check(s1='DU?Y', s2='r') == False def test_anagram_check_14(self): - assert anagram_check(s1='eecze', s2='g') == False + assert anagram_check(s1='f', s2='p{C-`Pq6T') == False def test_anagram_check_15(self): - assert anagram_check(s1='fymazhw', s2='qja') == False + assert anagram_check(s1='{M?/I', s2='#HxX') == False def test_anagram_check_16(self): - assert anagram_check(s1='', s2='zjslnlgb') == False + assert anagram_check(s1='*w', s2='LO-SW') == False def test_anagram_check_17(self): - assert anagram_check(s1='de', s2='thvvqoyx') == False + assert anagram_check(s1=''', s2='@y') == False def test_anagram_check_18(self): - assert anagram_check(s1='gqpctlvm', s2='') == False + assert anagram_check(s1='', s2='}Q') == False def test_anagram_check_19(self): - assert anagram_check(s1='', s2='y') == False + assert anagram_check(s1='Aen"W!y', s2='7,T ') == False def test_anagram_check_20(self): - assert anagram_check(s1='qkh', s2='vuwl') == False + assert anagram_check(s1='+pv', s2='"lR') == False def test_anagram_check_21(self): - assert anagram_check(s1='t', s2='t') == True + assert anagram_check(s1='|e#z|', s2='C'spOA,U') == False def test_anagram_check_22(self): - assert anagram_check(s1='jt', s2='ivx') == False + assert anagram_check(s1='+ov', s2='"lR') == False def test_anagram_check_23(self): - assert anagram_check(s1='v', s2='xuif') == False + assert anagram_check(s1='j(c@76t', s2='((') == False def test_anagram_check_24(self): - assert anagram_check(s1='', s2='afxe') == False + assert anagram_check(s1='kjCu #-FR', s2='u') == False def test_anagram_check_25(self): - assert anagram_check(s1='yjgvhbu', s2='itcww') == False + assert anagram_check(s1='{5', s2='7m;') == False def test_anagram_check_26(self): - assert anagram_check(s1='opw', s2='') == False + assert anagram_check(s1='|d+.OH', s2='P') == False def test_anagram_check_27(self): - assert anagram_check(s1='ynowvxbwt', s2='ofaunfn') == False + assert anagram_check(s1='%|K2&&*', s2='M; X') == False def test_anagram_check_28(self): - assert anagram_check(s1='vnx', s2='g') == False + assert anagram_check(s1='', s2='kF7J6Q\=G') == False def test_anagram_check_29(self): - assert anagram_check(s1='kgc', s2='vjwbqnzn') == False + assert anagram_check(s1='I:2y_pj"', s2='_'G') == False def test_anagram_check_30(self): - assert anagram_check(s1='e', s2='pf') == False + assert anagram_check(s1='Z)R"Qb8', s2=']T.\3(x') == False def test_anagram_check_31(self): - assert anagram_check(s1='imvqj', s2='kpfcfxga') == False + assert anagram_check(s1='^y1gH)jvp', s2='(Y1vpvfv') == False def test_anagram_check_32(self): - assert anagram_check(s1='wiespjdeo', s2='') == False + assert anagram_check(s1='W', s2='1e7') == False def test_anagram_check_33(self): - assert anagram_check(s1='jgi', s2='kl') == False + assert anagram_check(s1='Nj(}%', s2='m{|c8=a') == False def test_anagram_check_34(self): - assert anagram_check(s1='nylvfden', s2='kuihzw') == False + assert anagram_check(s1='B/mqTkzy]', s2='_'TX\U') == False def test_anagram_check_73(self): - assert anagram_check(s1='eb', s2='zzrnoog') == False + assert anagram_check(s1=' z{'wm04', s2='GDQQe'kK') == False def test_anagram_check_74(self): - assert anagram_check(s1='is', s2='oiwp') == False + assert anagram_check(s1='BnET', s2='xYmH}Dm') == False def test_anagram_check_75(self): - assert anagram_check(s1='gcpr', s2='bxto') == False + assert anagram_check(s1='Z)R"Qb8', s2=']{C,E') == False def test_anagram_check_76(self): - assert anagram_check(s1='js', s2='ocpiiox') == False + assert anagram_check(s1='Rn1]', s2=']') == False def test_anagram_check_77(self): - assert anagram_check(s1='ze', s2='vdp') == False + assert anagram_check(s1='FN', s2='qQ7h'.n') == False def test_anagram_check_78(self): - assert anagram_check(s1='zpmr', s2='lrvyck') == False + assert anagram_check(s1='', s2='7') == False def test_anagram_check_79(self): - assert anagram_check(s1='m', s2='xy') == False + assert anagram_check(s1=''Cc';sX', s2='PA%') == False def test_anagram_check_80(self): - assert anagram_check(s1='gdludomrk', s2='utrjdnvtk') == False + assert anagram_check(s1='Q#9KVEZ', s2='-/^S0;]/') == False def test_anagram_check_81(self): - assert anagram_check(s1='dwns', s2='ftdv') == False + assert anagram_check(s1='', s2=',') == False def test_anagram_check_82(self): - assert anagram_check(s1='iiimynmts', s2='cjft') == False + assert anagram_check(s1='#7(,v{\{J', s2='6S$~h?') == False def test_anagram_check_83(self): - assert anagram_check(s1='g', s2='vdoa') == False + assert anagram_check(s1='_D,x4b', s2='ALY') == False def test_anagram_check_84(self): - assert anagram_check(s1='ilpqxrck', s2='znolqmjlw') == False + assert anagram_check(s1='_8^4amA', s2=']f4') == False def test_anagram_check_85(self): - assert anagram_check(s1='', s2='zzrnoog') == False + assert anagram_check(s1='tC@H{=G', s2='u1;)') == False def test_anagram_check_86(self): - assert anagram_check(s1='jdfpwvy', s2='') == False + assert anagram_check(s1='j#', s2='q)7(') == False def test_anagram_check_87(self): - assert anagram_check(s1='syad', s2='') == False + assert anagram_check(s1='zy!ob:llU', s2='Pjf') == False def test_anagram_check_88(self): - assert anagram_check(s1='', s2='vmroguwdi') == False + assert anagram_check(s1='L]c1clT?', s2='') == False def test_anagram_check_89(self): - assert anagram_check(s1='olnymh', s2='ezbivaom') == False + assert anagram_check(s1='Mg:sk(*', s2=';') == False def test_anagram_check_90(self): - assert anagram_check(s1='hlaplylu', s2='lrk') == False + assert anagram_check(s1='rME', s2='^m') == False def test_anagram_check_91(self): - assert anagram_check(s1='vgooctm', s2='zzrnoog') == False + assert anagram_check(s1='0e:JCRNB', s2='mh:?3rb') == False def test_anagram_check_92(self): - assert anagram_check(s1='f', s2='feaj') == False + assert anagram_check(s1='~.njBt/Pr', s2='%w5PP/@oY') == False def test_anagram_check_93(self): - assert anagram_check(s1='obhxgd', s2='') == False + assert anagram_check(s1=' z;(6@09', s2='.=') == False def test_anagram_check_94(self): - assert anagram_check(s1='copxl', s2='mycb') == False + assert anagram_check(s1='', s2='}*%C^hI') == False def test_anagram_check_95(self): - assert anagram_check(s1='l', s2='x') == False + assert anagram_check(s1='+_prg', s2='atD' def test_longest_sorted_substr_15(self): - assert longest_sorted_substr(s='jcubqguw') == 'guw' + assert longest_sorted_substr(s='s') == 's' def test_longest_sorted_substr_16(self): - assert longest_sorted_substr(s='bfosuwy') == 'bfosuwy' + assert longest_sorted_substr(s='{EX_?r*M$') == 'EX_' def test_longest_sorted_substr_17(self): - assert longest_sorted_substr(s='mxponpls') == 'mx' + assert longest_sorted_substr(s='2@U+0&') == '2@U' def test_longest_sorted_substr_18(self): - assert longest_sorted_substr(s='sr') == 's' + assert longest_sorted_substr(s='Ze') == 'Ze' def test_longest_sorted_substr_19(self): - assert longest_sorted_substr(s='xfsumjg') == 'fsu' + assert longest_sorted_substr(s='{-7R<])') == '-7R' def test_longest_sorted_substr_20(self): - assert longest_sorted_substr(s='wjoq') == 'joq' + assert longest_sorted_substr(s='Mh|') == 'Mh|' def test_longest_sorted_substr_21(self): - assert longest_sorted_substr(s='ngps') == 'gps' + assert longest_sorted_substr(s='ZOk_Zq') == 'Ok' def test_longest_sorted_substr_22(self): - assert longest_sorted_substr(s='szmn') == 'sz' + assert longest_sorted_substr(s='jpb') == 'jp' def test_longest_sorted_substr_23(self): - assert longest_sorted_substr(s='gafni') == 'afn' + assert longest_sorted_substr(s='$') == '$' def test_longest_sorted_substr_24(self): - assert longest_sorted_substr(s='iedhk') == 'dhk' + assert longest_sorted_substr(s='2v7Z') == '2v' def test_longest_sorted_substr_25(self): - assert longest_sorted_substr(s='pr') == 'pr' + assert longest_sorted_substr(s='3NyuK') == '3Ny' def test_longest_sorted_substr_26(self): - assert longest_sorted_substr(s='jmbyfose') == 'fos' + assert longest_sorted_substr(s='Aj3~Y') == 'Aj' def test_longest_sorted_substr_27(self): - assert longest_sorted_substr(s='cg') == 'cg' + assert longest_sorted_substr(s='lgoz}B4A~') == 'goz}' def test_longest_sorted_substr_28(self): - assert longest_sorted_substr(s='li') == 'l' + assert longest_sorted_substr(s='~Dhq', k=883) == '\'H?>Dhq' def test_raildecrypt_79(self): - assert raildecrypt(st='yvq', k=653) == 'yvq' + assert raildecrypt(st='E', k=557) == 'E' def test_raildecrypt_80(self): - assert raildecrypt(st='rrqjdipd', k=295) == 'rrqjdipd' + assert raildecrypt(st='|bD', k=651) == '|bD' def test_raildecrypt_81(self): - assert raildecrypt(st='', k=979) == '' + assert raildecrypt(st='?bb(.`', k=502) == '?bb(.`' def test_raildecrypt_82(self): - assert raildecrypt(st='fb', k=171) == 'fb' + assert raildecrypt(st='{,rXk!3W', k=885) == '{,rXk!3W' def test_raildecrypt_83(self): - assert raildecrypt(st='dvrxkkqv', k=833) == 'dvrxkkqv' + assert raildecrypt(st=' WS`#ov ~', k=189) == ' WS`#ov ~' def test_raildecrypt_84(self): - assert raildecrypt(st='', k=509) == '' + assert raildecrypt(st='-O HB', k=208) == '-O HB' def test_raildecrypt_85(self): - assert raildecrypt(st='rjgljb', k=577) == 'rjgljb' + assert raildecrypt(st='[', k=714) == '[' def test_raildecrypt_86(self): - assert raildecrypt(st='cywbdyyx', k=488) == 'cywbdyyx' + assert raildecrypt(st='Ckmi|', k=14) == 'Ckmi|' def test_raildecrypt_87(self): - assert raildecrypt(st='tuozjmmz', k=501) == 'tuozjmmz' + assert raildecrypt(st='mHbwuB', k=931) == 'mHbwuB' def test_raildecrypt_88(self): - assert raildecrypt(st='fizmdsie', k=274) == 'fizmdsie' + assert raildecrypt(st='_?->'}#', k=388) == '_?->'}#' def test_raildecrypt_89(self): - assert raildecrypt(st='', k=133) == '' + assert raildecrypt(st='', k=454) == '' def test_raildecrypt_90(self): - assert raildecrypt(st='mcci', k=303) == 'mcci' + assert raildecrypt(st='&,+f9p}y>', k=990) == '&,+f9p}y>' def test_raildecrypt_91(self): - assert raildecrypt(st='mihtm', k=31) == 'mihtm' + assert raildecrypt(st='JCXpF', k=726) == 'JCXpF' def test_raildecrypt_92(self): - assert raildecrypt(st='jezuahj', k=995) == 'jezuahj' + assert raildecrypt(st='B', k=350) == 'B' def test_raildecrypt_93(self): - assert raildecrypt(st='julhyxf', k=58) == 'julhyxf' + assert raildecrypt(st='g_=f.B1U', k=960) == 'g_=f.B1U' def test_raildecrypt_94(self): - assert raildecrypt(st='olhwe', k=133) == 'olhwe' + assert raildecrypt(st='Zb', k=614) == 'Zb' def test_raildecrypt_95(self): - assert raildecrypt(st='qzbxekned', k=490) == 'qzbxekned' + assert raildecrypt(st='Y/', k=867) == 'Y/' def test_raildecrypt_96(self): - assert raildecrypt(st='j', k=590) == 'j' + assert raildecrypt(st=''CXpF', k=437) == ''CXpF' def test_raildecrypt_97(self): - assert raildecrypt(st='zje', k=555) == 'zje' + assert raildecrypt(st='X:F', k=695) == 'X:F' def test_raildecrypt_98(self): - assert raildecrypt(st='sdod', k=169) == 'sdod' + assert raildecrypt(st='HR9.T\F#', k=662) == 'HR9.T\F#' def test_raildecrypt_99(self): - assert raildecrypt(st='e', k=95) == 'e' + assert raildecrypt(st='', k=362) == '' def test_raildecrypt_100(self): - assert raildecrypt(st='lido', k=727) == 'lido' \ No newline at end of file + assert raildecrypt(st='', k=360) == '' \ No newline at end of file diff --git a/tests/railencrypt_instrumented.py b/tests/railencrypt_instrumented.py index b35d6b7..6a16de6 100644 --- a/tests/railencrypt_instrumented.py +++ b/tests/railencrypt_instrumented.py @@ -5,301 +5,301 @@ from benchmark.railfence_cipher import railencrypt class Test_railencrypt(TestCase): def test_railencrypt_1(self): - assert railencrypt(st='', k=12) == '' + assert railencrypt(st='FKglwgJ(p', k=840) == 'FKglwgJ(p' def test_railencrypt_2(self): - assert railencrypt(st='rwzcleip', k=680) == 'rwzcleip' + assert railencrypt(st='gvj', k=379) == 'gvj' def test_railencrypt_3(self): - assert railencrypt(st='rwheldzx', k=666) == 'rwheldzx' + assert railencrypt(st='', k=755) == '' def test_railencrypt_4(self): - assert railencrypt(st='', k=821) == '' + assert railencrypt(st='9pS', k=577) == '9pS' def test_railencrypt_5(self): - assert railencrypt(st='idbnrbhwh', k=718) == 'idbnrbhwh' + assert railencrypt(st='`j4z_:S', k=169) == '`j4z_:S' def test_railencrypt_6(self): - assert railencrypt(st='vgh', k=754) == 'vgh' + assert railencrypt(st='? }qW^W', k=892) == '? }qW^W' def test_railencrypt_7(self): - assert railencrypt(st='doo', k=496) == 'doo' + assert railencrypt(st='ns(ob!Pb', k=389) == 'ns(ob!Pb' def test_railencrypt_8(self): - assert railencrypt(st='mryny', k=619) == 'mryny' + assert railencrypt(st='r$&=(', k=427) == 'r$&=(' def test_railencrypt_9(self): - assert railencrypt(st='', k=426) == '' + assert railencrypt(st='2A/L~[%4', k=339) == '2A/L~[%4' def test_railencrypt_10(self): - assert railencrypt(st='xeeqrsmoj', k=245) == 'xeeqrsmoj' + assert railencrypt(st='M>'', k=210) == 'M>'' def test_railencrypt_11(self): - assert railencrypt(st='f', k=358) == 'f' + assert railencrypt(st='=5]'146#', k=143) == '=5]'146#' def test_railencrypt_12(self): - assert railencrypt(st='jnfgdr', k=221) == 'jnfgdr' + assert railencrypt(st='c?g!b', k=675) == 'c?g!b' def test_railencrypt_13(self): - assert railencrypt(st='hrq', k=676) == 'hrq' + assert railencrypt(st='U"i-', k=547) == 'U"i-' def test_railencrypt_14(self): - assert railencrypt(st='q', k=552) == 'q' + assert railencrypt(st='+e[', k=328) == '+e[' def test_railencrypt_15(self): - assert railencrypt(st='rt', k=957) == 'rt' + assert railencrypt(st='@ICWq0.[D', k=944) == '@ICWq0.[D' def test_railencrypt_16(self): - assert railencrypt(st='vrnqfbhd', k=622) == 'vrnqfbhd' + assert railencrypt(st='~a}By', k=141) == '~a}By' def test_railencrypt_17(self): - assert railencrypt(st='', k=496) == '' + assert railencrypt(st='', k=574) == '' def test_railencrypt_18(self): - assert railencrypt(st='ihutvt', k=661) == 'ihutvt' + assert railencrypt(st='#7oR+_$*', k=457) == '#7oR+_$*' def test_railencrypt_19(self): - assert railencrypt(st='iv', k=671) == 'iv' + assert railencrypt(st='/c', k=900) == '/c' def test_railencrypt_20(self): - assert railencrypt(st='djch', k=441) == 'djch' + assert railencrypt(st='r', k=492) == 'r' def test_railencrypt_21(self): - assert railencrypt(st='doo', k=527) == 'doo' + assert railencrypt(st='vh]lR', k=242) == 'vh]lR' def test_railencrypt_22(self): - assert railencrypt(st='p', k=768) == 'p' + assert railencrypt(st='**hH2', k=270) == '**hH2' def test_railencrypt_23(self): - assert railencrypt(st='kft', k=527) == 'kft' + assert railencrypt(st=')>On.', k=70) == ')>On.' def test_railencrypt_24(self): - assert railencrypt(st='tafnzqyuq', k=352) == 'tafnzqyuq' + assert railencrypt(st='djQ*5r_Uk', k=420) == 'djQ*5r_Uk' def test_railencrypt_25(self): - assert railencrypt(st='qmfvr', k=289) == 'qmfvr' + assert railencrypt(st='{+xw', k=405) == '{+xw' def test_railencrypt_26(self): - assert railencrypt(st='pcmyim', k=927) == 'pcmyim' + assert railencrypt(st='RGvx~r', k=976) == 'RGvx~r' def test_railencrypt_27(self): - assert railencrypt(st='vxxgc', k=897) == 'vxxgc' + assert railencrypt(st='<$', k=154) == '<$' def test_railencrypt_28(self): - assert railencrypt(st='gmatyguqw', k=426) == 'gmatyguqw' + assert railencrypt(st=')>On.', k=221) == ')>On.' def test_railencrypt_29(self): - assert railencrypt(st='', k=940) == '' + assert railencrypt(st='IH!=Y`l*', k=885) == 'IH!=Y`l*' def test_railencrypt_30(self): - assert railencrypt(st='cszhjgvt', k=873) == 'cszhjgvt' + assert railencrypt(st='w::L', k=641) == 'w::L' def test_railencrypt_31(self): - assert railencrypt(st='ocbnbj', k=523) == 'ocbnbj' + assert railencrypt(st=')>On.', k=885) == ')>On.' def test_railencrypt_32(self): - assert railencrypt(st='', k=343) == '' + assert railencrypt(st='!CIXRTgh', k=754) == '!CIXRTgh' def test_railencrypt_33(self): - assert railencrypt(st='bugjol', k=786) == 'bugjol' + assert railencrypt(st='?NGYChStM', k=850) == '?NGYChStM' def test_railencrypt_34(self): - assert railencrypt(st='ujqmp', k=446) == 'ujqmp' + assert railencrypt(st=' X$qR?', k=389) == ' X$qR?' def test_railencrypt_35(self): - assert railencrypt(st='ihutvt', k=369) == 'ihutvt' + assert railencrypt(st='dA$PGkO', k=453) == 'dA$PGkO' def test_railencrypt_36(self): - assert railencrypt(st='uc', k=927) == 'uc' + assert railencrypt(st=',gN', k=663) == ',gN' def test_railencrypt_37(self): - assert railencrypt(st='lgnhpcl', k=207) == 'lgnhpcl' + assert railencrypt(st='', k=885) == '' def test_railencrypt_38(self): - assert railencrypt(st='fuuq', k=570) == 'fuuq' + assert railencrypt(st='3kDF>S%/', k=816) == '3kDF>S%/' def test_railencrypt_39(self): - assert railencrypt(st='blxp', k=440) == 'blxp' + assert railencrypt(st='h{I