Пример #1
0
def test_CreateRandomGraphTuple(
  node_x_dimensionality: int,
  node_y_dimensionality: int,
  graph_x_dimensionality: int,
  graph_y_dimensionality: int,
  with_data_flow: bool,
):
  """Black-box test of generator properties."""
  graph_tuple = random_graph_tuple_database_generator.CreateRandomGraphTuple(
    node_x_dimensionality=node_x_dimensionality,
    node_y_dimensionality=node_y_dimensionality,
    graph_x_dimensionality=graph_x_dimensionality,
    graph_y_dimensionality=graph_y_dimensionality,
    with_data_flow=with_data_flow,
  )
  assert graph_tuple.node_x_dimensionality == node_x_dimensionality
  assert graph_tuple.node_y_dimensionality == node_y_dimensionality
  assert graph_tuple.graph_x_dimensionality == graph_x_dimensionality
  assert graph_tuple.graph_y_dimensionality == graph_y_dimensionality
  if with_data_flow:
    assert graph_tuple.data_flow_steps >= 1
    assert graph_tuple.data_flow_root_node >= 0
    assert graph_tuple.data_flow_positive_node_count >= 1
  else:
    assert graph_tuple.data_flow_steps is None
    assert graph_tuple.data_flow_root_node is None
    assert graph_tuple.data_flow_positive_node_count is None
def db_10000(
    empty_graph_db: graph_tuple_database.Database,
) -> graph_tuple_database.Database:
    """Fixture which returns a database with 5000 + 2 graph tuples, where 2 of the
  graph tuples are empty.

  For the current implementation of CreateRandomGraphTuple(), a database of
  5000 graphs is ~14MB of data.
  """
    # Generate some random graph tuples.
    graph_pool = [
        random_graph_tuple_database_generator.CreateRandomGraphTuple()
        for _ in range(128)
    ]

    # Generate a full list of graphs by randomly selecting from the graph pool.
    random_graph_tuples: List[graph_tuple_database.GraphTuple] = [
        copy.deepcopy(random.choice(graph_pool)) for _ in range(10000)
    ]
    # Index the random graphs by ir_id.
    for i, t in enumerate(random_graph_tuples):
        t.ir_id = i
        t.data_flow_steps = i

    with empty_graph_db.Session(commit=True) as s:
        s.add_all(random_graph_tuples)
        # Create the empty graph tuples. These should be ignored by the graph
        # reader.
        s.add_all([
            graph_tuple_database.GraphTuple.CreateEmpty(0),
            graph_tuple_database.GraphTuple.CreateEmpty(0),
        ])

    return empty_graph_db