Upload test_case_gen.py with huggingface_hub
Browse files- test_case_gen.py +105 -0
test_case_gen.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from hypothesis import given
|
| 2 |
+
# from hypothesis.strategies import text
|
| 3 |
+
|
| 4 |
+
# @given(text())
|
| 5 |
+
# def test_uppercase_conversion(s):
|
| 6 |
+
# assert not (s is None)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# import ast
|
| 10 |
+
|
| 11 |
+
# def extract_input_types(code_str):
|
| 12 |
+
# tree = ast.parse(code_str)
|
| 13 |
+
# input_types = []
|
| 14 |
+
|
| 15 |
+
# class InputVisitor(ast.NodeVisitor):
|
| 16 |
+
# def visit_Call(self, node):
|
| 17 |
+
# if isinstance(node.func, ast.Name) and node.func.id == 'input':
|
| 18 |
+
# # Assumes single input call, no argument parsing
|
| 19 |
+
# input_types.append('string')
|
| 20 |
+
# self.generic_visit(node)
|
| 21 |
+
|
| 22 |
+
# visitor = InputVisitor()
|
| 23 |
+
# visitor.visit(tree)
|
| 24 |
+
|
| 25 |
+
# return input_types
|
| 26 |
+
|
| 27 |
+
# # Example usage
|
| 28 |
+
# code_str = """
|
| 29 |
+
# t = int(input())
|
| 30 |
+
# for i in range(t):
|
| 31 |
+
# n = int(input())
|
| 32 |
+
# j = 9
|
| 33 |
+
# firstdecrease = False
|
| 34 |
+
# for i in range(n):
|
| 35 |
+
# print(j, end='')
|
| 36 |
+
# if not firstdecrease:
|
| 37 |
+
# j = (j - 1) % 10
|
| 38 |
+
# else:
|
| 39 |
+
# j = (j + 1) % 10
|
| 40 |
+
# if not firstdecrease and j == 8:
|
| 41 |
+
# firstdecrease = True
|
| 42 |
+
# print()
|
| 43 |
+
# """
|
| 44 |
+
|
| 45 |
+
# input_types = extract_input_types(code_str)
|
| 46 |
+
# print(input_types) # ['string', 'string']
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# fuzz.py
|
| 51 |
+
import afl
|
| 52 |
+
import sys
|
| 53 |
+
import io
|
| 54 |
+
|
| 55 |
+
def run_code_with_input(code_str, inputs):
|
| 56 |
+
# Redirect stdout to capture print statements
|
| 57 |
+
old_stdout = sys.stdout
|
| 58 |
+
sys.stdout = io.StringIO()
|
| 59 |
+
|
| 60 |
+
# Prepare the input
|
| 61 |
+
input_str = '\n'.join(map(str, inputs)) + '\n'
|
| 62 |
+
old_stdin = sys.stdin
|
| 63 |
+
sys.stdin = io.StringIO(input_str)
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
# Execute the code
|
| 67 |
+
exec(code_str)
|
| 68 |
+
# Get the output
|
| 69 |
+
output = sys.stdout.getvalue().strip()
|
| 70 |
+
finally:
|
| 71 |
+
# Reset stdout and stdin
|
| 72 |
+
sys.stdout = old_stdout
|
| 73 |
+
sys.stdin = old_stdin
|
| 74 |
+
|
| 75 |
+
return output
|
| 76 |
+
|
| 77 |
+
def fuzz():
|
| 78 |
+
afl.init()
|
| 79 |
+
code_str = """
|
| 80 |
+
import sys
|
| 81 |
+
t = int(input())
|
| 82 |
+
for _ in range(t):
|
| 83 |
+
n = int(input())
|
| 84 |
+
j = 9
|
| 85 |
+
firstdecrease = False
|
| 86 |
+
for _ in range(n):
|
| 87 |
+
print(j, end='')
|
| 88 |
+
if not firstdecrease:
|
| 89 |
+
j = (j - 1) % 10
|
| 90 |
+
else:
|
| 91 |
+
j = (j + 1) % 10
|
| 92 |
+
if not firstdecrease and j == 8:
|
| 93 |
+
firstdecrease = True
|
| 94 |
+
print()
|
| 95 |
+
"""
|
| 96 |
+
|
| 97 |
+
# Fuzz the code
|
| 98 |
+
while True:
|
| 99 |
+
input_data = afl.raw_input()
|
| 100 |
+
inputs = input_data.decode().strip().split('\n')
|
| 101 |
+
inputs = list(map(int, inputs)) # Convert to integers if necessary
|
| 102 |
+
run_code_with_input(code_str, inputs)
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
fuzz()
|