Exemple #1
0
class TestDistanceMeasures:
    @pytest.mark.parametrize(
        "graph, expected_value",
        (
            (gp.cycle_graph(3), 3),
            (gp.cycle_graph(4), 4),
            (gp.cycle_graph(5), 5),
            (gp.path_graph(3), 4),
            (gp.path_graph(4), 6),
            (gp.path_graph(5), 8),
        ),
    )
    def test_triameter(self, graph, expected_value):
        """Ensure triameter returns the expected value for a given graph"""
        assert gp.triameter(graph) == expected_value
Exemple #2
0
class TestFunctions:
    def test_sequence_of_zeros_is_graphic(self):
        assert gp.is_graphic([0, 0, 0, 0]) == True

    def test_descending_sequence_of_integers_is_not_graphic(self):
        assert gp.is_graphic([5, 4, 3, 2, 1]) == False

    def test_elimination_sequence_of_complete_graph(self):
        G = gp.complete_graph(5)
        assert gp.elimination_sequence(G) == [4, 3, 2, 1, 0]

    @pytest.mark.parametrize(
        "graph, source, target, expected_value",
        (
            (gp.path_graph(5), 0, 4, 4),
            (gp.path_graph(5), 1, 4, 3),
            (gp.path_graph(5), 2, 4, 2),
            (gp.path_graph(5), 3, 4, 1),
            (gp.path_graph(5), 4, 4, 0),
        ),
    )
    def test_distance(self, graph, source, target, expected_value):
        """Ensure that distance returns the expected value for a given graph"""
        assert gp.distance(graph, source, target) == expected_value
 def test_total_zero_forcing_number_of_path_is_2(self):
     G = gp.path_graph(5)
     assert gp.total_zero_forcing_number(G) == 2
 def test_pair_of_adjacent_nodes_is_total_forcing_set_of_path(self):
     G = gp.path_graph(6)
     assert gp.is_total_zero_forcing_set(G, [2, 3]) == True
 def test_leaf_is_not_total_forcing_set_of_path(self):
     G = gp.path_graph(3)
     assert gp.is_total_zero_forcing_set(G, [0]) == False
 def test_leaf_is_zero_forcing_set_of_path(self):
     G = gp.path_graph(3)
     assert gp.is_zero_forcing_set(G, [0]) == True
 def test_endpoint_is_connected_forcing_set_of_path(self):
     G = gp.path_graph(2)
     assert gp.is_connected_zero_forcing_set(G, [0])
Exemple #8
0
def test_min_maximal_matching_of_P2_through_P4_is_1():
    for i in range(2, 5):
        P = gp.path_graph(i)
        assert gp.min_maximal_matching_number(P) == 1
Exemple #9
0
def test_matching_number_of_path_is_ceil_of_half_of_edges():
    for i in range(2, 12):
        P = gp.path_graph(i)
        m = math.ceil(gp.number_of_edges(P) / 2)
        assert gp.matching_number(P, method="bf") == m
        assert gp.matching_number(P, method="ilp") == m
Exemple #10
0
class TestTopologicalIndices:
    @pytest.mark.parametrize(
        "graph, expected_value",
        ((gp.path_graph(2), 1**-0.5), (gp.cycle_graph(3), 1.5),
         (gp.cycle_graph(4), 2), (gp.cycle_graph(5), 2.5)),
    )
    def test_randic_index(self, graph, expected_value):
        """Ensure randic_index returns the expected value for a given graph"""
        assert gp.randic_index(graph) == expected_value

    @pytest.mark.parametrize(
        "graph, k, expected_value",
        (
            (gp.path_graph(2), -0.5, 1**-0.5),
            (gp.cycle_graph(3), -0.5, 1.5),
            (gp.cycle_graph(4), -0.5, 2),
            (gp.cycle_graph(5), -0.5, 2.5),
        ),
    )
    def test_generalized_randic_index(self, graph, k, expected_value):
        """Ensure randic_index returns the expected value for a given graph"""
        assert gp.generalized_randic_index(graph, k) == expected_value

    @pytest.mark.parametrize("graph, expected_value",
                             ((gp.path_graph(2), 1), (gp.cycle_graph(3), 1.5),
                              (gp.complete_graph(4), 2)))
    def test_augmented_randic_index(self, graph, expected_value):
        """Ensure augmented_randic_index returns the expected value for a given graph"""
        assert gp.augmented_randic_index(graph) == expected_value

    @pytest.mark.parametrize("graph, expected_value",
                             ((gp.path_graph(2), 1), (gp.cycle_graph(3), 1.5),
                              (gp.complete_graph(4), 2)))
    def test_harmonic_index(self, graph, expected_value):
        """Ensure augmented_randic_index returns the expected value for a given graph"""
        assert gp.harmonic_index(graph) == expected_value

    @pytest.mark.parametrize(
        "graph, expected_value",
        ((gp.path_graph(2), 0), (gp.cycle_graph(3), 3 * math.sqrt(2) / 2),
         (gp.complete_graph(4), 4.0)),
    )
    def test_atom_bond_connectivity_index(self, graph, expected_value):
        """Ensure augmented_randic_index returns the expected value for a given graph"""
        assert gp.atom_bond_connectivity_index(graph) == expected_value

    @pytest.mark.parametrize(
        "graph, expected_value",
        ((gp.path_graph(2), 1 / math.sqrt(2)), (gp.cycle_graph(3), 1.5),
         (gp.complete_graph(4), 6 / math.sqrt(6))),
    )
    def test_sum_connectivity_index(self, graph, expected_value):
        """Ensure augmented_randic_index returns the expected value for a given graph"""
        assert gp.sum_connectivity_index(graph) == expected_value

    @pytest.mark.parametrize("graph, expected_value",
                             ((gp.path_graph(2), 2.0),
                              (gp.cycle_graph(3), 12.0),
                              (gp.complete_graph(4), 36.0)))
    def test_first_zagreb_index(self, graph, expected_value):
        """Ensure augmented_randic_index returns the expected value for a given graph"""
        assert gp.first_zagreb_index(graph) == expected_value

    @pytest.mark.parametrize("graph, expected_value",
                             ((gp.path_graph(2), 1.0),
                              (gp.cycle_graph(3), 12.0),
                              (gp.complete_graph(4), 54.0)))
    def test_second_zagreb_index(self, graph, expected_value):
        """Ensure augmented_randic_index returns the expected value for a given graph"""
        assert gp.second_zagreb_index(graph) == expected_value
Exemple #11
0
def test_connected_domination_number_of_P5_is_3():
    G = gp.path_graph(5)
    assert gp.connected_domination_number(G) == 3