reran muttest with regeneration

This commit is contained in:
Claudio Maggioni 2023-12-27 16:07:31 +01:00
parent f5f605c259
commit 967209b852
33 changed files with 633 additions and 446 deletions

View file

@ -119,7 +119,7 @@ python3.7 muttest.py
The script will consider the tests in `fuzzer_tests` and `tests` and run mutation testing on them, collecting the The script will consider the tests in `fuzzer_tests` and `tests` and run mutation testing on them, collecting the
mutation score for each run in `out/mutation_results_fuzzer.csv` and `out/mutation_results_genetic.csv` respectively. mutation score for each run in `out/mutation_results_fuzzer.csv` and `out/mutation_results_genetic.csv` respectively.
If either or both file exist, the mutation run for the matching test suite will be skipped and the saved values will be If either or both file exist, the p run for the matching test suite will be skipped and the saved values will be
used. used.
The script additionally generates two plots for the distribution and average of mutation scores per kind of generation The script additionally generates two plots for the distribution and average of mutation scores per kind of generation
@ -127,3 +127,15 @@ and benchmark file. These two plots are saved in `out/mutation_scores.png` and `
respectively. `out/stats.csv` is also generated and will contain a statistical comparison between the mutation score respectively. `out/stats.csv` is also generated and will contain a statistical comparison between the mutation score
distribution for the fuzzer-generated and genetic-generated test of each benchmark file, including the average score for distribution for the fuzzer-generated and genetic-generated test of each benchmark file, including the average score for
both generations, the Wilcoxon paired test p-value, the Cohen's d effect size and its interpretation. both generations, the Wilcoxon paired test p-value, the Cohen's d effect size and its interpretation.
# Report
To compile the report run:
```shell
cd report
pdflatex -interaction=nonstopmode -output-directory=. main.tex
pdflatex -interaction=nonstopmode -output-directory=. main.tex
```
The report is then located in `report/main.pdf`.

View file

@ -32,7 +32,7 @@ class Archive:
def suite_str(self): def suite_str(self):
suite = self.build_suite() suite = self.build_suite()
return " ".join([",".join([f'{k}={repr(v)}' for k, v in test.items()]) + f",score={self}" for test in suite]) return " ".join([",".join([f'{k}={repr(v)}' for k, v in test.items()]) for test in suite])
def consider_test(self, test_case: frozendict): def consider_test(self, test_case: frozendict):
branch = self.satisfies_unseen_branches(test_case) branch = self.satisfies_unseen_branches(test_case)

View file

@ -18,7 +18,7 @@ INT_RANGE: Range = (-1000, 1000)
STRING_LEN_RANGE: Range = (0, 10) STRING_LEN_RANGE: Range = (0, 10)
STRING_CHAR_RANGE: Range = (32, 127) STRING_CHAR_RANGE: Range = (32, 127)
POOL_SIZE: int = 1000 POOL_SIZE: int = 1000
FUZZER_REPS: int = 1000 FUZZER_REPS: int = 250
OUT_DIR = os.path.join(os.path.dirname(__file__), "fuzzer_tests") OUT_DIR = os.path.join(os.path.dirname(__file__), "fuzzer_tests")
@ -210,7 +210,7 @@ def get_test_class(orig_f_name: str, cases: Set[Params]) -> str:
def generate_tests(files: List[str], seed_num: int, generation_fn: Callable[[str], Set[Params]], out_dir: str): 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) load_benchmark(save_instrumented=False, files_count=files)
seed(seed_num) # init random seed seed(seed_num) # init random seed
for file_name, f_names in tqdm(get_benchmark().items(), desc="Generating tests"): for file_name, f_names in tqdm(get_benchmark().items(), desc="Generating tests"):

View file

@ -3,22 +3,17 @@ from benchmark.anagram_check import anagram_check
class Test_anagram_check(TestCase): class Test_anagram_check(TestCase):
# distances_true = {1: [8], 3: [0]} # distances_true = {1: [0], 2: [0]}
# distances_false = {1: [0], 3: [7]} # distances_false = {1: [1], 2: [1]}
def test_anagram_check_1(self): def test_anagram_check_1(self):
assert anagram_check(s1='gU(@sp?!<', s2='^$') == False assert anagram_check(s1='2', s2='K') == False
# distances_true = {1: [1], 3: [0]}
# distances_false = {1: [0], 3: [1]}
def test_anagram_check_2(self):
assert anagram_check(s1='NW', s2='^') == False
# distances_true = {1: [2], 3: [1], 4: [3]} # distances_true = {1: [2], 3: [1], 4: [3]}
# distances_false = {1: [0], 3: [0], 4: [0]} # distances_false = {1: [0], 3: [0], 4: [0]}
def test_anagram_check_2(self):
assert anagram_check(s1='N9)', s2='%;r') == False
# distances_true = {1: [0], 2: [0]}
# distances_false = {1: [1], 2: [1]}
def test_anagram_check_3(self): def test_anagram_check_3(self):
assert anagram_check(s1='j', s2='7') == False assert anagram_check(s1='I@N', s2='}*9') == False
# distances_true = {1: [0], 2: [2], 3: [0]}
# distances_false = {1: [1], 2: [0], 3: [2]}
def test_anagram_check_4(self):
assert anagram_check(s1='i', s2='E y') == False

View file

@ -4,14 +4,14 @@ from benchmark.caesar_cipher import decrypt
class Test_encrypt(TestCase): class Test_encrypt(TestCase):
# distances_true = {1: [0, 6, 0, 10, 0, 0, 0, 0]} # distances_true = {1: [24, 61, 0, 0, 48, 5]}
# distances_false = {1: [48, 0, 60, 0, 57, 30, 25, 47]} # distances_false = {1: [0, 0, 12, 18, 0, 0]}
def test_encrypt_1(self): def test_encrypt_1(self):
assert encrypt(strng='_*k&hMH^', key=79) == 'Oy[uX=8N' assert encrypt(strng='P+sy8c', key=23) == 'gB+1Oz'
class Test_decrypt(TestCase): class Test_decrypt(TestCase):
# distances_true = {2: [0, 0, 32, 0]} # distances_true = {2: [9, 0, 43, 25, 0, 8, 42]}
# distances_false = {2: [1, 12, 0, 24]} # distances_false = {2: [0, 8, 0, 0, 5, 0, 0]}
def test_decrypt_1(self): def test_decrypt_1(self):
assert decrypt(strng='\\Q|E', key=61) == '~s?g' assert decrypt(strng='VFxfIUw', key=46) == "(wJ8z'I"

View file

@ -3,22 +3,17 @@ from benchmark.check_armstrong import check_armstrong
class Test_check_armstrong(TestCase): class Test_check_armstrong(TestCase):
# distances_true = {1: [583], 2: [582], 3: [433], 4: [0, 0, 0, 1], 5: [81]} # distances_true = {1: [1], 2: [0]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [583, 58, 5, 0], 5: [0]} # distances_false = {1: [0], 2: [1]}
def test_check_armstrong_1(self): def test_check_armstrong_1(self):
assert check_armstrong(n=583) == False assert check_armstrong(n=1) == True
# distances_true = {1: [0]} # distances_true = {1: [135], 2: [134], 3: [0]}
# distances_false = {1: [1]} # distances_false = {1: [0], 2: [0], 3: [16]}
def test_check_armstrong_2(self): def test_check_armstrong_2(self):
assert check_armstrong(n=0) == True assert check_armstrong(n=135) == False
# distances_true = {1: [153], 2: [152], 3: [3], 4: [0, 0, 0, 1], 5: [0]} # distances_true = {1: [307], 2: [306], 3: [157], 4: [0, 0, 0, 1], 5: [63]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [153, 15, 1, 0], 5: [1]} # distances_false = {1: [0], 2: [0], 3: [0], 4: [307, 30, 3, 0], 5: [0]}
def test_check_armstrong_3(self): def test_check_armstrong_3(self):
assert check_armstrong(n=153) == True assert check_armstrong(n=307) == False
# distances_true = {1: [5], 2: [4], 3: [0]}
# distances_false = {1: [0], 2: [0], 3: [146]}
def test_check_armstrong_4(self):
assert check_armstrong(n=5) == False

View file

@ -3,17 +3,32 @@ from benchmark.common_divisor_count import cd_count
class Test_cd_count(TestCase): class Test_cd_count(TestCase):
# distances_true = {1: [180], 2: [450], 3: [0], 4: [451], 5: [0, 0, 1], 6: [0, 0, 0, 2, 0, 0, 6, 2, 0], 7: [89, 43, 27, 13, 9, 1]} # distances_true = {1: [301], 2: [0]}
# distances_false = {1: [0], 2: [0], 3: [180], 4: [0], 5: [180, 90, 0], 6: [1, 1, 1, 0, 1, 1, 0, 0, 1], 7: [0, 0, 0, 0, 0, 0]} # distances_false = {1: [0], 2: [1]}
def test_cd_count_1(self): def test_cd_count_1(self):
assert cd_count(a=-180, b=450) == 12 assert cd_count(a=301, b=0) == 2
# distances_true = {1: [524], 2: [858], 3: [525], 4: [0], 5: [0, 0, 0, 0, 0, 0, 0, 0, 1], 6: [0], 7: [1]} # distances_true = {1: [28], 2: [7], 3: [29], 4: [8], 5: [0, 0, 1], 6: [0, 1], 7: [6]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [858], 5: [524, 334, 190, 144, 46, 6, 4, 2, 0], 6: [1], 7: [0]} # distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [28, 7, 0], 6: [1, 0], 7: [0]}
def test_cd_count_2(self): def test_cd_count_2(self):
assert cd_count(a=524, b=-858) == 2 assert cd_count(a=28, b=7) == 2
# distances_true = {1: [171], 2: [880], 3: [0], 4: [881], 5: [0, 0, 0, 0, 0, 1], 6: [0], 7: [0]} # distances_true = {1: [153], 2: [2], 3: [154], 4: [3], 5: [0, 0, 0, 1], 6: [0], 7: [0]}
# distances_false = {1: [0], 2: [0], 3: [171], 4: [0], 5: [171, 25, 21, 4, 1, 0], 6: [1], 7: [1]} # distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [153, 2, 1, 0], 6: [1], 7: [1]}
def test_cd_count_3(self): def test_cd_count_3(self):
assert cd_count(a=-171, b=880) == 1 assert cd_count(a=153, b=2) == 1
# distances_true = {1: [502], 2: [178], 3: [503], 4: [179], 5: [0, 0, 0, 0, 0, 0, 0, 0, 1], 6: [0], 7: [1]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [502, 178, 146, 32, 18, 14, 4, 2, 0], 6: [1], 7: [0]}
def test_cd_count_4(self):
assert cd_count(a=502, b=178) == 2
# distances_true = {1: [0]}
# distances_false = {1: [1]}
def test_cd_count_5(self):
assert cd_count(a=0, b=904) == 2
# distances_true = {1: [443], 2: [6], 3: [0], 4: [0], 5: [0, 0, 0, 0, 1], 6: [0], 7: [0]}
# distances_false = {1: [0], 2: [0], 3: [443], 4: [6], 5: [443, 6, 5, 1, 0], 6: [1], 7: [1]}
def test_cd_count_6(self):
assert cd_count(a=-443, b=-6) == 1

View file

@ -3,7 +3,7 @@ from benchmark.exponentiation import exponentiation
class Test_exponentiation(TestCase): class Test_exponentiation(TestCase):
# distances_true = {1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 3: [0], 2: [1, 1, 0, 0, 0, 1, 0, 0, 0]} # distances_true = {1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 3: [0], 2: [0, 1, 0, 1, 1, 1, 1, 1, 0]}
# distances_false = {1: [630, 314, 156, 77, 38, 18, 8, 3, 1, 0], 3: [1], 2: [0, 0, 1, 1, 1, 0, 1, 1, 1]} # distances_false = {1: [832, 415, 207, 103, 51, 25, 12, 5, 2, 0], 3: [1], 2: [1, 0, 1, 0, 0, 0, 0, 0, 1]}
def test_exponentiation_1(self): def test_exponentiation_1(self):
assert exponentiation(baseNumber=229, power=631) == 11381234101445775753511392015341744682588570986102224039390720285077899169674568038197326342940064901244177560842841924371421802587044521315773772186187547659830685455568537528049212994980159679816838690878596437635556336390603217974843590523706585633093363478766247718669151124253597924271460074695331123030002477672470888683820892451691712794240150714666068396254837851712428304279437706402840278841022427798845642299620119122197582242489041676042030717852031723255821528213497142055551145575663634990077305256845727132894737670148720272258452398194448015830799903170149287684706972565823541486622411136605841318617521051177682587295876588617192583199512651351936677507861660939730278101046178558162552821556410557719089125378645170386340572632243077354907575845913647147461310394166725741203050654294205855227960718731811784697401084780988753863828019215023964034022075473428520603004040086437560944507735374937837026821029527152268670187574842115160681136501433596553090081291095916580753660680615454664168228698567169031280782756475821551196582762941080904807113833394318850338264484961526692224500757025151325286773628959521989541968478235125022809094655704670640668124923174654970259046198975073787375738402994461267901157313580710146722768111601235186132446805107849024669181014876768249128669364324993951100257739165644330717095953945583658926347402457474225454535689578418160695265405822296417373349554757877558059686302770208714142534097327460841575601330771335995265872402591629 assert exponentiation(baseNumber=-6, power=833) == -1584862427176646441032581448163502056522304714791688863077680763401594759422056202480618372145524894456151986289670118768654538337866053263611922000599918608949612484758034859452586327393651279190541552669586881048781584189639428134027926187502542805755360587303203758250141709609935145755270362171617090607605771330425353289800694836743426874185222171194524983577694492237864072603517346560417482797868100221342243559501229220749459182746246997902149679964895722044423357661248125544267360836746288616059898701793481334662209049986346281366837693465240393495058780389499730155312477987604559702499972667524745974854042821278371009362182850127855616

View file

@ -3,12 +3,27 @@ from benchmark.gcd import gcd
class Test_gcd(TestCase): class Test_gcd(TestCase):
# distances_true = {1: [182], 2: [931], 3: [749], 4: [0], 5: [0, 0, 0, 0, 0, 1]} # distances_true = {1: [0]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [749], 5: [183, 17, 13, 4, 1, 0]} # distances_false = {1: [1]}
def test_gcd_1(self): def test_gcd_1(self):
assert gcd(a=183, b=932) == 1 assert gcd(a=1, b=751) == 1
# distances_true = {1: [720], 2: [503], 3: [217], 4: [218], 5: [0, 0, 0, 0, 1]} # distances_true = {1: [964], 2: [964], 3: [0]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [504, 217, 70, 7, 0]} # distances_false = {1: [0], 2: [0], 3: [1]}
def test_gcd_2(self): def test_gcd_2(self):
assert gcd(a=721, b=504) == 7 assert gcd(a=965, b=965) == 965
# distances_true = {1: [700], 2: [440], 3: [260], 4: [261], 5: [0, 0, 0, 0, 0, 0, 0, 0, 1]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [441, 260, 181, 79, 23, 10, 3, 1, 0]}
def test_gcd_3(self):
assert gcd(a=701, b=441) == 1
# distances_true = {1: [941], 2: [944], 3: [3], 4: [0], 5: [0, 0, 1]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [3], 5: [942, 3, 0]}
def test_gcd_4(self):
assert gcd(a=942, b=945) == 3
# distances_true = {1: [354], 2: [0]}
# distances_false = {1: [0], 2: [1]}
def test_gcd_5(self):
assert gcd(a=355, b=1) == 1

View file

@ -3,12 +3,7 @@ from benchmark.longest_substring import longest_sorted_substr
class Test_longest_sorted_substr(TestCase): class Test_longest_sorted_substr(TestCase):
# distances_true = {1: [5, 0, 56, 0, 81, 0, 0], 2: [0, 1, 1, 0]} # distances_true = {1: [0, 17, 12, 17, 0, 47, 10, 0], 2: [0, 1, 1]}
# distances_false = {1: [0, 38, 0, 86, 0, 5, 57], 2: [1, 0, 0, 1]} # distances_false = {1: [12, 0, 0, 0, 42, 0, 0, 3], 2: [1, 0, 0]}
def test_longest_sorted_substr_1(self): def test_longest_sorted_substr_1(self):
assert longest_sorted_substr(s='<7\\$y(,d') == '(,d' assert longest_sorted_substr(s='\\gVJ9b3)+') == '\\g'
# distances_true = {1: [29, 2, 0, 50], 2: [0]}
# distances_false = {1: [0, 0, 35, 0], 2: [1]}
def test_longest_sorted_substr_2(self):
assert longest_sorted_substr(s='Q42T"') == '2T'

View file

@ -3,22 +3,12 @@ from benchmark.rabin_karp import rabin_karp_search
class Test_rabin_karp_search(TestCase): class Test_rabin_karp_search(TestCase):
# distances_true = {1: [0, 70, 54, 65, 28, 51, 66], 3: [1], 4: [0, 0, 0, 0, 0, 0, 1], 5: [71, 55, 66, 29, 52, 67]} # distances_true = {1: [69, 86], 4: [0, 1], 5: [15]}
# distances_false = {1: [1, 0, 0, 0, 0, 0, 0], 3: [0], 4: [6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0]} # distances_false = {1: [0, 0], 4: [1, 0], 5: [0]}
def test_rabin_karp_search_1(self): def test_rabin_karp_search_1(self):
assert rabin_karp_search(pat='', txt=']vzK<k') == [] assert rabin_karp_search(pat='Hi', txt=';Wd') == []
# distances_true = {1: [43, 0, 35, 7, 61], 4: [0, 0, 0, 0, 1], 5: [62, 27, 69, 1], 2: [0], 3: [2]} # distances_true = {1: [53, 0], 4: [0, 1], 5: [94], 2: [0], 3: [1]}
# distances_false = {1: [0, 1, 0, 0, 0], 4: [4, 3, 2, 1, 0], 5: [0, 0, 0, 0], 2: [53], 3: [0]} # distances_false = {1: [0, 1], 4: [1, 0], 5: [0], 2: [47], 3: [0]}
def test_rabin_karp_search_2(self): def test_rabin_karp_search_2(self):
assert rabin_karp_search(pat='z+e', txt=':EQBa9M') == [] assert rabin_karp_search(pat='+g', txt='rZJ') == []
# distances_true = {1: [50, 61, 64, 66, 16, 14, 66], 4: [0, 0, 0, 0, 0, 0, 1], 5: [16, 13, 11, 93, 63, 11]}
# distances_false = {1: [0, 0, 0, 0, 0, 0, 0], 4: [6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0]}
def test_rabin_karp_search_3(self):
assert rabin_karp_search(pat='f)', txt='^E}QhXq_') == []
# distances_true = {1: [14, 24, 0, 29, 5, 70, 55], 4: [0, 0, 0, 0, 0, 0, 1], 5: [65, 89, 60, 84, 19, 34], 2: [1], 3: [0]}
# distances_false = {1: [0, 0, 1, 0, 0, 0, 0], 4: [6, 5, 4, 3, 2, 1, 0], 5: [0, 0, 0, 0, 0, 0], 2: [0], 3: [1]}
def test_rabin_karp_search_4(self):
assert rabin_karp_search(pat='X', txt='J@X;Sw!') == [2]

View file

@ -4,34 +4,24 @@ from benchmark.railfence_cipher import raildecrypt
class Test_railencrypt(TestCase): class Test_railencrypt(TestCase):
# distances_true = {1: [0], 2: [944], 4: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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_false = {1: [1, 1, 1, 1, 0, 0, 0, 1], 2: [0, 0, 0, 1, 0], 3: [0, 0, 1], 4: [106, 0, 0, 0, 0, 0, 38, 0, 0, 57, 0, 0, 0, 77, 0, 32, 0, 0, 41, 0, 108, 0, 0, 0, 0, 0, 0, 119, 0, 0, 0, 0]}
def test_railencrypt_1(self): def test_railencrypt_1(self):
assert railencrypt(st='}', k=945) == '}' assert railencrypt(st='j9)wlM& ', k=4) == 'j&9M )lw'
# 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_true = {1: [0, 0, 0, 0, 0, 0, 0, 0], 2: [61, 60, 59, 58, 57, 56, 55, 54], 4: [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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# distances_false = {1: [1, 1, 1, 1, 1, 1, 1, 1, 0], 2: [0, 0, 0, 0, 0, 0, 0, 1], 3: [0], 4: [119, 0, 0, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 107, 0, 122, 0, 0, 0, 0, 0, 0, 0, 72, 0]}
def test_railencrypt_3(self):
assert railencrypt(st='w[*]^=kHz', k=8) == 'w[*]^=kzH'
class Test_raildecrypt(TestCase): class Test_raildecrypt(TestCase):
# distances_true = {5: [0, 0, 0, 0, 0, 0, 0, 0, 0], 6: [43, 42, 41, 40, 39, 38, 37, 36, 35], 8: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 9: [73, 68, 91, 120, 37, 34, 41, 61, 107], 10: [0, 1, 1, 1, 1, 1, 1, 1, 1], 12: [1], 11: [0, 0, 0, 0, 0, 0, 0, 0]} # distances_false = {5: [1, 1, 1, 0, 0, 1, 1], 6: [0, 0, 1, 0, 1], 7: [0, 1], 8: [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1], 9: [80, 119, 85, 119, 33, 102, 116], 10: [0, 1, 1, 0, 0, 1, 1], 12: [1, 0, 1], 11: [0, 1, 0, 1]}
def test_raildecrypt_1(self): def test_raildecrypt_1(self):
assert raildecrypt(st='ID[x%")=k', k=44) == 'ID[x%")=k' assert raildecrypt(st='P!wwfUt', k=3) == 'PwUw!ft'
# distances_true = {5: [0, 0, 0, 0, 1, 1, 1, 0, 0], 6: [3, 2, 1, 0, 2, 1], 7: [2, 1, 0], 8: [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], 9: [0, 0, 0, 0, 0, 0, 0, 0, 0], 10: [9, 0, 0, 0, 1, 1, 1, 0, 0], 12: [0, 2, 1, 0], 11: [2, 1, 0, 2, 1]} # distances_true = {5: [0], 6: [365], 8: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 9: [88], 10: [0], 12: [1]}
def test_raildecrypt_2(self): def test_raildecrypt_2(self):
assert raildecrypt(st='-B=96hGF$', k=4) == '-=h$G9B6F' assert raildecrypt(st='X', k=366) == 'X'
# distances_true = {5: [0, 0, 0, 0, 0, 0, 1, 1], 6: [5, 4, 3, 2, 1, 0], 7: [4, 3], 8: [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1], 9: [0, 0, 0, 0, 0, 0, 0, 0], 10: [8, 0, 0, 0, 0, 0, 1, 1], 12: [0, 4, 3], 11: [4, 3, 2, 1, 0]}
# distances_false = {5: [1, 1, 1, 1, 1, 1, 0, 0], 6: [0, 0, 0, 0, 0, 1], 7: [0, 0], 8: [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0], 9: [51, 99, 79, 96, 77, 65, 72, 104], 10: [0, 1, 1, 1, 1, 1, 0, 0], 12: [1, 0, 0], 11: [0, 0, 0, 0, 1]}
def test_raildecrypt_3(self):
assert raildecrypt(st='3cO`hMHA', k=6) == '3cO`MAHh'

View file

@ -3,22 +3,32 @@ from benchmark.zellers_birthday import zeller
class Test_zeller(TestCase): class Test_zeller(TestCase):
# distances_true = {1: [6], 2: [0], 3: [0], 4: [7], 5: [0], 6: [0], 7: [0], 8: [2, 1, 0]} # distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [0], 8: [2, 1, 0]}
# distances_false = {1: [0], 2: [121], 3: [71], 4: [0], 5: [71], 6: [7], 7: [1], 8: [0, 0, 1]} # distances_false = {1: [214], 2: [49], 3: [78], 4: [1], 5: [0], 7: [1], 8: [0, 0, 1]}
def test_zeller_1(self): def test_zeller_1(self):
assert zeller(d=-26, m=133, y=29) == 'Tuesday' assert zeller(d=245, m=-61, y=-22) == 'Tuesday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1904], 7: [3], 8: [6, 5, 4, 3, 2, 1, 0]} # distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1916], 7: [9], 8: [5, 4, 3, 2, 1, 0]}
# distances_false = {1: [929], 2: [304], 3: [97], 4: [20], 5: [0], 7: [0], 8: [0, 0, 0, 0, 0, 0, 1]} # distances_false = {1: [601], 2: [838], 3: [85], 4: [8], 5: [0], 7: [0], 8: [0, 0, 0, 0, 0, 1]}
def test_zeller_2(self): def test_zeller_2(self):
assert zeller(d=960, m=-316, y=-3) == 'Saturday' assert zeller(d=-632, m=-850, y=15) == 'Friday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [74], 5: [0], 6: [0], 7: [0], 8: [3, 2, 1, 0]} # distances_true = {1: [5], 2: [0], 3: [0], 4: [9], 5: [0], 6: [0], 7: [10], 8: [0]}
# distances_false = {1: [932], 2: [552], 3: [4], 4: [0], 5: [4], 6: [74], 7: [2], 8: [0, 0, 0, 1]} # distances_false = {1: [0], 2: [47], 3: [69], 4: [0], 5: [69], 6: [9], 7: [0], 8: [1]}
def test_zeller_3(self): def test_zeller_3(self):
assert zeller(d=963, m=-564, y=96) == 'Wednesday' assert zeller(d=-27, m=-59, y=-31) == 'Sunday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [58], 5: [0], 6: [0], 7: [3], 8: [3, 2, 1, 0]} # distances_true = {1: [0], 2: [6], 3: [0], 4: [0], 5: [1915], 7: [5], 8: [5, 4, 3, 2, 1, 0]}
# distances_false = {1: [492], 2: [988], 3: [20], 4: [0], 5: [20], 6: [58], 7: [0], 8: [0, 0, 0, 1]} # distances_false = {1: [885], 2: [0], 3: [86], 4: [9], 5: [0], 7: [0], 8: [0, 0, 0, 0, 0, 1]}
def test_zeller_4(self): def test_zeller_4(self):
assert zeller(d=-523, m=-1000, y=80) == 'Wednesday' assert zeller(d=916, m=7, y=-14) == 'Friday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [8], 8: [0]}
# distances_false = {1: [256], 2: [21], 3: [78], 4: [1], 5: [0], 7: [0], 8: [1]}
def test_zeller_5(self):
assert zeller(d=287, m=-33, y=-22) == 'Sunday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [5], 5: [0], 6: [0], 7: [4], 8: [0]}
# distances_false = {1: [18], 2: [41], 3: [73], 4: [0], 5: [73], 6: [5], 7: [0], 8: [1]}
def test_zeller_6(self):
assert zeller(d=-49, m=-53, y=-27) == 'Sunday'

View file

@ -12,12 +12,11 @@ import instrument
import operators import operators
from archive import Archive from archive import Archive
INDMUPROB = 0.05
MUPROB = 0.33 MUPROB = 0.33
CXPROB = 0.33 CXPROB = 0.33
TOURNSIZE = 3 TOURNSIZE = 3
NPOP = 200 NPOP = 200
NGEN = 30 NGEN = 20
REPS = 10 REPS = 10
OUT_DIR = os.path.join(os.path.dirname(__file__), "tests") OUT_DIR = os.path.join(os.path.dirname(__file__), "tests")
@ -102,7 +101,7 @@ def compute_fitness(f_name: str, archive: Archive, individual: list) -> Tuple[fl
try: try:
out = instrument.invoke(f_name, x) out = instrument.invoke(f_name, x)
except AssertionError: except AssertionError:
print(f_name, x, "=", "[FAILS] fitness = inf") # print(f_name, x, "=", "[FAILS] fitness = inf")
return math.inf, return math.inf,
fitness = 0.0 fitness = 0.0
@ -128,7 +127,7 @@ def compute_fitness(f_name: str, archive: Archive, individual: list) -> Tuple[fl
if no_branches_hit: if no_branches_hit:
fitness = 1000000 fitness = 1000000
print(f_name, x, "=", out, "fitness =", fitness) # print(f_name, x, "=", out, "fitness =", fitness)
return fitness, return fitness,

View file

@ -6,6 +6,7 @@ from typing import Optional, Dict, DefaultDict, Tuple, List
import astunparse import astunparse
import frozendict import frozendict
import pandas as pd
import tqdm import tqdm
import operators import operators
@ -23,6 +24,7 @@ class BranchTransformer(ast.NodeTransformer):
instrumented_name: Optional[str] instrumented_name: Optional[str]
in_assert: bool in_assert: bool
in_return: bool in_return: bool
function_nodes: int
def __init__(self): def __init__(self):
self.branch_num = 0 self.branch_num = 0
@ -30,6 +32,7 @@ class BranchTransformer(ast.NodeTransformer):
self.in_assert = False self.in_assert = False
self.in_return = False self.in_return = False
self.branches_range = {} self.branches_range = {}
self.function_nodes = 0
@staticmethod @staticmethod
def to_instrumented_name(name: str): def to_instrumented_name(name: str):
@ -53,6 +56,7 @@ class BranchTransformer(ast.NodeTransformer):
return ast_node return ast_node
def visit_FunctionDef(self, ast_node): def visit_FunctionDef(self, ast_node):
self.function_nodes += 1
self.instrumented_name = ast_node.name self.instrumented_name = ast_node.name
b_start = self.branch_num b_start = self.branch_num
ast_node.name = BranchTransformer.to_instrumented_name(ast_node.name) ast_node.name = BranchTransformer.to_instrumented_name(ast_node.name)
@ -83,7 +87,7 @@ class BranchTransformer(ast.NodeTransformer):
ArgType = str ArgType = str
Arg = Tuple[str, ArgType] Arg = Tuple[str, ArgType]
Params = frozendict.frozendict[str, any] Params = 'frozendict.frozendict[str, any]'
SignatureDict = Dict[str, List[Arg]] SignatureDict = Dict[str, List[Arg]]
n_of_branches: Dict[str, Tuple[int, int]] = {} n_of_branches: Dict[str, Tuple[int, int]] = {}
@ -91,7 +95,7 @@ functions: SignatureDict = {}
module_of: Dict[str, List[str]] = {} module_of: Dict[str, List[str]] = {}
def instrument(source_path: str, target_path: str, save_instrumented=True): def instrument(source_path: str, target_path: str, save_instrumented=True) -> Tuple[int, int]:
global functions, n_of_branches global functions, n_of_branches
with open(source_path, "r") as f: with open(source_path, "r") as f:
@ -102,6 +106,9 @@ def instrument(source_path: str, target_path: str, save_instrumented=True):
b = BranchTransformer() b = BranchTransformer()
b.visit(node) b.visit(node)
functions_found = b.function_nodes
conditions_found = b.branch_num - 1
for f_name, limits in b.branches_range.items(): for f_name, limits in b.branches_range.items():
n_of_branches[f_name] = limits n_of_branches[f_name] = limits
@ -132,6 +139,8 @@ def instrument(source_path: str, target_path: str, save_instrumented=True):
functions[f.name] = arg_types functions[f.name] = arg_types
module_of[f.name] = os.path.splitext(os.path.normpath(os.path.relpath(source_path, ROOT_DIR)))[0].split("/") module_of[f.name] = os.path.splitext(os.path.normpath(os.path.relpath(source_path, ROOT_DIR)))[0].split("/")
return functions_found, conditions_found
def invoke(f_name: str, f_args: Params) -> any: def invoke(f_name: str, f_args: Params) -> any:
global functions global functions
@ -159,14 +168,24 @@ def find_py_files(search_dir: str):
yield os.path.join(cwd, file) yield os.path.join(cwd, file)
def load_benchmark(save_instrumented=True, files: List[str] = ()): def load_benchmark(save_instrumented=True, files_count: List[str] = ()) -> Tuple[int, int, int]:
to_load = set([os.path.splitext(os.path.basename(file))[0] + ".py" for file in files]) to_load = set([os.path.splitext(os.path.basename(file))[0] + ".py" for file in files_count])
do_all = len(to_load) == 0 do_all = len(to_load) == 0
files_count = 0
functions_count = 0
conditions_count = 0
for file in tqdm.tqdm(find_py_files(IN_DIR), desc="Instrumenting"): for file in tqdm.tqdm(find_py_files(IN_DIR), desc="Instrumenting"):
filename = os.path.basename(file) filename = os.path.basename(file)
if do_all or filename in to_load: if do_all or filename in to_load:
instrument(file, os.path.join(OUT_DIR, filename), save_instrumented=save_instrumented) fs, cs = instrument(file, os.path.join(OUT_DIR, filename), save_instrumented=save_instrumented)
files_count += 1
functions_count += fs
conditions_count += cs
return files_count, functions_count, conditions_count
def call_statement(f_name: str, f_args: Params) -> str: def call_statement(f_name: str, f_args: Params) -> str:
@ -191,5 +210,15 @@ def get_benchmark() -> Dict[str, List[str]]:
return dict(names) return dict(names)
def main():
files_count, functions_count, conditions_count = load_benchmark(save_instrumented=True)
df = pd.DataFrame.from_records([
{'Type': 'Python Files', 'Number': files_count},
{'Type': 'Function Nodes', 'Number': functions_count},
{'Type': 'Comparison Nodes', 'Number': conditions_count},
])
print(df.to_latex(index=False))
if __name__ == '__main__': if __name__ == '__main__':
load_benchmark(save_instrumented=True) main()

View file

@ -5,7 +5,7 @@ import subprocess
import sys import sys
from math import sqrt from math import sqrt
from statistics import mean, variance from statistics import mean, variance
from typing import List, Dict from typing import List, Dict, Callable, Set
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
@ -13,6 +13,10 @@ import seaborn as sns
from scipy.stats import wilcoxon from scipy.stats import wilcoxon
from tqdm import tqdm from tqdm import tqdm
import genetic
from fuzzer import generate_tests, fuzzer_generate
from instrument import Params
ROOT_DIR = os.path.dirname(__file__) ROOT_DIR = os.path.dirname(__file__)
IN_SOURCE_DIR = os.path.join(ROOT_DIR, "benchmark") IN_SOURCE_DIR = os.path.join(ROOT_DIR, "benchmark")
IN_TEST_DIR = os.path.join(ROOT_DIR, "tests") IN_TEST_DIR = os.path.join(ROOT_DIR, "tests")
@ -33,6 +37,7 @@ def cohen_d(d1: List[float], d2: List[float]) -> float:
def effect_size(eff: float) -> str: def effect_size(eff: float) -> str:
eff = abs(eff)
if eff <= 0.01: if eff <= 0.01:
return 'Very small' return 'Very small'
elif eff <= 0.2: elif eff <= 0.2:
@ -52,17 +57,21 @@ def compute_stats(df_gen: pd.DataFrame, df_fuz: pd.DataFrame, output_file: str,
combined_df.columns = ['source', *combined_df.columns[1:]] combined_df.columns = ['source', *combined_df.columns[1:]]
del combined_df[combined_df.columns[1]] del combined_df[combined_df.columns[1]]
plt.figure(figsize=(18, 8)) plt.figure(figsize=(10, 6))
sns.set(style="whitegrid") sns.set(style="whitegrid")
sns.boxplot(data=combined_df, x="file", y="score", hue="source") sns.boxplot(data=combined_df, x="file", y="score", hue="source")
plt.yticks(range(0, 101, 10)) plt.yticks(range(0, 101, 10))
plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig(output_file) plt.savefig(output_file)
plt.figure(figsize=(18, 8)) plt.figure(figsize=(10, 6))
df_avg = combined_df.groupby(['file', 'source']).mean().reset_index() df_avg = combined_df.groupby(['file', 'source']).mean().reset_index()
sns.set(style="whitegrid") sns.set(style="whitegrid")
sns.barplot(data=df_avg, x="file", y="score", hue="source") sns.barplot(data=df_avg, x="file", y="score", hue="source")
plt.yticks(range(0, 101, 10)) plt.yticks(range(0, 101, 10))
plt.xticks(rotation=45)
plt.tight_layout()
plt.savefig(avg_output_file) plt.savefig(avg_output_file)
df_avg = df_avg.pivot(index='file', columns='source', values='score').rename_axis(None, axis=1) df_avg = df_avg.pivot(index='file', columns='source', values='score').rename_axis(None, axis=1)
@ -86,26 +95,28 @@ def run_mutpy(test_path: str, source_path: str) -> float:
[sys.executable, [sys.executable,
MUT_PY_PATH, MUT_PY_PATH,
'-t', source_path, '-t', source_path,
'-u', test_path, '-u', test_path]).decode('utf-8')
'--hom-strategy', 'RANDOM',
'--percentage', '75']).decode('utf-8')
score = re.search('Mutation score \\[.*]: (\\d+\\.\\d+)%', output).group(1) score = re.search('Mutation score \\[.*]: (\\d+\\.\\d+)%', output).group(1)
return float(score) return float(score)
def mutate_suite(out_file: str, in_test_dir: str, to_test: List[str]): def mutate_suite(out_file: str, in_test_dir: str, to_test: List[str], seeds: List[int],
generation_fn: Callable[[str], Set[Params]]):
scores: List[Dict[str, any]] = [] scores: List[Dict[str, any]] = []
if os.path.isfile(out_file): # do not re-generate if file exists if os.path.isfile(out_file): # do not re-generate if file exists
return pd.read_csv(out_file, index_col=0) return pd.read_csv(out_file, index_col=0)
for filename in tqdm(to_test, desc=f"mut.py [{os.path.basename(out_file)}]"): for seed in tqdm(seeds, desc=f"generating with seeds"):
source_path = os.path.join(IN_SOURCE_DIR, f"{filename}.py") generate_tests([], seed, generation_fn, in_test_dir)
test_path = os.path.join(in_test_dir, f"test_{filename}.py")
scores.append({ for filename in tqdm(to_test, desc=f"mut.py [{os.path.basename(out_file)}]"):
'file': filename, source_path = os.path.join(IN_SOURCE_DIR, f"{filename}.py")
'score': run_mutpy(test_path, source_path) test_path = os.path.join(in_test_dir, f"test_{filename}.py")
}) scores.append({
'file': filename,
'score': run_mutpy(test_path, source_path)
})
df = pd.DataFrame.from_records(scores) df = pd.DataFrame.from_records(scores)
df.to_csv(out_file) df.to_csv(out_file)
@ -115,10 +126,15 @@ def mutate_suite(out_file: str, in_test_dir: str, to_test: List[str]):
def main(): def main():
files = [os.path.splitext(f) for f in os.listdir(IN_SOURCE_DIR)] files = [os.path.splitext(f) for f in os.listdir(IN_SOURCE_DIR)]
to_test = [file[0] for file in files if file[1] == ".py"] to_test = [file[0] for file in files if file[1] == ".py"]
to_test = [e for t in to_test for e in ([t] * REPS)]
df_gen = mutate_suite(os.path.join(OUT_DIR, 'mutation_results_genetic.csv'), IN_TEST_DIR, to_test) seeds = [182, 81, 95, 16, 124, 166, 178, 22, 20, 54]
df_fuz = mutate_suite(os.path.join(OUT_DIR, 'mutation_results_fuzzer.csv'), IN_FUZZER_TEST_DIR, to_test)
genetic.init_deap()
df_gen = mutate_suite(os.path.join(OUT_DIR, 'mutation_results_genetic.csv'), IN_TEST_DIR, to_test, seeds,
genetic.generate)
df_fuz = mutate_suite(os.path.join(OUT_DIR, 'mutation_results_fuzzer.csv'), IN_FUZZER_TEST_DIR, to_test, seeds,
fuzzer_generate)
compute_stats(df_gen, df_fuz, compute_stats(df_gen, df_fuz,
os.path.join(OUT_DIR, "mutation_scores.png"), os.path.join(OUT_DIR, "mutation_scores.png"),

View file

@ -1,101 +1,101 @@
,file,score ,file,score
0,anagram_check,16.7 0,anagram_check,23.1
1,anagram_check,9.1 1,caesar_cipher,61.8
2,anagram_check,25.0 2,check_armstrong,83.9
3,anagram_check,20.0 3,common_divisor_count,74.5
4,anagram_check,33.3 4,exponentiation,71.4
5,anagram_check,12.5 5,gcd,60.9
6,anagram_check,30.0 6,longest_substring,69.6
7,anagram_check,25.0 7,rabin_karp,28.1
8,anagram_check,30.0 8,railfence_cipher,88.3
9,anagram_check,30.0 9,zellers_birthday,68.3
10,caesar_cipher,61.5 10,anagram_check,23.1
11,caesar_cipher,60.9 11,caesar_cipher,61.8
12,caesar_cipher,60.0 12,check_armstrong,77.4
13,caesar_cipher,58.1 13,common_divisor_count,78.7
14,caesar_cipher,67.9 14,exponentiation,68.6
15,caesar_cipher,56.0 15,gcd,65.2
16,caesar_cipher,58.3 16,longest_substring,73.9
17,caesar_cipher,61.5 17,rabin_karp,26.3
18,caesar_cipher,70.0 18,railfence_cipher,89.4
19,caesar_cipher,47.6 19,zellers_birthday,72.5
20,check_armstrong,88.0 20,anagram_check,23.1
21,check_armstrong,88.9 21,caesar_cipher,61.8
22,check_armstrong,90.9 22,check_armstrong,25.8
23,check_armstrong,94.1 23,common_divisor_count,76.6
24,check_armstrong,87.0 24,exponentiation,68.6
25,check_armstrong,88.9 25,gcd,56.5
26,check_armstrong,88.9 26,longest_substring,78.3
27,check_armstrong,91.7 27,rabin_karp,26.3
28,check_armstrong,88.5 28,railfence_cipher,88.3
29,check_armstrong,88.5 29,zellers_birthday,72.5
30,common_divisor_count,71.4 30,anagram_check,23.1
31,common_divisor_count,71.0 31,caesar_cipher,58.8
32,common_divisor_count,71.4 32,check_armstrong,38.7
33,common_divisor_count,75.0 33,common_divisor_count,76.6
34,common_divisor_count,65.5 34,exponentiation,68.6
35,common_divisor_count,71.4 35,gcd,60.9
36,common_divisor_count,75.0 36,longest_substring,78.3
37,common_divisor_count,63.9 37,rabin_karp,50.9
38,common_divisor_count,78.1 38,railfence_cipher,87.2
39,common_divisor_count,69.4 39,zellers_birthday,70.0
40,exponentiation,66.7 40,anagram_check,23.1
41,exponentiation,67.9 41,caesar_cipher,58.8
42,exponentiation,74.1 42,check_armstrong,45.2
43,exponentiation,72.0 43,common_divisor_count,74.5
44,exponentiation,65.4 44,exponentiation,71.4
45,exponentiation,61.5 45,gcd,60.9
46,exponentiation,67.7 46,longest_substring,82.6
47,exponentiation,70.8 47,rabin_karp,24.6
48,exponentiation,71.4 48,railfence_cipher,89.4
49,exponentiation,72.4 49,zellers_birthday,62.5
50,gcd,53.3 50,anagram_check,23.1
51,gcd,60.0 51,caesar_cipher,58.8
52,gcd,37.5 52,check_armstrong,83.9
53,gcd,52.9 53,common_divisor_count,78.7
54,gcd,47.4 54,exponentiation,68.6
55,gcd,45.0 55,gcd,43.5
56,gcd,62.5 56,longest_substring,78.3
57,gcd,55.6 57,rabin_karp,15.8
58,gcd,43.8 58,railfence_cipher,87.2
59,gcd,50.0 59,zellers_birthday,67.5
60,longest_substring,85.7 60,anagram_check,23.1
61,longest_substring,88.2 61,caesar_cipher,58.8
62,longest_substring,82.4 62,check_armstrong,25.8
63,longest_substring,85.7 63,common_divisor_count,74.5
64,longest_substring,75.0 64,exponentiation,68.6
65,longest_substring,86.7 65,gcd,60.9
66,longest_substring,76.5 66,longest_substring,82.6
67,longest_substring,75.0 67,rabin_karp,26.3
68,longest_substring,94.4 68,railfence_cipher,89.4
69,longest_substring,90.0 69,zellers_birthday,69.2
70,rabin_karp,61.4 70,anagram_check,23.1
71,rabin_karp,70.0 71,caesar_cipher,61.8
72,rabin_karp,65.0 72,check_armstrong,77.4
73,rabin_karp,60.5 73,common_divisor_count,78.7
74,rabin_karp,68.4 74,exponentiation,71.4
75,rabin_karp,71.8 75,gcd,60.9
76,rabin_karp,67.6 76,longest_substring,78.3
77,rabin_karp,63.9 77,rabin_karp,29.8
78,rabin_karp,72.5 78,railfence_cipher,89.4
79,rabin_karp,60.4 79,zellers_birthday,66.7
80,railfence_cipher,88.6 80,anagram_check,23.1
81,railfence_cipher,86.8 81,caesar_cipher,64.7
82,railfence_cipher,93.8 82,check_armstrong,77.4
83,railfence_cipher,90.6 83,common_divisor_count,72.3
84,railfence_cipher,88.6 84,exponentiation,68.6
85,railfence_cipher,90.0 85,gcd,60.9
86,railfence_cipher,91.0 86,longest_substring,69.6
87,railfence_cipher,90.4 87,rabin_karp,24.6
88,railfence_cipher,91.0 88,railfence_cipher,87.2
89,railfence_cipher,92.0 89,zellers_birthday,64.2
90,zellers_birthday,68.1 90,anagram_check,23.1
91,zellers_birthday,73.0 91,caesar_cipher,58.8
92,zellers_birthday,70.7 92,check_armstrong,45.2
93,zellers_birthday,68.5 93,common_divisor_count,76.6
94,zellers_birthday,71.0 94,exponentiation,68.6
95,zellers_birthday,65.6 95,gcd,60.9
96,zellers_birthday,67.4 96,longest_substring,82.6
97,zellers_birthday,67.8 97,rabin_karp,26.3
98,zellers_birthday,68.8 98,railfence_cipher,88.3
99,zellers_birthday,70.1 99,zellers_birthday,67.5

1 file score
2 0 anagram_check 16.7 23.1
3 1 anagram_check caesar_cipher 9.1 61.8
4 2 anagram_check check_armstrong 25.0 83.9
5 3 anagram_check common_divisor_count 20.0 74.5
6 4 anagram_check exponentiation 33.3 71.4
7 5 anagram_check gcd 12.5 60.9
8 6 anagram_check longest_substring 30.0 69.6
9 7 anagram_check rabin_karp 25.0 28.1
10 8 anagram_check railfence_cipher 30.0 88.3
11 9 anagram_check zellers_birthday 30.0 68.3
12 10 caesar_cipher anagram_check 61.5 23.1
13 11 caesar_cipher 60.9 61.8
14 12 caesar_cipher check_armstrong 60.0 77.4
15 13 caesar_cipher common_divisor_count 58.1 78.7
16 14 caesar_cipher exponentiation 67.9 68.6
17 15 caesar_cipher gcd 56.0 65.2
18 16 caesar_cipher longest_substring 58.3 73.9
19 17 caesar_cipher rabin_karp 61.5 26.3
20 18 caesar_cipher railfence_cipher 70.0 89.4
21 19 caesar_cipher zellers_birthday 47.6 72.5
22 20 check_armstrong anagram_check 88.0 23.1
23 21 check_armstrong caesar_cipher 88.9 61.8
24 22 check_armstrong 90.9 25.8
25 23 check_armstrong common_divisor_count 94.1 76.6
26 24 check_armstrong exponentiation 87.0 68.6
27 25 check_armstrong gcd 88.9 56.5
28 26 check_armstrong longest_substring 88.9 78.3
29 27 check_armstrong rabin_karp 91.7 26.3
30 28 check_armstrong railfence_cipher 88.5 88.3
31 29 check_armstrong zellers_birthday 88.5 72.5
32 30 common_divisor_count anagram_check 71.4 23.1
33 31 common_divisor_count caesar_cipher 71.0 58.8
34 32 common_divisor_count check_armstrong 71.4 38.7
35 33 common_divisor_count 75.0 76.6
36 34 common_divisor_count exponentiation 65.5 68.6
37 35 common_divisor_count gcd 71.4 60.9
38 36 common_divisor_count longest_substring 75.0 78.3
39 37 common_divisor_count rabin_karp 63.9 50.9
40 38 common_divisor_count railfence_cipher 78.1 87.2
41 39 common_divisor_count zellers_birthday 69.4 70.0
42 40 exponentiation anagram_check 66.7 23.1
43 41 exponentiation caesar_cipher 67.9 58.8
44 42 exponentiation check_armstrong 74.1 45.2
45 43 exponentiation common_divisor_count 72.0 74.5
46 44 exponentiation 65.4 71.4
47 45 exponentiation gcd 61.5 60.9
48 46 exponentiation longest_substring 67.7 82.6
49 47 exponentiation rabin_karp 70.8 24.6
50 48 exponentiation railfence_cipher 71.4 89.4
51 49 exponentiation zellers_birthday 72.4 62.5
52 50 gcd anagram_check 53.3 23.1
53 51 gcd caesar_cipher 60.0 58.8
54 52 gcd check_armstrong 37.5 83.9
55 53 gcd common_divisor_count 52.9 78.7
56 54 gcd exponentiation 47.4 68.6
57 55 gcd 45.0 43.5
58 56 gcd longest_substring 62.5 78.3
59 57 gcd rabin_karp 55.6 15.8
60 58 gcd railfence_cipher 43.8 87.2
61 59 gcd zellers_birthday 50.0 67.5
62 60 longest_substring anagram_check 85.7 23.1
63 61 longest_substring caesar_cipher 88.2 58.8
64 62 longest_substring check_armstrong 82.4 25.8
65 63 longest_substring common_divisor_count 85.7 74.5
66 64 longest_substring exponentiation 75.0 68.6
67 65 longest_substring gcd 86.7 60.9
68 66 longest_substring 76.5 82.6
69 67 longest_substring rabin_karp 75.0 26.3
70 68 longest_substring railfence_cipher 94.4 89.4
71 69 longest_substring zellers_birthday 90.0 69.2
72 70 rabin_karp anagram_check 61.4 23.1
73 71 rabin_karp caesar_cipher 70.0 61.8
74 72 rabin_karp check_armstrong 65.0 77.4
75 73 rabin_karp common_divisor_count 60.5 78.7
76 74 rabin_karp exponentiation 68.4 71.4
77 75 rabin_karp gcd 71.8 60.9
78 76 rabin_karp longest_substring 67.6 78.3
79 77 rabin_karp 63.9 29.8
80 78 rabin_karp railfence_cipher 72.5 89.4
81 79 rabin_karp zellers_birthday 60.4 66.7
82 80 railfence_cipher anagram_check 88.6 23.1
83 81 railfence_cipher caesar_cipher 86.8 64.7
84 82 railfence_cipher check_armstrong 93.8 77.4
85 83 railfence_cipher common_divisor_count 90.6 72.3
86 84 railfence_cipher exponentiation 88.6 68.6
87 85 railfence_cipher gcd 90.0 60.9
88 86 railfence_cipher longest_substring 91.0 69.6
89 87 railfence_cipher rabin_karp 90.4 24.6
90 88 railfence_cipher 91.0 87.2
91 89 railfence_cipher zellers_birthday 92.0 64.2
92 90 zellers_birthday anagram_check 68.1 23.1
93 91 zellers_birthday caesar_cipher 73.0 58.8
94 92 zellers_birthday check_armstrong 70.7 45.2
95 93 zellers_birthday common_divisor_count 68.5 76.6
96 94 zellers_birthday exponentiation 71.0 68.6
97 95 zellers_birthday gcd 65.6 60.9
98 96 zellers_birthday longest_substring 67.4 82.6
99 97 zellers_birthday rabin_karp 67.8 26.3
100 98 zellers_birthday railfence_cipher 68.8 88.3
101 99 zellers_birthday 70.1 67.5

View file

@ -1,101 +1,101 @@
,file,score ,file,score
0,anagram_check,16.7 0,anagram_check,7.7
1,anagram_check,0.0 1,caesar_cipher,61.8
2,anagram_check,22.2 2,check_armstrong,93.5
3,anagram_check,18.2 3,common_divisor_count,66.0
4,anagram_check,14.3 4,exponentiation,71.4
5,anagram_check,18.2 5,gcd,47.8
6,anagram_check,30.0 6,longest_substring,78.3
7,anagram_check,20.0 7,rabin_karp,45.6
8,anagram_check,18.2 8,railfence_cipher,87.2
9,anagram_check,27.3 9,zellers_birthday,70.0
10,caesar_cipher,61.5 10,anagram_check,7.7
11,caesar_cipher,60.0 11,caesar_cipher,61.8
12,caesar_cipher,66.7 12,check_armstrong,93.5
13,caesar_cipher,61.5 13,common_divisor_count,68.1
14,caesar_cipher,60.9 14,exponentiation,71.4
15,caesar_cipher,66.7 15,gcd,60.9
16,caesar_cipher,61.5 16,longest_substring,78.3
17,caesar_cipher,63.0 17,rabin_karp,50.9
18,caesar_cipher,59.1 18,railfence_cipher,88.3
19,caesar_cipher,63.0 19,zellers_birthday,71.7
20,check_armstrong,85.0 20,anagram_check,7.7
21,check_armstrong,91.7 21,caesar_cipher,61.8
22,check_armstrong,92.3 22,check_armstrong,93.5
23,check_armstrong,91.7 23,common_divisor_count,61.7
24,check_armstrong,85.7 24,exponentiation,68.6
25,check_armstrong,87.5 25,gcd,47.8
26,check_armstrong,92.9 26,longest_substring,69.6
27,check_armstrong,90.0 27,rabin_karp,50.9
28,check_armstrong,87.5 28,railfence_cipher,87.2
29,check_armstrong,87.5 29,zellers_birthday,75.0
30,common_divisor_count,65.6 30,anagram_check,7.7
31,common_divisor_count,74.3 31,caesar_cipher,61.8
32,common_divisor_count,73.7 32,check_armstrong,93.5
33,common_divisor_count,67.6 33,common_divisor_count,72.3
34,common_divisor_count,77.1 34,exponentiation,68.6
35,common_divisor_count,75.0 35,gcd,60.9
36,common_divisor_count,76.5 36,longest_substring,82.6
37,common_divisor_count,72.2 37,rabin_karp,50.9
38,common_divisor_count,70.3 38,railfence_cipher,88.3
39,common_divisor_count,70.3 39,zellers_birthday,73.3
40,exponentiation,68.0 40,anagram_check,7.7
41,exponentiation,68.8 41,caesar_cipher,61.8
42,exponentiation,70.0 42,check_armstrong,93.5
43,exponentiation,78.3 43,common_divisor_count,70.2
44,exponentiation,78.6 44,exponentiation,71.4
45,exponentiation,65.4 45,gcd,47.8
46,exponentiation,60.0 46,longest_substring,78.3
47,exponentiation,65.0 47,rabin_karp,50.9
48,exponentiation,69.2 48,railfence_cipher,87.2
49,exponentiation,61.5 49,zellers_birthday,71.7
50,gcd,47.4 50,anagram_check,7.7
51,gcd,47.4 51,caesar_cipher,58.8
52,gcd,50.0 52,check_armstrong,93.5
53,gcd,43.8 53,common_divisor_count,76.6
54,gcd,44.4 54,exponentiation,68.6
55,gcd,45.0 55,gcd,43.5
56,gcd,43.8 56,longest_substring,69.6
57,gcd,36.8 57,rabin_karp,50.9
58,gcd,44.4 58,railfence_cipher,87.2
59,gcd,43.8 59,zellers_birthday,70.8
60,longest_substring,88.2 60,anagram_check,7.7
61,longest_substring,77.8 61,caesar_cipher,58.8
62,longest_substring,93.8 62,check_armstrong,93.5
63,longest_substring,84.2 63,common_divisor_count,78.7
64,longest_substring,87.5 64,exponentiation,68.6
65,longest_substring,77.8 65,gcd,60.9
66,longest_substring,84.2 66,longest_substring,69.6
67,longest_substring,76.5 67,rabin_karp,50.9
68,longest_substring,81.2 68,railfence_cipher,88.3
69,longest_substring,78.9 69,zellers_birthday,70.8
70,rabin_karp,63.9 70,anagram_check,7.7
71,rabin_karp,60.9 71,caesar_cipher,61.8
72,rabin_karp,65.0 72,check_armstrong,93.5
73,rabin_karp,68.9 73,common_divisor_count,78.7
74,rabin_karp,64.4 74,exponentiation,71.4
75,rabin_karp,66.7 75,gcd,60.9
76,rabin_karp,63.0 76,longest_substring,73.9
77,rabin_karp,64.4 77,rabin_karp,49.1
78,rabin_karp,63.6 78,railfence_cipher,85.1
79,rabin_karp,64.3 79,zellers_birthday,71.7
80,railfence_cipher,90.0 80,anagram_check,7.7
81,railfence_cipher,87.3 81,caesar_cipher,61.8
82,railfence_cipher,89.6 82,check_armstrong,93.5
83,railfence_cipher,90.0 83,common_divisor_count,78.7
84,railfence_cipher,88.4 84,exponentiation,71.4
85,railfence_cipher,86.5 85,gcd,60.9
86,railfence_cipher,92.5 86,longest_substring,87.0
87,railfence_cipher,89.9 87,rabin_karp,49.1
88,railfence_cipher,90.8 88,railfence_cipher,86.2
89,railfence_cipher,91.2 89,zellers_birthday,70.8
90,zellers_birthday,63.6 90,anagram_check,7.7
91,zellers_birthday,69.1 91,caesar_cipher,61.8
92,zellers_birthday,68.6 92,check_armstrong,93.5
93,zellers_birthday,66.3 93,common_divisor_count,76.6
94,zellers_birthday,71.4 94,exponentiation,40.0
95,zellers_birthday,69.9 95,gcd,65.2
96,zellers_birthday,67.4 96,longest_substring,82.6
97,zellers_birthday,68.4 97,rabin_karp,26.3
98,zellers_birthday,65.2 98,railfence_cipher,89.4
99,zellers_birthday,68.7 99,zellers_birthday,71.7

1 file score
2 0 anagram_check 16.7 7.7
3 1 anagram_check caesar_cipher 0.0 61.8
4 2 anagram_check check_armstrong 22.2 93.5
5 3 anagram_check common_divisor_count 18.2 66.0
6 4 anagram_check exponentiation 14.3 71.4
7 5 anagram_check gcd 18.2 47.8
8 6 anagram_check longest_substring 30.0 78.3
9 7 anagram_check rabin_karp 20.0 45.6
10 8 anagram_check railfence_cipher 18.2 87.2
11 9 anagram_check zellers_birthday 27.3 70.0
12 10 caesar_cipher anagram_check 61.5 7.7
13 11 caesar_cipher 60.0 61.8
14 12 caesar_cipher check_armstrong 66.7 93.5
15 13 caesar_cipher common_divisor_count 61.5 68.1
16 14 caesar_cipher exponentiation 60.9 71.4
17 15 caesar_cipher gcd 66.7 60.9
18 16 caesar_cipher longest_substring 61.5 78.3
19 17 caesar_cipher rabin_karp 63.0 50.9
20 18 caesar_cipher railfence_cipher 59.1 88.3
21 19 caesar_cipher zellers_birthday 63.0 71.7
22 20 check_armstrong anagram_check 85.0 7.7
23 21 check_armstrong caesar_cipher 91.7 61.8
24 22 check_armstrong 92.3 93.5
25 23 check_armstrong common_divisor_count 91.7 61.7
26 24 check_armstrong exponentiation 85.7 68.6
27 25 check_armstrong gcd 87.5 47.8
28 26 check_armstrong longest_substring 92.9 69.6
29 27 check_armstrong rabin_karp 90.0 50.9
30 28 check_armstrong railfence_cipher 87.5 87.2
31 29 check_armstrong zellers_birthday 87.5 75.0
32 30 common_divisor_count anagram_check 65.6 7.7
33 31 common_divisor_count caesar_cipher 74.3 61.8
34 32 common_divisor_count check_armstrong 73.7 93.5
35 33 common_divisor_count 67.6 72.3
36 34 common_divisor_count exponentiation 77.1 68.6
37 35 common_divisor_count gcd 75.0 60.9
38 36 common_divisor_count longest_substring 76.5 82.6
39 37 common_divisor_count rabin_karp 72.2 50.9
40 38 common_divisor_count railfence_cipher 70.3 88.3
41 39 common_divisor_count zellers_birthday 70.3 73.3
42 40 exponentiation anagram_check 68.0 7.7
43 41 exponentiation caesar_cipher 68.8 61.8
44 42 exponentiation check_armstrong 70.0 93.5
45 43 exponentiation common_divisor_count 78.3 70.2
46 44 exponentiation 78.6 71.4
47 45 exponentiation gcd 65.4 47.8
48 46 exponentiation longest_substring 60.0 78.3
49 47 exponentiation rabin_karp 65.0 50.9
50 48 exponentiation railfence_cipher 69.2 87.2
51 49 exponentiation zellers_birthday 61.5 71.7
52 50 gcd anagram_check 47.4 7.7
53 51 gcd caesar_cipher 47.4 58.8
54 52 gcd check_armstrong 50.0 93.5
55 53 gcd common_divisor_count 43.8 76.6
56 54 gcd exponentiation 44.4 68.6
57 55 gcd 45.0 43.5
58 56 gcd longest_substring 43.8 69.6
59 57 gcd rabin_karp 36.8 50.9
60 58 gcd railfence_cipher 44.4 87.2
61 59 gcd zellers_birthday 43.8 70.8
62 60 longest_substring anagram_check 88.2 7.7
63 61 longest_substring caesar_cipher 77.8 58.8
64 62 longest_substring check_armstrong 93.8 93.5
65 63 longest_substring common_divisor_count 84.2 78.7
66 64 longest_substring exponentiation 87.5 68.6
67 65 longest_substring gcd 77.8 60.9
68 66 longest_substring 84.2 69.6
69 67 longest_substring rabin_karp 76.5 50.9
70 68 longest_substring railfence_cipher 81.2 88.3
71 69 longest_substring zellers_birthday 78.9 70.8
72 70 rabin_karp anagram_check 63.9 7.7
73 71 rabin_karp caesar_cipher 60.9 61.8
74 72 rabin_karp check_armstrong 65.0 93.5
75 73 rabin_karp common_divisor_count 68.9 78.7
76 74 rabin_karp exponentiation 64.4 71.4
77 75 rabin_karp gcd 66.7 60.9
78 76 rabin_karp longest_substring 63.0 73.9
79 77 rabin_karp 64.4 49.1
80 78 rabin_karp railfence_cipher 63.6 85.1
81 79 rabin_karp zellers_birthday 64.3 71.7
82 80 railfence_cipher anagram_check 90.0 7.7
83 81 railfence_cipher caesar_cipher 87.3 61.8
84 82 railfence_cipher check_armstrong 89.6 93.5
85 83 railfence_cipher common_divisor_count 90.0 78.7
86 84 railfence_cipher exponentiation 88.4 71.4
87 85 railfence_cipher gcd 86.5 60.9
88 86 railfence_cipher longest_substring 92.5 87.0
89 87 railfence_cipher rabin_karp 89.9 49.1
90 88 railfence_cipher 90.8 86.2
91 89 railfence_cipher zellers_birthday 91.2 70.8
92 90 zellers_birthday anagram_check 63.6 7.7
93 91 zellers_birthday caesar_cipher 69.1 61.8
94 92 zellers_birthday check_armstrong 68.6 93.5
95 93 zellers_birthday common_divisor_count 66.3 76.6
96 94 zellers_birthday exponentiation 71.4 40.0
97 95 zellers_birthday gcd 69.9 65.2
98 96 zellers_birthday longest_substring 67.4 82.6
99 97 zellers_birthday rabin_karp 68.4 26.3
100 98 zellers_birthday railfence_cipher 65.2 89.4
101 99 zellers_birthday 68.7 71.7

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View file

@ -1,11 +1,11 @@
file,fuzzer,genetic,cohen-d,interpretation,wilcoxon file,fuzzer,genetic,cohen-d,interpretation,wilcoxon
anagram_check,23.16,18.51,-0.569,Very small,0.0526 anagram_check,23.1,7.7,inf,Huge,0.002
caesar_cipher,60.18,62.39,0.4672,Medium,0.359 caesar_cipher,60.59,61.2,0.3549,Medium,0.2955
check_armstrong,89.54,89.18,-0.1427,Very small,0.625 check_armstrong,58.07,93.5,2.0757,Huge,0.002
common_divisor_count,71.21,72.26,0.2596,Medium,0.5566 common_divisor_count,76.17,72.76,-0.7471,Large,0.1258
exponentiation,68.99,68.48,-0.099,Very small,0.7695 exponentiation,69.44,67.14,-0.3342,Medium,0.7108
gcd,50.8,44.68,-1.0306,Very small,0.0665 gcd,59.15,55.66,-0.5016,Large,0.1627
longest_substring,83.96,83.01,-0.1547,Very small,0.8457 longest_substring,77.41,76.98,-0.0771,Small,0.7589
rabin_karp,66.15,64.51,-0.4597,Very small,0.3081 rabin_karp,27.9,47.55,2.3688,Huge,0.0078
railfence_cipher,90.28,89.62,-0.3514,Very small,0.375 railfence_cipher,88.41,87.44,-0.8844,Very large,0.1011
zellers_birthday,69.1,67.86,-0.5598,Very small,0.1851 zellers_birthday,68.09,71.75,1.4701,Huge,0.0039

1 file fuzzer genetic cohen-d interpretation wilcoxon
2 anagram_check 23.16 23.1 18.51 7.7 -0.569 inf Very small Huge 0.0526 0.002
3 caesar_cipher 60.18 60.59 62.39 61.2 0.4672 0.3549 Medium 0.359 0.2955
4 check_armstrong 89.54 58.07 89.18 93.5 -0.1427 2.0757 Very small Huge 0.625 0.002
5 common_divisor_count 71.21 76.17 72.26 72.76 0.2596 -0.7471 Medium Large 0.5566 0.1258
6 exponentiation 68.99 69.44 68.48 67.14 -0.099 -0.3342 Very small Medium 0.7695 0.7108
7 gcd 50.8 59.15 44.68 55.66 -1.0306 -0.5016 Very small Large 0.0665 0.1627
8 longest_substring 83.96 77.41 83.01 76.98 -0.1547 -0.0771 Very small Small 0.8457 0.7589
9 rabin_karp 66.15 27.9 64.51 47.55 -0.4597 2.3688 Very small Huge 0.3081 0.0078
10 railfence_cipher 90.28 88.41 89.62 87.44 -0.3514 -0.8844 Very small Very large 0.375 0.1011
11 zellers_birthday 69.1 68.09 67.86 71.75 -0.5598 1.4701 Very small Huge 0.1851 0.0039

BIN
report/main.pdf Normal file

Binary file not shown.

131
report/main.tex Normal file
View file

@ -0,0 +1,131 @@
%!TEX TS-program = pdflatexmk
\documentclass{scrartcl}
\usepackage{algorithm}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{rotating}
\usepackage{graphicx}
\usepackage{paralist}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{pbox}
\usepackage{enumitem}
\usepackage{colortbl}
\usepackage{pifont}
\usepackage{xspace}
\usepackage{url}
\usepackage{tikz}
\usepackage{fontawesome}
\usepackage{lscape}
\usepackage{listings}
\usepackage{color}
\usepackage{anyfontsize}
\usepackage{comment}
\usepackage{soul}
\usepackage{multibib}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[margin=2.5cm]{geometry}
\title{Knowledge Search \& Extraction \\ Project 02: Python Test Generator}
\author{Claudio Maggioni}
\date{}
\begin{document}
\maketitle
\subsection*{Section 1 - Instrumentation}
Report and comment the instrumentation of the code (e.g. number of files, number of functions, number of branches).
\begin{table} [H]
\centering
\begin{tabular}{lr}
\toprule
\textbf{Type} & \textbf{Number} \\
\midrule
Python Files & 10 \\
Function Nodes & 12 \\
Comparison Nodes & 44 \\
\bottomrule
\end{tabular}
\caption{Count of files and nodes found.}
\label{tab:count1}
\end{table}
\subsection*{Section 2: Fuzzer test generator}
Describe and comment the steps to generate test cases using Fuzzer (include any hyper parameter used during the process)
\subsection*{Section 3: Genetic Algorithm test generator}
Describe and comment the steps to generated test cases using Genetic Algorithm (include any hyper parameter used during the process)
\subsection*{Section 4: Statistical comparison of test generators}
Report and comment the results of the experimental procedure:
\paragraph{For each benchmark program P:}
\begin{itemize}
\item Repeat the following experiment N times (e.g., with N = 10):
\begin{itemize}
\item Generate random test cases for P using the GA generator
\item Measure the mutation score for P
\item Generate search based test cases for P using the Fuzzer
\item Measure the mutation score for P
\end{itemize}
\item Visualize the N mutations score values of Fuzzer and GA using boxplots
\item Report the average mutation score of Fuzzer and GA
\item Compute the effect size using the Cohens d effect size measure
\item Compare the N mutation score values of Fuzzer vs GA using the Wilcoxon statistical test
\end{itemize}
\begin{figure}[H]
\begin{center}
\includegraphics[width=\linewidth]{../out/mutation_scores}
\caption{Distributions of \textit{mut.py} mutation scores over the generated benchmark tests suites
using the fuzzer and the genetic algorithm.}\label{fig:mutation-scores}
\end{center}
\end{figure}
\begin{figure}[H]
\begin{center}
\includegraphics[width=\linewidth]{../out/mutation_scores_mean}
\caption{\textit{mut.py} Mutation score average over the generated benchmark tests suites
using the fuzzer and the genetic algorithm.}\label{fig:mutation-scores-mean}
\end{center}
\end{figure}
\begin{table}[H]
\centering
\begin{tabular}{lrrp{3.5cm}r}
\toprule
\textbf{File} & \textbf{$E(\text{Fuzzer})$} & \textbf{$E(\text{Genetic})$} & \hfill \textbf{Cohen's $d$} & \textbf{Wilcoxon $p$} \\ \midrule
anagram\_check & 23.16 & 18.51 & -0.5690 \hfill (Large) & 0.0526 \\
caesar\_cipher & 60.18 & 62.39 & 0.4672 \hfill (Medium) & 0.3590 \\
check\_armstrong & 89.54 & 89.18 & -0.1427 \hfill (Small) & 0.6250 \\
common\_divisor\_count & 71.21 & 72.26 & 0.2596 \hfill (Medium) & 0.5566 \\
exponentiation & 68.99 & 68.48 & -0.0990 \hfill (Small) & 0.7695 \\
gcd & 50.80 & 44.68 & -1.0306 \hfill (Very large) & 0.0665 \\
longest\_substring & 83.96 & 83.01 & -0.1547 \hfill (Small) & 0.8457 \\
rabin\_karp & 66.15 & 64.51 & -0.4597 \hfill (Medium) & 0.3081 \\
railfence\_cipher & 90.28 & 89.62 & -0.3514 \hfill (Medium) & 0.3750 \\
zellers\_birthday & 69.10 & 67.86 & -0.5598 \hfill (Large) & 0.1851 \\ \bottomrule
\end{tabular}
\caption{Statistical comparison between fuzzer and genetic algorithm test case generation in terms of mutation
score as reported by \textit{mut.py} over 10 runs. The table reports run means, the wilcoxon paired test p-value
and the Cohen's $d$ effect size for each file in the benchmark.}\label{tab:stats}
\end{table}
\end{document}

View file

@ -6,9 +6,9 @@ class Test_anagram_check(TestCase):
# distances_true = {1: [1], 3: [0]} # distances_true = {1: [1], 3: [0]}
# distances_false = {1: [0], 3: [1]} # distances_false = {1: [0], 3: [1]}
def test_anagram_check_1(self): def test_anagram_check_1(self):
assert anagram_check(s1='/O', s2='#') == False assert anagram_check(s1='Oi', s2='p') == False
# distances_true = {1: [0], 2: [0]} # distances_true = {1: [0], 2: [0]}
# distances_false = {1: [1], 2: [1]} # distances_false = {1: [1], 2: [1]}
def test_anagram_check_2(self): def test_anagram_check_2(self):
assert anagram_check(s1='G', s2='2') == False assert anagram_check(s1='_', s2='T') == False

View file

@ -4,14 +4,14 @@ from benchmark.caesar_cipher import decrypt
class Test_encrypt(TestCase): class Test_encrypt(TestCase):
# distances_true = {1: [0, 19, 0, 0, 0, 0]} # distances_true = {1: [3, 47, 0, 0, 46, 0, 22]}
# distances_false = {1: [66, 0, 3, 31, 33, 53]} # distances_false = {1: [0, 0, 31, 19, 0, 8, 0]}
def test_encrypt_1(self): def test_encrypt_1(self):
assert encrypt(strng='w#8TVj', key=73) == 'al">@T' assert encrypt(strng='V*wk+`C', key=38) == "|P>2Q'i"
class Test_decrypt(TestCase): class Test_decrypt(TestCase):
# distances_true = {2: [0, 0, 0, 223, 18, 37, 0, 29]} # distances_true = {2: [0, 215, 203, 206, 217, 13]}
# distances_false = {2: [18, 16, 11, 0, 0, 0, 14, 0]} # distances_false = {2: [21, 0, 0, 0, 0, 0]}
def test_decrypt_1(self): def test_decrypt_1(self):
assert decrypt(strng='027 Sf4^', key=34) == 'motþ1Dq<' assert decrypt(strng='C."%0d', key=56) == 'jöêíø,'

