-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomize.py
74 lines (64 loc) · 2.69 KB
/
randomize.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
import random
# Original code snippet
original_snippet_concatenation = '("....." + a * b + ".....")'
original_snippet_interpolation = '(".....%d.....%d...", a * b, c)' # c-style
original_snippet_others = '(".....{a * b}.....{c}...")' # others
# Error types
error_types_concatenation = [
lambda s: s.replace('*', '/'),
lambda s: s.replace('+', '-'), # modify this
lambda s: s.replace('+ "', ''),
lambda s: s.replace('" +', ''),
lambda s: s.replace('+ "....."', '"'),
lambda s: s.replace('....."', '"'),
lambda s: s.replace('a * b', 'a * '),
lambda s: s.replace('a * b', '* b'),
lambda s: s.replace('a * b', 'a + '),
lambda s: s.replace('a * b', '+ b'),
lambda s: s + ' + c',
lambda s: 'c + ' + s,
lambda s: s.replace('a * b', 'a * b + c'),
lambda s: s.replace('a * b', 'a + b + c'),
lambda s: s.replace('a * b', 'a b + c'),
lambda s: s.replace('a * b', '-a * b c'),
]
# Error types
error_types_interpolation = [
lambda s: s.replace('%d..."', '"'),
lambda s: s.replace('a * b', 'a, b'),
lambda s: s.replace('a * b,', ''),
lambda s: s.replace('" +', ''),
lambda s: s.replace('+ "....."', '"'),
lambda s: s.replace('....."', '"'),
lambda s: s.replace('a * b', 'a * '),
lambda s: s.replace('a * b', '* b'),
lambda s: s.replace('a * b', 'a + '),
lambda s: s.replace('a * b', '+ b'),
lambda s: s + ' + c',
lambda s: 'c + ' + s,
lambda s: s.replace('a * b', 'a * b + c'),
lambda s: s.replace('a * b', 'a + b + c'),
lambda s: s.replace('a * b', 'a b + c'),
lambda s: s.replace('a * b', '-a * b c'),
]
# List to hold permutations
permutations_concatenation = []
permutations_interpolation = []
# Function to introduce an error into a code snippet
def introduce_error(snippet, error_types):
# Select a random error to introduce
error_func = random.choice(error_types)
return error_func(snippet)
def error_concatenation():
for _ in range(14):
erroneous_snippet = introduce_error(original_snippet_concatenation, error_types_concatenation)
permutations_concatenation.append(erroneous_snippet)
return permutations_concatenation
def error_interpolation():
for _ in range(14):
erroneous_snippet = introduce_error(original_snippet_concatenation, error_types_concatenation)
permutations_interpolation.append(erroneous_snippet)
return permutations_interpolation
# # Display the generated permutations
# for i, permutation in enumerate(permutations, start=1):
# print(f"Permutation {i}: {permutation}")