-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TreshMom/task-1
Task 1
- Loading branch information
Showing
5 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: 'pip' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
python scripts/run_tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
print("import sources directory") | ||
from .task_1 import graph_info, create_labeled_two_cycle_graph | ||
|
||
__all__ = ["graph_info", "create_labeled_two_cycle_graph"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import cfpq_data | ||
from networkx.drawing import nx_pydot as pydot | ||
from typing import Tuple, Set | ||
|
||
|
||
def graph_info(name_graph: str) -> Tuple[int, int, Set[str]]: | ||
labels = set() | ||
for _, _, data in name_graph.edges(data=True): | ||
if "label" in data: | ||
labels.add(data["label"]) | ||
|
||
return (name_graph.number_of_nodes(), name_graph.number_of_edges(), labels) | ||
|
||
|
||
def create_labeled_two_cycle_graph( | ||
countNode1: int, countNode2: int, nameLabels: Tuple[str, str], path: str | ||
) -> None: | ||
pydot.write_dot( | ||
G=cfpq_data.labeled_two_cycles_graph( | ||
n=countNode1, | ||
m=countNode2, | ||
labels=nameLabels, | ||
), | ||
path=path, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import networkx as nx | ||
import os | ||
import tempfile | ||
import pytest | ||
from project import create_labeled_two_cycle_graph, graph_info | ||
|
||
|
||
@pytest.fixture() | ||
def start(): | ||
print("Start test") | ||
|
||
|
||
def test_create_labeled_two_cycle_graph(): | ||
with tempfile.NamedTemporaryFile(suffix=".dot") as tmp_file: | ||
create_labeled_two_cycle_graph(3, 4, ("a", "b"), tmp_file.name) | ||
assert os.path.exists(tmp_file.name) | ||
|
||
G = nx.drawing.nx_pydot.read_dot(tmp_file.name) | ||
|
||
assert G.number_of_nodes() == 8 | ||
assert G.number_of_edges() == 9 | ||
for _, _, data in G.edges(data=True): | ||
assert data["label"] in ["a", "b"] | ||
|
||
|
||
def test_graph_info(): | ||
G = nx.Graph() | ||
G.add_nodes_from([1, 2, 3]) | ||
G.add_edges_from([(1, 2, {"label": "a"}), (2, 3, {"label": "b"})]) | ||
|
||
node_count, edge_count, labels = graph_info(G) | ||
|
||
assert node_count == 3 | ||
assert edge_count == 2 | ||
assert labels == {"a", "b"} |