Skip to content

Commit df687db

Browse files
Merge pull request #77 from LaPlei96/master
Grammar usage and import
2 parents 1c20f34 + 32d2c77 commit df687db

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

docs/code/Alhazen.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def task_sqrt(x):
191191
from math import cos as rcos
192192
from math import sin as rsin
193193

194+
from numpy import nanmax, isnan
195+
194196
if __name__ == '__main__':
195197
"""
196198
This file contains the code under test for the example bug.
@@ -1645,11 +1647,11 @@ def get_all_input_specifications(dec_tree,
16451647
import random
16461648
from itertools import chain
16471649

1648-
def best_trees(forest, spec):
1650+
def best_trees(forest, spec, grammar):
16491651
samples = [tree_to_string(tree) for tree in forest]
16501652
fulfilled_fractions= []
16511653
for sample in samples:
1652-
gen_features = collect_features([sample], CALC_GRAMMAR)
1654+
gen_features = collect_features([sample], grammar)
16531655

16541656
# calculate percentage of fulfilled requirements (used to rank the sample)
16551657
fulfilled_count = 0
@@ -1716,7 +1718,7 @@ def generate_samples_advanced(grammar: Grammar,
17161718
done = False
17171719
starttime = time.time()
17181720
best_chosen = [fuzzer.fuzz_tree() for _ in range(100)]
1719-
done, best_chosen = best_trees(best_chosen, spec)
1721+
done, best_chosen = best_trees(best_chosen, spec, grammar)
17201722
if done:
17211723
final_samples.append(tree_to_string(best_chosen))
17221724

@@ -1756,7 +1758,7 @@ def generate_samples_advanced(grammar: Grammar,
17561758
curr = s[0]
17571759
except SyntaxError:
17581760
pass
1759-
done, best_chosen = best_trees(best_chosen, spec)
1761+
done, best_chosen = best_trees(best_chosen, spec, grammar)
17601762
if done:
17611763
final_samples.append(tree_to_string(best_chosen))
17621764
if not done:
@@ -1773,6 +1775,8 @@ def generate_samples_random(grammar, new_input_specifications, num):
17731775

17741776
return data
17751777

1778+
generate_samples = generate_samples_advanced
1779+
17761780
if __name__ == '__main__':
17771781
generate_samples = generate_samples_advanced
17781782

notebooks/Alhazen.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,11 +2745,11 @@
27452745
"metadata": {},
27462746
"outputs": [],
27472747
"source": [
2748-
"def best_trees(forest, spec):\n",
2748+
"def best_trees(forest, spec, grammar):\n",
27492749
" samples = [tree_to_string(tree) for tree in forest]\n",
27502750
" fulfilled_fractions= []\n",
27512751
" for sample in samples:\n",
2752-
" gen_features = collect_features([sample], CALC_GRAMMAR)\n",
2752+
" gen_features = collect_features([sample], grammar)\n",
27532753
"\n",
27542754
" # calculate percentage of fulfilled requirements (used to rank the sample)\n",
27552755
" fulfilled_count = 0\n",
@@ -2823,7 +2823,7 @@
28232823
" done = False\n",
28242824
" starttime = time.time()\n",
28252825
" best_chosen = [fuzzer.fuzz_tree() for _ in range(100)]\n",
2826-
" done, best_chosen = best_trees(best_chosen, spec)\n",
2826+
" done, best_chosen = best_trees(best_chosen, spec, grammar)\n",
28272827
" if done:\n",
28282828
" final_samples.append(tree_to_string(best_chosen))\n",
28292829
"\n",
@@ -2863,7 +2863,7 @@
28632863
" curr = s[0]\n",
28642864
" except SyntaxError:\n",
28652865
" pass\n",
2866-
" done, best_chosen = best_trees(best_chosen, spec)\n",
2866+
" done, best_chosen = best_trees(best_chosen, spec, grammar)\n",
28672867
" if done:\n",
28682868
" final_samples.append(tree_to_string(best_chosen))\n",
28692869
" if not done:\n",

0 commit comments

Comments
 (0)