View file

@ -3,27 +3,27 @@ from benchmark.check_armstrong import check_armstrong
class Test_check_armstrong(TestCase): 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_2(self):
assert check_armstrong(n=2) == False
# distances_true = {1: [1], 2: [0]} # distances_true = {1: [1], 2: [0]}
# distances_false = {1: [0], 2: [1]} # distances_false = {1: [0], 2: [1]}
def test_check_armstrong_3(self): def test_check_armstrong_1(self):
assert check_armstrong(n=1) == True assert check_armstrong(n=1) == True
# distances_true = {1: [0]}
# distances_false = {1: [1]}
def test_check_armstrong_2(self):
assert check_armstrong(n=0) == True
# distances_true = {1: [161], 2: [160], 3: [11], 4: [0, 0, 0, 1], 5: [57]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [161, 16, 1, 0], 5: [0]}
def test_check_armstrong_3(self):
assert check_armstrong(n=161) == False
# distances_true = {1: [153], 2: [152], 3: [3], 4: [0, 0, 0, 1], 5: [0]} # 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]} # distances_false = {1: [0], 2: [0], 3: [0], 4: [153, 15, 1, 0], 5: [1]}
def test_check_armstrong_4(self): def test_check_armstrong_4(self):
assert check_armstrong(n=153) == True assert check_armstrong(n=153) == True
# distances_true = {1: [0]} # distances_true = {1: [3], 2: [2], 3: [0]}
# distances_false = {1: [1]} # distances_false = {1: [0], 2: [0], 3: [148]}
def test_check_armstrong_5(self): def test_check_armstrong_5(self):
assert check_armstrong(n=0) == True assert check_armstrong(n=3) == False

View file

@ -3,37 +3,32 @@ from benchmark.common_divisor_count import cd_count
class Test_cd_count(TestCase): class Test_cd_count(TestCase):
# distances_true = {1: [5], 2: [621], 3: [0], 4: [622], 5: [0, 0, 1], 6: [0], 7: [0]}
# distances_false = {1: [0], 2: [0], 3: [5], 4: [0], 5: [5, 1, 0], 6: [1], 7: [1]}
def test_cd_count_1(self):
assert cd_count(a=-5, b=621) == 1
# distances_true = {1: [0]} # distances_true = {1: [0]}
# distances_false = {1: [1]} # distances_false = {1: [1]}
def test_cd_count_1(self):
assert cd_count(a=0, b=15) == 2
# distances_true = {1: [393], 2: [0]}
# distances_false = {1: [0], 2: [1]}
def test_cd_count_2(self): def test_cd_count_2(self):
assert cd_count(a=393, b=0) == 2 assert cd_count(a=0, b=621) == 2
# distances_true = {1: [10], 2: [25], 3: [0], 4: [0], 5: [0, 0, 1], 6: [0, 1], 7: [4]} # distances_true = {1: [2], 2: [616], 3: [3], 4: [617], 5: [0, 1], 6: [0], 7: [1]}
# distances_false = {1: [0], 2: [0], 3: [10], 4: [25], 5: [10, 5, 0], 6: [1, 0], 7: [0]} # distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [2, 0], 6: [1], 7: [0]}
def test_cd_count_3(self): def test_cd_count_3(self):
assert cd_count(a=-10, b=-25) == 2 assert cd_count(a=2, b=616) == 2
# distances_true = {1: [402], 2: [6], 3: [403], 4: [0], 5: [0, 0, 1], 6: [0, 0], 7: [5, 1]} # distances_true = {1: [7], 2: [630], 3: [0], 4: [631], 5: [0, 1], 6: [0, 1], 7: [6]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [6], 5: [402, 6, 0], 6: [1, 1], 7: [0, 0]} # distances_false = {1: [0], 2: [0], 3: [7], 4: [0], 5: [7, 0], 6: [1, 0], 7: [0]}
def test_cd_count_4(self): def test_cd_count_4(self):
assert cd_count(a=402, b=-6) == 4 assert cd_count(a=-7, b=630) == 2
# distances_true = {1: [392], 2: [7], 3: [393], 4: [8], 5: [0, 0, 1], 6: [0, 1], 7: [6]} # distances_true = {1: [624], 2: [0]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [392, 7, 0], 6: [1, 0], 7: [0]} # distances_false = {1: [0], 2: [1]}
def test_cd_count_5(self): def test_cd_count_5(self):
assert cd_count(a=392, b=7) == 2 assert cd_count(a=-624, b=0) == 2
# distances_true = {1: [394], 2: [8], 3: [395], 4: [9], 5: [0, 0, 0, 1], 6: [0], 7: [1]} # distances_true = {1: [637], 2: [6], 3: [0], 4: [0], 5: [0, 0, 0, 1], 6: [0], 7: [0]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [394, 8, 2, 0], 6: [1], 7: [0]} # distances_false = {1: [0], 2: [0], 3: [637], 4: [6], 5: [637, 6, 1, 0], 6: [1], 7: [1]}
def test_cd_count_6(self): def test_cd_count_6(self):
assert cd_count(a=394, b=8) == 2 assert cd_count(a=-637, b=-6) == 1
# 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

