-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputs.py
82 lines (70 loc) · 1.84 KB
/
inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import random
import string
def random_string(length):
letters = string.ascii_letters + string.digits
return ''.join(random.choice(letters) for i in range(length))
def input_string():
choice = random.choice([0, 1, 2])
if (choice == 0):
return '"{}"'.format(random_string(random.randint(1, 100)))
if (choice == 1):
return "NULL"
if (choice == 2):
return '""'
def input_uint():
return str(random.randint(0, 2147483647))
def input_short_uint():
return str(random.randint(0, 100))
def input_int():
choice = random.choice([0, 1, 2, 3])
if (choice == 0):
return str(random.randint(-2147483648, 2147483647))
if (choice == 1):
return str(2147483647)
if (choice == 2):
return str(-2147483648)
if (choice == 3):
return str(0)
def input_char():
choice = random.choice([0, 1])
if (choice == 0):
return "'" + random.choice(string.ascii_letters + string.digits) + "'"
if (choice == 1):
return "'\\0'"
def input_map_func():
choice = random.choice([0, 1])
if (choice == 0):
return "&map"
if (choice == 1):
return "NULL"
def input_del_func():
choice = random.choice([0, 1])
if (choice == 0):
return "&del"
if (choice == 1):
return "NULL"
def input_lstmap_func():
choice = random.choice([0, 1])
if (choice == 0):
return "&lstmap"
if (choice == 1):
return "NULL"
def input_elem():
choice = random.choice([0, 1])
if (choice == 0):
return "ft_lstnew({})".format(input_string())
if (choice == 1):
return "NULL"
def create_pointer(n, size):
choice = random.choice([0, 1])
s = ""
s += "\tvoid *ptr{} = NULL;\n".format(str(n))
if (choice):
s += "\tptr{} = malloc(sizeof(char) * {});\n".format(n, str(size))
return s
def create_list(n):
res = ""
res += "\tt_list *list{} = {};\n".format(n, input_elem())
for i in range(random.randint(0, 3)):
res += "\tft_lstadd_back(&list{}, {});\n".format(n, input_elem())
return res