示例#1
0
 def test_generate_statements(self):
     config = arithmetic_repeats_config.ArithmeticRepeatsConfig(
         base=10,
         length=10,
         max_repeat_statements=5,
         max_repetitions=2,
     )
     statements, unused_hole_statement_index = (
         arithmetic_repeats._generate_statements(config.length, config))
     self.assertLen(statements, 10)
示例#2
0
def main(argv):
    del argv  # Unused.

    config = arithmetic_repeats_config.ArithmeticRepeatsConfig(
        base=10,
        length=30,
        max_repeat_statements=10,
        max_repetitions=9,
        max_repeat_block_size=20,
        repeat_probability=0.2,
        permit_nested_repeats=True,
    )
    python_source = program_generators.generate_python_source(
        config.length, config)
    cfg = python_programs.to_cfg(python_source)
    num_graphs = len(os.listdir('/tmp/control_flow_graphs/'))
    path = '/tmp/control_flow_graphs/cfg{:03d}.png'.format(num_graphs)
    control_flow_graphviz.render(cfg, include_src=python_source, path=path)
示例#3
0
 def test_evaluate_cfg_on_random_program(self):
     initial_value = 1  # v0 = 1
     initial_values = {'v0': initial_value}
     config = arithmetic_repeats_config.ArithmeticRepeatsConfig(
         base=10,
         length=10,
         max_repeat_statements=10,
         max_repetitions=9,
         max_repeat_block_size=5,
         repeat_probability=0.2,
         permit_nested_repeats=True,
     )
     python_source = program_generators.generate_python_source(
         config.length, config)
     cfg = python_programs.to_cfg(python_source)
     values = python_interpreter.evaluate_cfg(self.executor,
                                              cfg,
                                              initial_values=initial_values)
     self.assertIn('v0', values)