View file

@ -3,7 +3,7 @@ from benchmark.exponentiation import exponentiation
class Test_exponentiation(TestCase): class Test_exponentiation(TestCase):
# 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_true = {1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 3: [0], 2: [0, 1, 1, 1, 1, 1, 0, 0, 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]} # distances_false = {1: [773, 386, 192, 95, 47, 23, 11, 5, 2, 0], 3: [1], 2: [1, 0, 0, 0, 0, 0, 1, 1, 0]}
def test_exponentiation_1(self): def test_exponentiation_1(self):
assert exponentiation(baseNumber=273, power=680) == 3895829911570928427062789161404619914280587771868641368230047219958283345300450942897840323420791983227798964155996689168523437566770315575583013976403957872742182353547463597025702302902832229086505206794667167898163934216590804080800733688120376430395338105859000612063507722208813216463729860745825987959359261789071423513895716311721748115129973945455387902352811050072692137174188206432034223389947642057171762532443123845107375361110833977798080587890468684612289410208695964211522638003354245409255507983104542683355382317518977114366295148467288902108644080093389079060315506570882647437359202448921746467958494827152271151409822952703502092414977688648082960249156331982392167922155653098989699335892059699361415118388425849978057627932625853662432314879750773240572688797268782645610220407914772433232815718897161329409011757811650965412399303355317182165903778708510492810189246784961371248406019716330925132073748574311471381406856686563502008322111913444321152997673213749133497305507944474723081065221727352562980326137327122607087182234700957778053610249838737764681707961211892627389095734978445860126630875401467771828849380219936663564390488252632365445815860667399405147173712004117843019973408114982416950170127509936321352740444103690166146920102943006785619658810173984204313195394806290104680248135955773591764204824995379131427455872719071405823820721924895558772558138790298999583595141680838833952767448791324515927781329111543905447682668609169946357479866063142378522581199077752915958479926692022074057503083311484355723701186263368366885202884101517116580212732955571601354373596263954677080515220048136220941141669130397916801 assert exponentiation(baseNumber=-1, power=774) == 1

