MCPcopy Index your code
hub / github.com/evalplus/evalplus / TypedMutGen

Class TypedMutGen

evalplus/gen/type_mut.py:34–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33
34class TypedMutGen(MutateGen):
35 def __init__(self, inputs: List, signature: str, contract_code: str):
36 super().__init__(inputs, signature, contract_code)
37 self.timeout = 60 * 60 # 1 hour
38 self.ingredients = {
39 int: set(),
40 float: set(),
41 str: set(),
42 complex: set(),
43 }
44 for x in inputs:
45 self.fetch_ingredient(x)
46
47 def seed_selection(self):
48 # random for now.
49 return random.choice(self.seed_pool)
50
51 def mutate(self, seed_input: Any) -> List:
52 new_input = copy.deepcopy(seed_input)
53
54 patience = MUTATE_BOUND_SIZE
55 while new_input == seed_input or patience == 0:
56 new_input = self.typed_mutate(new_input)
57 patience -= 1
58
59 return new_input
60
61 #########################
62 # Type-aware generation #
63 #########################
64 @dispatch(NoneType)
65 def typed_gen(self, _):
66 return None
67
68 @dispatch(int)
69 def typed_gen(self, _):
70 @use_ingredient(0.5)
71 def _impl(*_):
72 return random.randint(-100, 100)
73
74 return _impl(self, _)
75
76 @dispatch(float)
77 def typed_gen(self, _):
78 @use_ingredient(0.5)
79 def _impl(*_):
80 return random.uniform(-100, 100)
81
82 return _impl(self, _)
83
84 @dispatch(bool)
85 def typed_gen(self, _):
86 return random.choice([True, False])
87
88 @dispatch(str)
89 def typed_gen(self, _):
90 @use_ingredient(0.5)
91 def _impl(*_):

Callers 1

input_generationFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected