Download .venv/Lib/site-packages/networkx/algorithms/tests/test_polynomials.py from DrDavis/PythonProject1: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/DrDavis/PythonProject1/resolve/main/.venv/Lib/site-packages/networkx/algorithms/tests/test_polynomials.py
- Command line
-
hf download hf://DrDavis/PythonProject1/.venv/Lib/site-packages/networkx/algorithms/tests/test_polynomials.py
-
curl -L -o test_polynomials.py https://huggingface.co/DrDavis/PythonProject1/resolve/main/.venv/Lib/site-packages/networkx/algorithms/tests/test_polynomials.py
1.98 kB
| """Unit tests for the :mod:`networkx.algorithms.polynomials` module.""" | |
| import pytest | |
| import networkx as nx | |
| sympy = pytest.importorskip("sympy") | |
| # Mapping of input graphs to a string representation of their tutte polynomials | |
| _test_tutte_graphs = { | |
| nx.complete_graph(1): "1", | |
| nx.complete_graph(4): "x**3 + 3*x**2 + 4*x*y + 2*x + y**3 + 3*y**2 + 2*y", | |
| nx.cycle_graph(5): "x**4 + x**3 + x**2 + x + y", | |
| nx.diamond_graph(): "x**3 + 2*x**2 + 2*x*y + x + y**2 + y", | |
| } | |
| _test_chromatic_graphs = { | |
| nx.complete_graph(1): "x", | |
| nx.complete_graph(4): "x**4 - 6*x**3 + 11*x**2 - 6*x", | |
| nx.cycle_graph(5): "x**5 - 5*x**4 + 10*x**3 - 10*x**2 + 4*x", | |
| nx.diamond_graph(): "x**4 - 5*x**3 + 8*x**2 - 4*x", | |
| nx.path_graph(5): "x**5 - 4*x**4 + 6*x**3 - 4*x**2 + x", | |
| } | |
| def test_tutte_polynomial(G, expected): | |
| assert nx.tutte_polynomial(G).equals(expected) | |
| def test_tutte_polynomial_disjoint(G): | |
| """Tutte polynomial factors into the Tutte polynomials of its components. | |
| Verify this property with the disjoint union of two copies of the input graph. | |
| """ | |
| t_g = nx.tutte_polynomial(G) | |
| H = nx.disjoint_union(G, G) | |
| t_h = nx.tutte_polynomial(H) | |
| assert sympy.simplify(t_g * t_g).equals(t_h) | |
| def test_chromatic_polynomial(G, expected): | |
| assert nx.chromatic_polynomial(G).equals(expected) | |
| def test_chromatic_polynomial_disjoint(G): | |
| """Chromatic polynomial factors into the Chromatic polynomials of its | |
| components. Verify this property with the disjoint union of two copies of | |
| the input graph. | |
| """ | |
| x_g = nx.chromatic_polynomial(G) | |
| H = nx.disjoint_union(G, G) | |
| x_h = nx.chromatic_polynomial(H) | |
| assert sympy.simplify(x_g * x_g).equals(x_h) | |