Skip to content

Commit

Permalink
add fuzz test cases, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Aug 16, 2024
1 parent 09e07a9 commit 30cf488
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from nltk.corpus import stopwords
from nltk import download as nltk_download
import emoji
import string

print("Downloading stopwords...")
nltk_download("stopwords")
Expand Down Expand Up @@ -39,6 +40,8 @@
character_ranges = {
file_id: list(stopwords.words(file_id)) for file_id in supported_languages
}

character_ranges["alphanumeric"] = string.ascii_letters + string.digits
character_ranges["unicode"] = [chr(i) for i in range(0x0000, 0x10FFFF)]
character_ranges["numbers"] = [str(random.randint(1, 10_000_000)) for _ in range(1000)]
character_ranges["long_numbers"] = [
Expand Down Expand Up @@ -69,7 +72,7 @@ def mutate(
seed = list(seed)

for i in range(len(seed)):
if change() and i not in characters_to_skip:
if change() and seed[i] not in characters_to_skip:
seed[i] = random.choice(character_ranges[character_range])

return "".join(seed)
Expand Down Expand Up @@ -102,6 +105,7 @@ def test_fuzzer():
tests = []

tests.extend([mutate(seed) for seed in seeds for _ in range(ITERATIONS_PER_SEED)])

tests.extend(
[mutate(seed, []) for seed in seeds for _ in range(ITERATIONS_PER_SEED)]
)
Expand Down

0 comments on commit 30cf488

Please sign in to comment.