Skip to content

Commit

Permalink
Merge branch 'main' into task-2
Browse files Browse the repository at this point in the history
  • Loading branch information
TreshMom committed Mar 1, 2024
2 parents c4ed3a2 + 1a0e768 commit f83c8ee
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
from .task_1 import graph_info, create_labeled_two_cycle_graph

__all__ = ["graph_info", "create_labeled_two_cycle_graph"]
<<<<<<< HEAD
__all__ = ["regex_to_min_dfa", "create_nfa"]
=======
>>>>>>> main
25 changes: 25 additions & 0 deletions project/task_1.py
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,
)
35 changes: 35 additions & 0 deletions tests/test_task_1.py
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"}

0 comments on commit f83c8ee

Please sign in to comment.