This commit is contained in:
Claudio Maggioni 2023-12-09 11:56:23 +01:00
parent 4272d6c3d4
commit b76e252f3c
16 changed files with 1559 additions and 1507 deletions

View file

@ -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

View file

@ -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__':

138
genetic.py Normal file
View file

@ -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()

View file

@ -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:

View file

@ -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<F!') == False
def test_anagram_check_35(self):
assert anagram_check(s1='', s2='xpqvjl') == False
assert anagram_check(s1='t@f.', s2='m`X)D~Lv') == False
def test_anagram_check_36(self):
assert anagram_check(s1='dxceubtlu', s2='kwfegvfu') == False
assert anagram_check(s1='xA9', s2='k>GAoo') == False
def test_anagram_check_37(self):
assert anagram_check(s1='rpl', s2='yduqc') == False
assert anagram_check(s1='rC.u KD:'', s2='~o') == False
def test_anagram_check_38(self):
assert anagram_check(s1='jyaxwjvv', s2='ve') == False
assert anagram_check(s1='MBgu', s2='/xN-`Pq6T') == False
def test_anagram_check_39(self):
assert anagram_check(s1='aevailuxu', s2='') == False
assert anagram_check(s1='y+>', s2='X)/') == False
def test_anagram_check_40(self):
assert anagram_check(s1='vpicbln', s2='l') == False
assert anagram_check(s1='-LtEPi-{?', s2='$j0I+') == False
def test_anagram_check_41(self):
assert anagram_check(s1='ckbgmzae', s2='ikfdk') == False
assert anagram_check(s1='[L$(F', s2='(JsXN]/MQ') == False
def test_anagram_check_42(self):
assert anagram_check(s1='o', s2='exwmqp') == False
assert anagram_check(s1='X6:', s2='[1N0<') == False
def test_anagram_check_43(self):
assert anagram_check(s1='ntuuht', s2='orkj') == False
assert anagram_check(s1='4x', s2='jp8qx') == False
def test_anagram_check_44(self):
assert anagram_check(s1='bo', s2='') == False
assert anagram_check(s1='"n.Fa+T<Q', s2='') == False
def test_anagram_check_45(self):
assert anagram_check(s1='fxfxea', s2='pnpmdti') == False
assert anagram_check(s1='', s2=' vik@%') == False
def test_anagram_check_46(self):
assert anagram_check(s1='l', s2='vqvrhhf') == False
assert anagram_check(s1='3Qze', s2='S)_') == False
def test_anagram_check_47(self):
assert anagram_check(s1='eqdgjmuu', s2='a') == False
assert anagram_check(s1='q%pCIP{f', s2='c=\Q') == False
def test_anagram_check_48(self):
assert anagram_check(s1='zxznuo', s2='mz') == False
assert anagram_check(s1='=xmur', s2='F') == False
def test_anagram_check_49(self):
assert anagram_check(s1='ffe', s2='uliflb') == False
assert anagram_check(s1='y2^)$)', s2='') == False
def test_anagram_check_50(self):
assert anagram_check(s1='kcy', s2='mazdaemjz') == False
assert anagram_check(s1='jlw)', s2='L(') == False
def test_anagram_check_51(self):
assert anagram_check(s1='coetxy', s2='jzkufxdun') == False
assert anagram_check(s1=':ei#f', s2='gv<X<') == False
def test_anagram_check_52(self):
assert anagram_check(s1='cdaasq', s2='mpglw') == False
assert anagram_check(s1='c@x[r', s2='.j7Wj') == False
def test_anagram_check_53(self):
assert anagram_check(s1='n', s2='xhzet') == False
assert anagram_check(s1='u>', s2='U') == False
def test_anagram_check_54(self):
assert anagram_check(s1='ama', s2='jxjpoim') == False
assert anagram_check(s1='va6x@Wa>', s2='0! ') == False
def test_anagram_check_55(self):
assert anagram_check(s1='lakfn', s2='x') == False
assert anagram_check(s1='/aRj', s2=')*') == False
def test_anagram_check_56(self):
assert anagram_check(s1='hdle', s2='qpcnia') == False
assert anagram_check(s1='`,-', s2='r{^HTYwqb') == False
def test_anagram_check_57(self):
assert anagram_check(s1='omquy', s2='qbqgfflcu') == False
assert anagram_check(s1='R&l_', s2='Y(u') == False
def test_anagram_check_58(self):
assert anagram_check(s1='gter', s2='cpicjywy') == False
assert anagram_check(s1='W', s2='lWidmzS9') == False
def test_anagram_check_59(self):
assert anagram_check(s1='lakfn', s2='vqvrhhf') == False
assert anagram_check(s1='w[rB;W', s2='k&1kF,1;E') == False
def test_anagram_check_60(self):
assert anagram_check(s1='jyznboajo', s2='bmca') == False
assert anagram_check(s1='4"', s2='?9'') == False
def test_anagram_check_61(self):
assert anagram_check(s1='', s2='ydb') == False
assert anagram_check(s1='r{>8', s2='K0B~f') == False
def test_anagram_check_62(self):
assert anagram_check(s1='sivmua', s2='x') == False
assert anagram_check(s1='k', s2='[n1#') == False
def test_anagram_check_63(self):
assert anagram_check(s1='eyyb', s2='uxjwf') == False
assert anagram_check(s1='2G]}8', s2='FX7.') == False
def test_anagram_check_64(self):
assert anagram_check(s1='wibdil', s2='it') == False
assert anagram_check(s1='', s2='>*%C^hI') == False
def test_anagram_check_65(self):
assert anagram_check(s1='fyfw', s2='lnj') == False
assert anagram_check(s1='F', s2='IRr.MF') == False
def test_anagram_check_66(self):
assert anagram_check(s1='xelkoql', s2='em') == False
assert anagram_check(s1='XV4yF0WTY', s2='sk#') == False
def test_anagram_check_67(self):
assert anagram_check(s1='jdfpwvy', s2='sg') == False
assert anagram_check(s1='[<o-`/"', s2='la`[QV+') == False
def test_anagram_check_68(self):
assert anagram_check(s1='i', s2='m') == False
assert anagram_check(s1=';T${', s2='N+_4@') == False
def test_anagram_check_69(self):
assert anagram_check(s1='m', s2='g') == False
assert anagram_check(s1='B/mqTkzy]', s2='_=\Q') == False
def test_anagram_check_70(self):
assert anagram_check(s1='frncc', s2='lxvsn') == False
assert anagram_check(s1='^Y', s2=' m%\fDZ)h') == False
def test_anagram_check_71(self):
assert anagram_check(s1='mwjzqp', s2='czgnpehn') == False
assert anagram_check(s1='N9', s2='&|A[we~ic') == False
def test_anagram_check_72(self):
assert anagram_check(s1='xc', s2='sg') == False
assert anagram_check(s1='gd0l', s2=''>') == 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='at<y&46') == False
def test_anagram_check_96(self):
assert anagram_check(s1='tulzvfub', s2='btimc') == False
assert anagram_check(s1='1G~GM-', s2='p') == False
def test_anagram_check_97(self):
assert anagram_check(s1='hna', s2='lrvyck') == False
assert anagram_check(s1=')gwoXqTN,', s2='R49qTWTgv') == False
def test_anagram_check_98(self):
assert anagram_check(s1='oiilgmvdw', s2='af') == False
assert anagram_check(s1='/6', s2='&Vp') == False
def test_anagram_check_99(self):
assert anagram_check(s1='vnx', s2='rbb') == False
assert anagram_check(s1='', s2='Rh') == False
def test_anagram_check_100(self):
assert anagram_check(s1='ctycslewe', s2='hnqmnppsp') == False
assert anagram_check(s1='WO(MMB"o', s2='>') == False
def test_anagram_check_101(self):
assert anagram_check(s1='', s2='`i:1B') == False

View file

@ -5,304 +5,301 @@ from benchmark.common_divisor_count import cd_count
class Test_cd_count(TestCase):
def test_cd_count_1(self):
assert cd_count(a=584, b=-345) == 1
assert cd_count(a=-750, b=879) == 2
def test_cd_count_2(self):
assert cd_count(a=-712, b=-668) == 3
assert cd_count(a=-998, b=763) == 1
def test_cd_count_3(self):
assert cd_count(a=975, b=-510) == 4
assert cd_count(a=-64, b=55) == 1
def test_cd_count_4(self):
assert cd_count(a=-610, b=-557) == 1
assert cd_count(a=-298, b=-790) == 2
def test_cd_count_5(self):
assert cd_count(a=176, b=400) == 5
assert cd_count(a=829, b=830) == 1
def test_cd_count_6(self):
assert cd_count(a=308, b=-472) == 3
assert cd_count(a=-973, b=220) == 1
def test_cd_count_7(self):
assert cd_count(a=-330, b=778) == 2
assert cd_count(a=872, b=55) == 1
def test_cd_count_8(self):
assert cd_count(a=-271, b=212) == 1
assert cd_count(a=348, b=-251) == 1
def test_cd_count_9(self):
assert cd_count(a=-841, b=-15) == 1
assert cd_count(a=544, b=-783) == 1
def test_cd_count_10(self):
assert cd_count(a=993, b=450) == 2
assert cd_count(a=-685, b=-824) == 1
def test_cd_count_11(self):
assert cd_count(a=-939, b=495) == 2
assert cd_count(a=875, b=735) == 4
def test_cd_count_12(self):
assert cd_count(a=322, b=545) == 1
assert cd_count(a=-546, b=700) == 4
def test_cd_count_13(self):
assert cd_count(a=325, b=-464) == 1
assert cd_count(a=-482, b=843) == 1
def test_cd_count_14(self):
assert cd_count(a=-415, b=109) == 1
assert cd_count(a=930, b=-853) == 1
def test_cd_count_15(self):
assert cd_count(a=388, b=302) == 2
assert cd_count(a=-1000, b=786) == 2
def test_cd_count_16(self):
assert cd_count(a=-120, b=-61) == 1
assert cd_count(a=701, b=-63) == 1
def test_cd_count_17(self):
assert cd_count(a=-402, b=164) == 2
assert cd_count(a=-974, b=-9) == 1
def test_cd_count_18(self):
assert cd_count(a=-315, b=257) == 1
assert cd_count(a=162, b=-399) == 2
def test_cd_count_19(self):
assert cd_count(a=-994, b=-955) == 1
assert cd_count(a=792, b=400) == 4
def test_cd_count_20(self):
assert cd_count(a=611, b=-113) == 1
assert cd_count(a=656, b=-516) == 3
def test_cd_count_21(self):
assert cd_count(a=821, b=550) == 1
assert cd_count(a=-544, b=731) == 2
def test_cd_count_22(self):
assert cd_count(a=-404, b=960) == 3
assert cd_count(a=512, b=788) == 3
def test_cd_count_23(self):
assert cd_count(a=162, b=-422) == 2
assert cd_count(a=878, b=-899) == 1
def test_cd_count_24(self):
assert cd_count(a=940, b=741) == 1
assert cd_count(a=16, b=792) == 4
def test_cd_count_25(self):
assert cd_count(a=12, b=-270) == 4
assert cd_count(a=117, b=-9) == 3
def test_cd_count_26(self):
assert cd_count(a=-490, b=-403) == 1
assert cd_count(a=-693, b=770) == 4
def test_cd_count_27(self):
assert cd_count(a=-87, b=-270) == 2
assert cd_count(a=-331, b=-615) == 1
def test_cd_count_28(self):
assert cd_count(a=-362, b=-406) == 2
assert cd_count(a=417, b=-884) == 1
def test_cd_count_29(self):
assert cd_count(a=328, b=-291) == 1
assert cd_count(a=327, b=-159) == 2
def test_cd_count_30(self):
assert cd_count(a=457, b=328) == 1
assert cd_count(a=-618, b=-665) == 1
def test_cd_count_31(self):
assert cd_count(a=-837, b=-349) == 1
assert cd_count(a=409, b=-668) == 1
def test_cd_count_32(self):
assert cd_count(a=27, b=-391) == 1
assert cd_count(a=-713, b=-192) == 1
def test_cd_count_33(self):
assert cd_count(a=-417, b=-969) == 2
assert cd_count(a=-582, b=-455) == 1
def test_cd_count_34(self):
assert cd_count(a=-529, b=-472) == 1
assert cd_count(a=930, b=-706) == 2
def test_cd_count_35(self):
assert cd_count(a=-109, b=-69) == 1
assert cd_count(a=-668, b=630) == 2
def test_cd_count_36(self):
assert cd_count(a=961, b=105) == 1
assert cd_count(a=-505, b=-14) == 1
def test_cd_count_37(self):
assert cd_count(a=-669, b=-16) == 1
assert cd_count(a=819, b=-291) == 2
def test_cd_count_38(self):
assert cd_count(a=-932, b=284) == 3
assert cd_count(a=-834, b=-422) == 2
def test_cd_count_39(self):
assert cd_count(a=164, b=-438) == 2
assert cd_count(a=466, b=722) == 2
def test_cd_count_40(self):
assert cd_count(a=-652, b=215) == 1
assert cd_count(a=125, b=304) == 1
def test_cd_count_41(self):
assert cd_count(a=-925, b=-731) == 1
assert cd_count(a=-602, b=221) == 1
def test_cd_count_42(self):
assert cd_count(a=751, b=-61) == 1
assert cd_count(a=22, b=259) == 1
def test_cd_count_43(self):
assert cd_count(a=-101, b=-24) == 1
assert cd_count(a=671, b=-530) == 1
def test_cd_count_44(self):
assert cd_count(a=397, b=-482) == 1
assert cd_count(a=-67, b=557) == 1
def test_cd_count_45(self):
assert cd_count(a=216, b=701) == 1
assert cd_count(a=10, b=920) == 4
def test_cd_count_46(self):
assert cd_count(a=-937, b=-668) == 1
assert cd_count(a=459, b=-956) == 1
def test_cd_count_47(self):
assert cd_count(a=628, b=-490) == 2
assert cd_count(a=845, b=-377) == 2
def test_cd_count_48(self):
assert cd_count(a=127, b=969) == 1
assert cd_count(a=-531, b=-413) == 2
def test_cd_count_49(self):
assert cd_count(a=297, b=382) == 1
assert cd_count(a=820, b=-58) == 2
def test_cd_count_50(self):
assert cd_count(a=-290, b=104) == 2
assert cd_count(a=769, b=-410) == 1
def test_cd_count_51(self):
assert cd_count(a=-68, b=-878) == 2
assert cd_count(a=-262, b=394) == 2
def test_cd_count_52(self):
assert cd_count(a=81, b=-13) == 1
assert cd_count(a=-961, b=-140) == 1
def test_cd_count_53(self):
assert cd_count(a=930, b=288) == 4
assert cd_count(a=960, b=-6) == 4
def test_cd_count_54(self):
assert cd_count(a=943, b=-700) == 1
assert cd_count(a=-808, b=792) == 4
def test_cd_count_55(self):
assert cd_count(a=-669, b=-422) == 1
assert cd_count(a=-28, b=669) == 1
def test_cd_count_56(self):
assert cd_count(a=-528, b=763) == 1
assert cd_count(a=277, b=228) == 1
def test_cd_count_57(self):
assert cd_count(a=735, b=154) == 2
assert cd_count(a=-693, b=-144) == 3
def test_cd_count_58(self):
assert cd_count(a=341, b=-332) == 1
assert cd_count(a=125, b=994) == 1
def test_cd_count_59(self):
assert cd_count(a=-62, b=-332) == 2
assert cd_count(a=-532, b=-342) == 4
def test_cd_count_60(self):
assert cd_count(a=-271, b=580) == 1
assert cd_count(a=-162, b=-266) == 2
def test_cd_count_61(self):
assert cd_count(a=-440, b=-186) == 2
assert cd_count(a=-561, b=219) == 2
def test_cd_count_62(self):
assert cd_count(a=260, b=-956) == 3
assert cd_count(a=-96, b=819) == 2
def test_cd_count_63(self):
assert cd_count(a=-625, b=457) == 1
assert cd_count(a=380, b=372) == 3
def test_cd_count_64(self):
assert cd_count(a=-483, b=-400) == 1
assert cd_count(a=439, b=-276) == 1
def test_cd_count_65(self):
assert cd_count(a=-319, b=137) == 1
assert cd_count(a=377, b=-874) == 1
def test_cd_count_66(self):
assert cd_count(a=-972, b=-931) == 1
assert cd_count(a=-532, b=-501) == 1
def test_cd_count_67(self):
assert cd_count(a=-285, b=940) == 2
assert cd_count(a=329, b=-487) == 1
def test_cd_count_68(self):
assert cd_count(a=-434, b=-581) == 2
assert cd_count(a=203, b=-883) == 1
def test_cd_count_69(self):
assert cd_count(a=-529, b=-666) == 1
assert cd_count(a=757, b=-958) == 1
def test_cd_count_70(self):
assert cd_count(a=948, b=763) == 1
assert cd_count(a=-86, b=-929) == 1
def test_cd_count_71(self):
assert cd_count(a=-660, b=-657) == 2
assert cd_count(a=-181, b=-231) == 1
def test_cd_count_72(self):
assert cd_count(a=-816, b=-241) == 1
assert cd_count(a=712, b=-241) == 1
def test_cd_count_73(self):
assert cd_count(a=524, b=594) == 2
assert cd_count(a=-583, b=542) == 1
def test_cd_count_74(self):
assert cd_count(a=-14, b=743) == 1
assert cd_count(a=151, b=-334) == 1
def test_cd_count_75(self):
assert cd_count(a=745, b=-80) == 2
assert cd_count(a=987, b=879) == 2
def test_cd_count_76(self):
assert cd_count(a=493, b=504) == 1
assert cd_count(a=328, b=546) == 2
def test_cd_count_77(self):
assert cd_count(a=-170, b=-232) == 2
assert cd_count(a=347, b=-337) == 1
def test_cd_count_78(self):
assert cd_count(a=28, b=-804) == 3
assert cd_count(a=10, b=-46) == 2
def test_cd_count_79(self):
assert cd_count(a=221, b=212) == 1
assert cd_count(a=-959, b=702) == 1
def test_cd_count_80(self):
assert cd_count(a=994, b=-397) == 1
assert cd_count(a=96, b=321) == 2
def test_cd_count_81(self):
assert cd_count(a=-902, b=193) == 1
assert cd_count(a=-1000, b=-865) == 2
def test_cd_count_82(self):
assert cd_count(a=221, b=580) == 1
assert cd_count(a=-781, b=-808) == 1
def test_cd_count_83(self):
assert cd_count(a=-953, b=312) == 1
assert cd_count(a=-593, b=-963) == 1
def test_cd_count_84(self):
assert cd_count(a=-21, b=-927) == 2
assert cd_count(a=376, b=230) == 2
def test_cd_count_85(self):
assert cd_count(a=-944, b=-658) == 2
assert cd_count(a=791, b=587) == 1
def test_cd_count_86(self):
assert cd_count(a=750, b=-290) == 4
assert cd_count(a=-737, b=327) == 1