def test_is_forest():
    # generate chain
    chain = np.c_[np.arange(1, 10), np.arange(9)]
    assert_true(is_forest(chain, len(chain) + 1))
    assert_true(is_forest(chain))
    # generate circle
    circle = np.vstack([chain, [9, 0]])
    assert_false(is_forest(circle))
    assert_false(is_forest(circle, len(chain) + 1))

    # union of two disjoint chains
    two_chains = np.vstack([chain, chain + 10])
    assert_true(is_forest(two_chains, 20))

    # union of chain and circle
    disco_graph = np.vstack([chain, circle + 10])
    assert_false(is_forest(disco_graph))

    # generate random fully connected graph
    graph = np.random.uniform(size=(10, 10))
    edges = np.c_[graph.nonzero()]
    assert_false(is_forest(edges))

    try:
        from scipy.sparse.csgraph import minimum_spanning_tree
        tree = minimum_spanning_tree(sparse.csr_matrix(graph))
        tree_edges = np.c_[tree.nonzero()]
        assert_true(is_forest(tree_edges, 10))
        assert_true(is_forest(tree_edges))
    except __HOLE__:
        pass
dataset/ETHPy150Open pystruct/pystruct/pystruct/tests/test_inference/test_maxprod.py/test_is_forest