def test_GraphToInputTarget_number_of_edges(): """Test number of edges in feature graphs.""" digraph = graph_util.AddShortestPath( np.random.RandomState(seed=1), graph_util.GenerateGraph(np.random.RandomState(seed=1), [10, 15])) igraph, tgraph = graph_util.GraphToInputTarget(digraph) assert igraph.number_of_edges() == digraph.number_of_edges() assert tgraph.number_of_edges() == digraph.number_of_edges()
def test_GraphToInputTarget_graph_features_shape(): """Test number of features graphs.""" digraph = graph_util.AddShortestPath( np.random.RandomState(seed=1), graph_util.GenerateGraph(np.random.RandomState(seed=1), [10, 15])) igraph, tgraph = graph_util.GraphToInputTarget(digraph) assert igraph.graph['features'].shape == (1,) assert tgraph.graph['features'].shape == (1,)
def test_GraphToInputTarget_edge_features_shape(): """Test number of features in edges.""" digraph = graph_util.AddShortestPath( np.random.RandomState(seed=1), graph_util.GenerateGraph(np.random.RandomState(seed=1), [10, 15])) igraph, tgraph = graph_util.GraphToInputTarget(digraph) for from_idx, to_idx in igraph.edges: assert igraph.edges[from_idx, to_idx]['features'].shape == (1,) assert tgraph.edges[from_idx, to_idx]['features'].shape == (2,)
def test_GenerateGraph_is_connected(): """Test that graph is connected.""" graph = graph_util.GenerateGraph( rand=np.random.RandomState(seed=1), num_nodes_min_max=[10, 15], dimensions=2, theta=20, rate=1.0, ) assert nx.is_connected(graph)
def test_GenerateGraph_num_edges(): """Test that graph has at least one edge per node.""" graph = graph_util.GenerateGraph( rand=np.random.RandomState(seed=1), num_nodes_min_max=[10, 15], dimensions=2, theta=20, rate=1.0, ) assert graph.number_of_edges() >= graph.number_of_nodes()
def test_GenerateGraph_num_nodes(): """Test that number of nodes is within requested range.""" graph = graph_util.GenerateGraph( rand=np.random.RandomState(seed=1), num_nodes_min_max=[10, 15], dimensions=2, theta=20, rate=1.0, ) assert 10 <= graph.number_of_nodes() < 15
def test_GenerateGraph_return_type(): """Test that networkx Graph is returned.""" graph = graph_util.GenerateGraph( rand=np.random.RandomState(seed=1), num_nodes_min_max=[10, 15], dimensions=2, theta=20, rate=1.0, ) assert isinstance(graph, nx.Graph)
def test_GraphToInputTarget_node_features_shape(): """Test number of features in nodes.""" digraph = graph_util.AddShortestPath( np.random.RandomState(seed=1), graph_util.GenerateGraph(np.random.RandomState(seed=1), [10, 15]), ) igraph, tgraph = graph_util.GraphToInputTarget(digraph) for node_idx in igraph.nodes: assert igraph.node[node_idx]["features"].shape == (5,) assert tgraph.node[node_idx]["features"].shape == (2,)