View file

@ -3,27 +3,27 @@ from benchmark.gcd import gcd
class Test_gcd(TestCase): class Test_gcd(TestCase):
# distances_true = {1: [6], 2: [3], 3: [3], 4: [4], 5: [0, 0, 0, 1]} # distances_true = {1: [97], 2: [0]}
# 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]} # distances_false = {1: [0], 2: [1]}
def test_gcd_3(self): def test_gcd_1(self):
assert gcd(a=2, b=1) == 1 assert gcd(a=98, b=1) == 1
# distances_true = {1: [6], 2: [6], 3: [0]} # distances_true = {1: [97], 2: [1], 3: [96], 4: [97], 5: [0, 1]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [0], 5: [2, 0]}
def test_gcd_2(self):
assert gcd(a=98, b=2) == 2
# distances_true = {1: [9], 2: [9], 3: [0]}
# distances_false = {1: [0], 2: [0], 3: [1]} # distances_false = {1: [0], 2: [0], 3: [1]}
def test_gcd_3(self):
assert gcd(a=10, b=10) == 10
# distances_true = {1: [7], 2: [943], 3: [936], 4: [0], 5: [0, 1]}
# distances_false = {1: [0], 2: [0], 3: [0], 4: [936], 5: [8, 0]}
def test_gcd_4(self): def test_gcd_4(self):
assert gcd(a=7, b=7) == 7 assert gcd(a=8, b=944) == 8
# distances_true = {1: [0]} # distances_true = {1: [0]}
# distances_false = {1: [1]} # distances_false = {1: [1]}
def test_gcd_5(self): def test_gcd_5(self):
assert gcd(a=1, b=2) == 1 assert gcd(a=1, b=933) == 1

