Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some code #44

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Simplify some code

  • Loading branch information
jvoisin committed May 20, 2020
commit 4f2cf7cb2af85c43ebbdf35cc9e5f79473420633
@@ -289,7 +289,7 @@ def mutate(self, res):
if len(res) == 0:
return None
pos = self._rand(len(res))
res[pos] = numpy.uint8(INTERESTING8[self._rand(len(INTERESTING8))])
res[pos] = numpy.uint8(random.choice(INTERESTING8))
return res


@@ -302,7 +302,7 @@ def mutate(self, res):
if len(res) < 2:
return None
pos = self._rand(len(res) - 1)
v = numpy.uint16(INTERESTING16[self._rand(len(INTERESTING16))])
v = numpy.uint16(random.choice(INTERESTING16))
if bool(random.getrandbits(1)):
v = struct.pack('>H', v)
else:
@@ -322,7 +322,7 @@ def mutate(self, res):
if len(res) < 4:
return None
pos = self._rand(len(res) - 3)
v = numpy.uint32(INTERESTING32[self._rand(len(INTERESTING32))])
v = numpy.uint32(random.choice(INTERESTING32))
if bool(random.getrandbits(1)):
v = struct.pack('>I', v)
else:
@@ -345,12 +345,12 @@ def mutate(self, res):
digits.append(k)
if len(digits) == 0:
return None
pos = self._rand(len(digits))
was = res[digits[pos]]
pos = random.choice(digits)
was = res[pos]
now = was
while was == now:
now = self._rand(10) + ord('0')
res[digits[pos]] = now
res[pos] = now
return res


@@ -452,12 +452,6 @@ def _add_file(self, path):
def length(self):
return len(self._inputs)

@staticmethod
def _rand(n):
if n == 1 or n == 0:
return 0
return random.randint(0, n-1)

# Exp2 generates n with probability 1/2^(n+1).
@staticmethod
def _rand_exp():
@@ -493,7 +487,7 @@ def generate_input(self):
self.put(zero_test_case)
return zero_test_case
else:
buf = self._inputs[self._rand(len(self._inputs))]
buf = random.choice(self._inputs)
return self.mutate(buf)

def mutate(self, buf):
@@ -506,8 +500,7 @@ def mutate(self, buf):
# We'll try up to 20 times, but if we don't find a
# suitable mutator after that, we'll just give up.
for n in range(20):
x = self._rand(len(self.mutators))
mutator = self.mutators[x]
mutator = random.choice(self.mutators)

#print("Mutate with {}".format(mutator.__class__.__name__))
newres = mutator.mutate(res)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.