Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TreshMom committed Mar 1, 2024
2 parents 7c7f67a + d99ddfa commit 1a0e768
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
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
4 changes: 3 additions & 1 deletion project/__init__.py
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"]
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 1a0e768

Please sign in to comment.