View file

@ -3,7 +3,7 @@ from benchmark.longest_substring import longest_sorted_substr
class Test_longest_sorted_substr(TestCase): class Test_longest_sorted_substr(TestCase):
# distances_true = {1: [38, 0, 29, 15, 0, 30, 0], 2: [0, 1, 1]} # distances_true = {1: [0, 8, 0, 27, 53, 0, 11], 2: [0, 1, 1]}
# distances_false = {1: [0, 21, 0, 0, 35, 0, 61], 2: [1, 0, 0]} # distances_false = {1: [11, 0, 82, 0, 0, 71, 0], 2: [1, 0, 0]}
def test_longest_sorted_substr_1(self): def test_longest_sorted_substr_1(self):
assert longest_sorted_substr(s='nH\\?0R4p') == 'H\\' assert longest_sorted_substr(s="$.&w\\'mb") == '$.'

View file

@ -3,12 +3,17 @@ from benchmark.rabin_karp import rabin_karp_search
class Test_rabin_karp_search(TestCase): class Test_rabin_karp_search(TestCase):
# distances_true = {1: [0], 2: [1], 3: [0], 4: [1]} # distances_true = {1: [0], 2: [1, 0], 3: [1], 4: [1]}
# distances_false = {1: [1], 2: [0], 3: [1], 4: [0]} # distances_false = {1: [1], 2: [0, 4], 3: [0], 4: [0]}
def test_rabin_karp_search_1(self): def test_rabin_karp_search_1(self):
assert rabin_karp_search(pat='k', txt='k') == [0] assert rabin_karp_search(pat='A@@', txt='A<g') == []
# distances_true = {1: [6], 4: [1]} # distances_true = {1: [28], 4: [1]}
# distances_false = {1: [0], 4: [0]} # distances_false = {1: [0], 4: [0]}
def test_rabin_karp_search_2(self): def test_rabin_karp_search_2(self):
assert rabin_karp_search(pat='V', txt='\\') == [] assert rabin_karp_search(pat='RC)', txt='][`') == []
# distances_true = {1: [0], 2: [0], 3: [2], 4: [1]}
# distances_false = {1: [1], 2: [25], 3: [0], 4: [0]}
def test_rabin_karp_search_3(self):
assert rabin_karp_search(pat='*3~', txt='C9`') == []

