works
This commit is contained in:
parent
a622cc5e27
commit
1153d5138a
19 changed files with 367 additions and 360 deletions
|
@ -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
|
||||
|
|
57
fuzzer.py
57
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__":
|
||||
|
|
32
genetic.py
32
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__':
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
|
@ -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
|
||||
|
|
|
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 41 KiB |
Binary file not shown.
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
@ -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
|
||||
|
|
|
|
@ -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
|
||||
|
|
|
@ -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<W;`i'
|
||||
assert encrypt(strng='w#8TVj', key=73) == 'al">@T'
|
||||
|
||||
|
||||
class Test_decrypt(TestCase):
|
||||
# distances_true = {2: [0, 0, 1, 0, 0, 3, 1, 18, 48]}
|
||||
# distances_false = {2: [1, 3, 0, 15, 6, 0, 0, 0, 0]}
|
||||
# distances_true = {2: [0, 0, 0, 223, 18, 37, 0, 29]}
|
||||
# distances_false = {2: [18, 16, 11, 0, 0, 0, 14, 0]}
|
||||
def test_decrypt_1(self):
|
||||
assert decrypt(strng='203$-53Db', key=19) == '~| py" 1O'
|
||||
assert decrypt(strng='027 Sf4^', key=34) == 'motþ1Dq<'
|
||||
|
|
|
@ -3,27 +3,27 @@ from benchmark.check_armstrong import check_armstrong
|
|||
|
||||
|
||||
class Test_check_armstrong(TestCase):
|
||||
# distances_true = {1: [156], 2: [155], 3: [6], 4: [0, 0, 0, 1], 5: [186]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [156, 15, 1, 0], 5: [0]}
|
||||
def test_check_armstrong_1(self):
|
||||
assert check_armstrong(n=156) == False
|
||||
|
||||
# distances_true = {1: [2], 2: [1], 3: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [149]}
|
||||
def test_check_armstrong_1(self):
|
||||
def test_check_armstrong_2(self):
|
||||
assert check_armstrong(n=2) == False
|
||||
|
||||
# distances_true = {1: [0]}
|
||||
# distances_false = {1: [1]}
|
||||
def test_check_armstrong_2(self):
|
||||
assert check_armstrong(n=0) == True
|
||||
|
||||
# distances_true = {1: [380], 2: [379], 3: [230], 4: [0, 0, 0, 1], 5: [159]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [380, 38, 3, 0], 5: [0]}
|
||||
# distances_true = {1: [1], 2: [0]}
|
||||
# distances_false = {1: [0], 2: [1]}
|
||||
def test_check_armstrong_3(self):
|
||||
assert check_armstrong(n=380) == False
|
||||
assert check_armstrong(n=1) == True
|
||||
|
||||
# distances_true = {1: [153], 2: [152], 3: [3], 4: [0, 0, 0, 1], 5: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [153, 15, 1, 0], 5: [1]}
|
||||
def test_check_armstrong_4(self):
|
||||
assert check_armstrong(n=153) == True
|
||||
|
||||
# distances_true = {1: [1], 2: [0]}
|
||||
# distances_false = {1: [0], 2: [1]}
|
||||
# distances_true = {1: [0]}
|
||||
# distances_false = {1: [1]}
|
||||
def test_check_armstrong_5(self):
|
||||
assert check_armstrong(n=1) == True
|
||||
assert check_armstrong(n=0) == True
|
||||
|
|
|
@ -3,32 +3,37 @@ from benchmark.common_divisor_count import cd_count
|
|||
|
||||
|
||||
class Test_cd_count(TestCase):
|
||||
# distances_true = {1: [5], 2: [618], 3: [6], 4: [619], 5: [0, 0, 0, 0, 1], 6: [0], 7: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [5, 3, 2, 1, 0], 6: [1], 7: [1]}
|
||||
def test_cd_count_1(self):
|
||||
assert cd_count(a=5, b=618) == 1
|
||||
|
||||
# distances_true = {1: [0]}
|
||||
# distances_false = {1: [1]}
|
||||
def test_cd_count_2(self):
|
||||
assert cd_count(a=0, b=-49) == 2
|
||||
def test_cd_count_1(self):
|
||||
assert cd_count(a=0, b=15) == 2
|
||||
|
||||
# distances_true = {1: [4], 2: [101], 3: [5], 4: [0], 5: [0, 0, 1], 6: [0], 7: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [101], 5: [4, 1, 0], 6: [1], 7: [1]}
|
||||
def test_cd_count_3(self):
|
||||
assert cd_count(a=4, b=-101) == 1
|
||||
|
||||
# distances_true = {1: [10], 2: [52], 3: [0], 4: [0], 5: [0, 0, 1], 6: [0], 7: [1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [10], 4: [52], 5: [10, 2, 0], 6: [1], 7: [0]}
|
||||
def test_cd_count_4(self):
|
||||
assert cd_count(a=-10, b=-52) == 2
|
||||
|
||||
# distances_true = {1: [9], 2: [0]}
|
||||
# distances_true = {1: [393], 2: [0]}
|
||||
# distances_false = {1: [0], 2: [1]}
|
||||
def test_cd_count_5(self):
|
||||
assert cd_count(a=9, b=0) == 2
|
||||
def test_cd_count_2(self):
|
||||
assert cd_count(a=393, b=0) == 2
|
||||
|
||||
# distances_true = {1: [10], 2: [150], 3: [0], 4: [0], 5: [0, 1], 6: [0, 0, 1], 7: [9, 3]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [10], 4: [150], 5: [10, 0], 6: [1, 1, 0], 7: [0, 0]}
|
||||
# distances_true = {1: [10], 2: [25], 3: [0], 4: [0], 5: [0, 0, 1], 6: [0, 1], 7: [4]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [10], 4: [25], 5: [10, 5, 0], 6: [1, 0], 7: [0]}
|
||||
def test_cd_count_3(self):
|
||||
assert cd_count(a=-10, b=-25) == 2
|
||||
|
||||
# distances_true = {1: [402], 2: [6], 3: [403], 4: [0], 5: [0, 0, 1], 6: [0, 0], 7: [5, 1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [6], 5: [402, 6, 0], 6: [1, 1], 7: [0, 0]}
|
||||
def test_cd_count_4(self):
|
||||
assert cd_count(a=402, b=-6) == 4
|
||||
|
||||
# distances_true = {1: [392], 2: [7], 3: [393], 4: [8], 5: [0, 0, 1], 6: [0, 1], 7: [6]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [392, 7, 0], 6: [1, 0], 7: [0]}
|
||||
def test_cd_count_5(self):
|
||||
assert cd_count(a=392, b=7) == 2
|
||||
|
||||
# distances_true = {1: [394], 2: [8], 3: [395], 4: [9], 5: [0, 0, 0, 1], 6: [0], 7: [1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [394, 8, 2, 0], 6: [1], 7: [0]}
|
||||
def test_cd_count_6(self):
|
||||
assert cd_count(a=-10, b=-150) == 4
|
||||
assert cd_count(a=394, b=8) == 2
|
||||
|
||||
# distances_true = {1: [391], 2: [2], 3: [392], 4: [3], 5: [0, 0, 0, 1], 6: [0], 7: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [391, 2, 1, 0], 6: [1], 7: [1]}
|
||||
def test_cd_count_7(self):
|
||||
assert cd_count(a=391, b=2) == 1
|
||||
|
|
|
@ -3,7 +3,7 @@ from benchmark.exponentiation import exponentiation
|
|||
|
||||
|
||||
class Test_exponentiation(TestCase):
|
||||
# distances_true = {1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 3: [0], 2: [1, 1, 0, 1, 0, 1, 1, 1, 1]}
|
||||
# distances_false = {1: [591, 295, 147, 73, 36, 17, 8, 3, 1, 0], 3: [1], 2: [0, 0, 1, 0, 1, 0, 0, 0, 0]}
|
||||
# distances_true = {1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 3: [0], 2: [1, 0, 1, 0, 1, 0, 1, 1, 1]}
|
||||
# distances_false = {1: [679, 339, 169, 84, 41, 20, 9, 4, 1, 0], 3: [1], 2: [0, 1, 0, 1, 0, 1, 0, 0, 0]}
|
||||
def test_exponentiation_1(self):
|
||||
assert exponentiation(baseNumber=748, power=592) == 2237411859567305228712820969577177889399507688925863669623492970046756800811752671771192642266754818786206883016528099952656873068236573570940727536208482507787576742117892529716174302439216500172363521344994812494798736599216689085381729125165667408413134378577619291662064250215391547791138001022452137862778730264821893010999654434708983063321061487758219131875157534566833176981850918287964729665626846138477133321680757074668758491790945198601054224199588300081988215907925870651530562786845054260705838873377721118111382749970684115994163428904242940249188932413043444079730697574946438556722431973692672316117631662669780447322962255376036216266360170992797300680863608151678208837497803629559832285706122751678247068182933676547879825690946817522731921058001762116141626296741021042361970731691972888241818460142317141771780073548156492405406490981515425290002128649234461825789947573119368985161153262332388808724131879060867880473096842000650483632521058294479344879944564436266652927131107918428149402925778007533423162302903655859402260228366219008304205413113994847339399353552421491921433679173463981507810853240889014970942564956030433528528976883729747234323037570498652835167034147294039927751837932259353682824119565000780453933743514380393121666554146174425347788804096581718436380869076273595714279596282320033858652789005508958162362572551844879419089353500606113442189427958545044465106509994666028492893004614086892576645413919934301813479926994631172622364458500761310743512340332065554689760340750349754142540650730287762939301975905339162897423087384712675419496189151357961520127467940210297313531487397450555066413386239184330770939775155310643870407646031104489325011664896
|
||||
assert exponentiation(baseNumber=273, power=680) == 3895829911570928427062789161404619914280587771868641368230047219958283345300450942897840323420791983227798964155996689168523437566770315575583013976403957872742182353547463597025702302902832229086505206794667167898163934216590804080800733688120376430395338105859000612063507722208813216463729860745825987959359261789071423513895716311721748115129973945455387902352811050072692137174188206432034223389947642057171762532443123845107375361110833977798080587890468684612289410208695964211522638003354245409255507983104542683355382317518977114366295148467288902108644080093389079060315506570882647437359202448921746467958494827152271151409822952703502092414977688648082960249156331982392167922155653098989699335892059699361415118388425849978057627932625853662432314879750773240572688797268782645610220407914772433232815718897161329409011757811650965412399303355317182165903778708510492810189246784961371248406019716330925132073748574311471381406856686563502008322111913444321152997673213749133497305507944474723081065221727352562980326137327122607087182234700957778053610249838737764681707961211892627389095734978445860126630875401467771828849380219936663564390488252632365445815860667399405147173712004117843019973408114982416950170127509936321352740444103690166146920102943006785619658810173984204313195394806290104680248135955773591764204824995379131427455872719071405823820721924895558772558138790298999583595141680838833952767448791324515927781329111543905447682668609169946357479866063142378522581199077752915958479926692022074057503083311484355723701186263368366885202884101517116580212732955571601354373596263954677080515220048136220941141669130397916801
|
||||
|
|
|
@ -3,22 +3,27 @@ from benchmark.gcd import gcd
|
|||
|
||||
|
||||
class Test_gcd(TestCase):
|
||||
# distances_true = {1: [6], 2: [3], 3: [3], 4: [4], 5: [0, 0, 0, 1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [4, 3, 1, 0]}
|
||||
def test_gcd_1(self):
|
||||
assert gcd(a=7, b=4) == 1
|
||||
|
||||
# distances_true = {1: [3], 2: [5], 3: [2], 4: [0], 5: [0, 0, 1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [2], 5: [4, 2, 0]}
|
||||
def test_gcd_2(self):
|
||||
assert gcd(a=4, b=6) == 2
|
||||
|
||||
# distances_true = {1: [1], 2: [0]}
|
||||
# distances_false = {1: [0], 2: [1]}
|
||||
def test_gcd_3(self):
|
||||
assert gcd(a=2, b=1) == 1
|
||||
|
||||
# distances_true = {1: [6], 2: [6], 3: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [1]}
|
||||
def test_gcd_4(self):
|
||||
assert gcd(a=7, b=7) == 7
|
||||
|
||||
# distances_true = {1: [0]}
|
||||
# distances_false = {1: [1]}
|
||||
def test_gcd_1(self):
|
||||
assert gcd(a=1, b=376) == 1
|
||||
|
||||
# distances_true = {1: [3], 2: [309], 3: [306], 4: [0], 5: [0, 0, 1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [306], 5: [4, 2, 0]}
|
||||
def test_gcd_2(self):
|
||||
assert gcd(a=4, b=310) == 2
|
||||
|
||||
# distances_true = {1: [930], 2: [8], 3: [922], 4: [923], 5: [0, 0, 0, 1]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [9, 4, 1, 0]}
|
||||
def test_gcd_3(self):
|
||||
assert gcd(a=931, b=9) == 1
|
||||
|
||||
# distances_true = {1: [698], 2: [0]}
|
||||
# distances_false = {1: [0], 2: [1]}
|
||||
def test_gcd_4(self):
|
||||
assert gcd(a=699, b=1) == 1
|
||||
def test_gcd_5(self):
|
||||
assert gcd(a=1, b=2) == 1
|
||||
|
|
|
@ -3,7 +3,7 @@ from benchmark.longest_substring import longest_sorted_substr
|
|||
|
||||
|
||||
class Test_longest_sorted_substr(TestCase):
|
||||
# distances_true = {1: [45, 0, 14, 0, 15, 0, 0], 2: [0, 1, 1, 0]}
|
||||
# distances_false = {1: [0, 43, 0, 13, 0, 30, 3], 2: [1, 0, 0, 1]}
|
||||
# distances_true = {1: [38, 0, 29, 15, 0, 30, 0], 2: [0, 1, 1]}
|
||||
# distances_false = {1: [0, 21, 0, 0, 35, 0, 61], 2: [1, 0, 0]}
|
||||
def test_longest_sorted_substr_1(self):
|
||||
assert longest_sorted_substr(s='b5_Q]Nkm') == 'Nkm'
|
||||
assert longest_sorted_substr(s='nH\\?0R4p') == 'H\\'
|
||||
|
|
|
@ -6,14 +6,9 @@ class Test_rabin_karp_search(TestCase):
|
|||
# distances_true = {1: [0], 2: [1], 3: [0], 4: [1]}
|
||||
# distances_false = {1: [1], 2: [0], 3: [1], 4: [0]}
|
||||
def test_rabin_karp_search_1(self):
|
||||
assert rabin_karp_search(pat='z', txt='z') == [0]
|
||||
assert rabin_karp_search(pat='k', txt='k') == [0]
|
||||
|
||||
# distances_true = {1: [0], 2: [0], 3: [3], 4: [1]}
|
||||
# distances_false = {1: [1], 2: [23], 3: [0], 4: [0]}
|
||||
# distances_true = {1: [6], 4: [1]}
|
||||
# distances_false = {1: [0], 4: [0]}
|
||||
def test_rabin_karp_search_2(self):
|
||||
assert rabin_karp_search(pat='b&k<', txt='K@qO') == []
|
||||
|
||||
# distances_true = {1: [0, 0, 61, 51, 81, 82, 87, 98], 3: [1, 2], 4: [0, 0, 0, 0, 0, 0, 0, 1], 5: [1, 62, 52, 82, 83, 88, 99]}
|
||||
# distances_false = {1: [1, 1, 0, 0, 0, 0, 0, 0], 3: [0, 0], 4: [7, 6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0, 0]}
|
||||
def test_rabin_karp_search_3(self):
|
||||
assert rabin_karp_search(pat='', txt='ex[>NC6') == []
|
||||
assert rabin_karp_search(pat='V', txt='\\') == []
|
||||
|
|
|
@ -4,14 +4,14 @@ from benchmark.railfence_cipher import raildecrypt
|
|||
|
||||
|
||||
class Test_railencrypt(TestCase):
|
||||
# distances_true = {1: [0, 0, 0, 0, 1, 1, 1, 0, 0], 2: [3, 2, 1, 0, 2, 1], 3: [2, 1, 0], 4: [0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1]}
|
||||
# distances_false = {1: [1, 1, 1, 1, 0, 0, 0, 1, 1], 2: [0, 0, 0, 1, 0, 0], 3: [0, 0, 1], 4: [102, 0, 0, 0, 0, 0, 112, 0, 0, 0, 110, 0, 0, 0, 122, 0, 52, 0, 0, 0, 124, 0, 50, 0, 0, 0, 48, 0, 0, 0, 38, 0, 0, 0, 0, 0]}
|
||||
# distances_true = {1: [0, 0, 0, 1, 1, 0, 0, 1], 2: [2, 1, 0, 1, 0], 3: [1, 0, 1], 4: [0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1]}
|
||||
# distances_false = {1: [1, 1, 1, 0, 0, 1, 1, 0], 2: [0, 0, 1, 0, 1], 3: [0, 1, 0], 4: [86, 0, 0, 0, 113, 0, 0, 0, 0, 119, 0, 79, 0, 125, 0, 97, 0, 0, 73, 0, 0, 0, 119, 0]}
|
||||
def test_railencrypt_1(self):
|
||||
assert railencrypt(st='fn|&2zp40', k=4) == 'fpnz4|20&'
|
||||
assert railencrypt(st='VwIOq}wa', k=3) == 'VqwO}aIw'
|
||||
|
||||
|
||||
class Test_raildecrypt(TestCase):
|
||||
# distances_true = {5: [0, 0, 0, 0, 1, 1, 1], 6: [3, 2, 1, 0], 7: [2, 1, 0], 8: [0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1], 9: [0, 0, 0, 0, 0, 0, 0], 10: [7, 0, 0, 0, 1, 1, 1], 12: [0, 2, 1, 0], 11: [2, 1, 0]}
|
||||
# distances_false = {5: [1, 1, 1, 1, 0, 0, 0], 6: [0, 0, 0, 1], 7: [0, 0, 1], 8: [1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0], 9: [125, 79, 95, 32, 85, 109, 46], 10: [0, 1, 1, 1, 0, 0, 0], 12: [1, 0, 0, 1], 11: [0, 0, 1]}
|
||||
# distances_true = {5: [0, 0, 0, 0, 0, 1, 1, 1, 1], 6: [4, 3, 2, 1, 0], 7: [3, 2, 1, 0], 8: [0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1], 9: [0, 0, 0, 0, 0, 0, 0, 0, 0], 10: [9, 0, 0, 0, 0, 1, 1, 1, 1], 12: [0, 3, 2, 1, 0], 11: [3, 2, 1, 0]}
|
||||
# distances_false = {5: [1, 1, 1, 1, 1, 0, 0, 0, 0], 6: [0, 0, 0, 0, 1], 7: [0, 0, 0, 1], 8: [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], 9: [32, 34, 87, 124, 65, 97, 36, 47, 82], 10: [0, 1, 1, 1, 1, 0, 0, 0, 0], 12: [1, 0, 0, 0, 1], 11: [0, 0, 0, 1]}
|
||||
def test_raildecrypt_1(self):
|
||||
assert raildecrypt(st='}.Om_U ', k=4) == '}O_ Um.'
|
||||
assert raildecrypt(st=' R"/W$|aA', k=5) == ' "W|Aa$/R'
|
||||
|
|
|
@ -3,17 +3,27 @@ from benchmark.zellers_birthday import zeller
|
|||
|
||||
|
||||
class Test_zeller(TestCase):
|
||||
# distances_true = {1: [1], 2: [6], 3: [0], 4: [0], 5: [1923], 7: [5], 8: [0]}
|
||||
# distances_false = {1: [0], 2: [0], 3: [78], 4: [1], 5: [0], 7: [0], 8: [1]}
|
||||
# distances_true = {1: [13], 2: [0], 3: [0], 4: [4], 5: [0], 6: [0], 7: [0], 8: [2, 1, 0]}
|
||||
# distances_false = {1: [0], 2: [408], 3: [74], 4: [0], 5: [74], 6: [4], 7: [2], 8: [0, 0, 1]}
|
||||
def test_zeller_1(self):
|
||||
assert zeller(d=31, m=7, y=-22) == 'Sunday'
|
||||
assert zeller(d=19, m=420, y=-26) == 'Tuesday'
|
||||
|
||||
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [0], 8: [3, 2, 1, 0]}
|
||||
# distances_false = {1: [1], 2: [1], 3: [78], 4: [1], 5: [0], 7: [1], 8: [0, 0, 0, 1]}
|
||||
# distances_true = {1: [0], 2: [0], 3: [0], 4: [9], 5: [0], 6: [0], 7: [0], 8: [3, 2, 1, 0]}
|
||||
# distances_false = {1: [544], 2: [397], 3: [69], 4: [0], 5: [69], 6: [9], 7: [1], 8: [0, 0, 0, 1]}
|
||||
def test_zeller_2(self):
|
||||
assert zeller(d=32, m=13, y=-22) == 'Wednesday'
|
||||
assert zeller(d=-575, m=-409, y=31) == 'Wednesday'
|
||||
|
||||
# distances_true = {1: [1], 2: [0], 3: [0], 4: [8], 5: [0], 6: [0], 7: [0], 8: [1, 0]}
|
||||
# distances_false = {1: [0], 2: [1], 3: [70], 4: [0], 5: [70], 6: [8], 7: [1], 8: [0, 1]}
|
||||
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [8], 8: [5, 4, 3, 2, 1, 0]}
|
||||
# distances_false = {1: [547], 2: [393], 3: [78], 4: [1], 5: [0], 7: [0], 8: [0, 0, 0, 0, 0, 1]}
|
||||
def test_zeller_3(self):
|
||||
assert zeller(d=31, m=13, y=-30) == 'Monday'
|
||||
assert zeller(d=-578, m=-405, y=22) == 'Friday'
|
||||
|
||||
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [0], 8: [1, 0]}
|
||||
# distances_false = {1: [547], 2: [397], 3: [78], 4: [1], 5: [0], 7: [1], 8: [0, 1]}
|
||||
def test_zeller_4(self):
|
||||
assert zeller(d=-578, m=-409, y=22) == 'Monday'
|
||||
|
||||
# distances_true = {1: [0], 2: [4], 3: [0], 4: [0], 5: [1922], 7: [7], 8: [0]}
|
||||
# distances_false = {1: [862], 2: [0], 3: [79], 4: [2], 5: [0], 7: [0], 8: [1]}
|
||||
def test_zeller_5(self):
|
||||
assert zeller(d=893, m=9, y=-21) == 'Sunday'
|
||||
|
|
Reference in a new issue