View file

@ -5,13 +5,13 @@ from benchmark.railfence_cipher import raildecrypt
class Test_railencrypt(TestCase): class Test_railencrypt(TestCase):
# 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_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]} # distances_false = {1: [1, 1, 1, 0, 0, 1, 1, 0], 2: [0, 0, 1, 0, 1], 3: [0, 1, 0], 4: [126, 0, 0, 0, 110, 0, 0, 0, 0, 117, 0, 52, 0, 50, 0, 67, 0, 0, 32, 0, 0, 0, 104, 0]}
def test_railencrypt_1(self): def test_railencrypt_1(self):
assert railencrypt(st='VwIOq}wa', k=3) == 'VqwO}aIw' assert railencrypt(st='~u 4n2hC', k=3) == '~nu42C h'
class Test_raildecrypt(TestCase): class Test_raildecrypt(TestCase):
# 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_true = {5: [0, 0, 0, 1, 1, 0, 0, 1], 6: [2, 1, 0, 1, 0], 7: [1, 0, 1], 8: [0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1], 9: [0, 0, 0, 0, 0, 0, 0, 0], 10: [8, 0, 0, 1, 1, 0, 0, 1], 12: [0, 1, 0, 1], 11: [1, 0, 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]} # distances_false = {5: [1, 1, 1, 0, 0, 1, 1, 0], 6: [0, 0, 1, 0, 1], 7: [0, 1, 0], 8: [1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0], 9: [58, 96, 58, 124, 48, 73, 82, 79], 10: [0, 1, 1, 0, 0, 1, 1, 0], 12: [1, 0, 1, 0], 11: [0, 1, 0, 1]}
def test_raildecrypt_1(self): def test_raildecrypt_1(self):
assert raildecrypt(st=' R"/W$|aA', k=5) == ' "W|Aa$/R' assert raildecrypt(st=':0`|IO:R', k=3) == ':`:|0IRO'

View file

@ -3,27 +3,22 @@ from benchmark.zellers_birthday import zeller
class Test_zeller(TestCase): class Test_zeller(TestCase):
# distances_true = {1: [13], 2: [0], 3: [0], 4: [4], 5: [0], 6: [0], 7: [0], 8: [2, 1, 0]} # distances_true = {1: [1], 2: [6], 3: [0], 4: [0], 5: [1923], 7: [5], 8: [0]}
# distances_false = {1: [0], 2: [408], 3: [74], 4: [0], 5: [74], 6: [4], 7: [2], 8: [0, 0, 1]} # distances_false = {1: [0], 2: [0], 3: [78], 4: [1], 5: [0], 7: [0], 8: [1]}
def test_zeller_1(self): def test_zeller_1(self):
assert zeller(d=19, m=420, y=-26) == 'Tuesday' assert zeller(d=-31, m=-7, y=-22) == 'Sunday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [9], 5: [0], 6: [0], 7: [0], 8: [3, 2, 1, 0]} # distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [0], 8: [6, 5, 4, 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]} # distances_false = {1: [4], 2: [1], 3: [78], 4: [1], 5: [0], 7: [1], 8: [0, 0, 0, 0, 0, 0, 1]}
def test_zeller_2(self): def test_zeller_2(self):
assert zeller(d=-575, m=-409, y=31) == 'Wednesday' assert zeller(d=-35, m=-13, y=-22) == 'Saturday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [8], 8: [5, 4, 3, 2, 1, 0]} # distances_true = {1: [1], 2: [0], 3: [0], 4: [7], 5: [0], 6: [0], 7: [0], 8: [0]}
# distances_false = {1: [547], 2: [393], 3: [78], 4: [1], 5: [0], 7: [0], 8: [0, 0, 0, 0, 0, 1]} # distances_false = {1: [0], 2: [1], 3: [71], 4: [0], 5: [71], 6: [7], 7: [1], 8: [1]}
def test_zeller_3(self): def test_zeller_3(self):
assert zeller(d=-578, m=-405, y=22) == 'Friday' assert zeller(d=-31, m=-13, y=-29) == 'Sunday'
# distances_true = {1: [0], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [0], 8: [1, 0]} # distances_true = {1: [1], 2: [0], 3: [0], 4: [0], 5: [1923], 7: [1], 8: [4, 3, 2, 1, 0]}
# distances_false = {1: [547], 2: [397], 3: [78], 4: [1], 5: [0], 7: [1], 8: [0, 1]} # distances_false = {1: [0], 2: [2], 3: [78], 4: [1], 5: [0], 7: [0], 8: [0, 0, 0, 0, 1]}
def test_zeller_4(self): def test_zeller_4(self):
assert zeller(d=-578, m=-409, y=22) == 'Monday' assert zeller(d=-31, m=-14, y=-22) == 'Thursday'
# 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'