Skip to content

Commit

Permalink
Merge pull request #1 from IThror10/feature/hw1
Browse files Browse the repository at this point in the history
Первая домашняя работа по Формальным языкам
  • Loading branch information
IThror10 authored Mar 1, 2024
2 parents 31ce799 + e234e49 commit db6c96c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Python application

on:
[ push, pull_request ]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r ./requirements.txt
- name: Test with pytest
run: |
python ./scripts/run_tests.py
19 changes: 19 additions & 0 deletions project/hw1/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cfpq_data
from cfpq_data.graphs.generators import labeled_two_cycles_graph
from networkx.drawing.nx_pydot import write_dot


def getGraphInfoByName(graphName: str):
graph_csv = cfpq_data.download(graphName)
graph = cfpq_data.graph_from_csv(graph_csv)
return (
graph.number_of_nodes(),
graph.number_of_edges(),
set(map(lambda x: x[2]["label"], graph.edges(data=True))),
)


def createBiSycleGraph(cSize1: int, cSize2: int, labels: set, path: str):
graph = labeled_two_cycles_graph(n=cSize1, m=cSize2, labels=labels)
print(path)
write_dot(graph, path)
48 changes: 48 additions & 0 deletions tests/test_hw1_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest

from tempfile import NamedTemporaryFile
from project.hw1.task import createBiSycleGraph, getGraphInfoByName


def test_get_graph_info_by_bzip_name():
nodes, edge, labels = getGraphInfoByName("bzip")
assert nodes == 632
assert edge == 556
assert labels == {"a", "d"}


def test_get_graph_info_by_biomedical_name():
nodes, edge, labels = getGraphInfoByName("biomedical")
assert nodes == 341
assert edge == 459
assert labels == {
"type",
"label",
"subClassOf",
"comment",
"versionInfo",
"title",
"language",
"publisher",
"description",
"creator",
}


def test_create_bisycle_graph():
target = ["digraph {"]
for i in [1, 2, 3, 0]:
target.append(f"{i};")
for j in range(3, 8):
target.append(f"{(j + 1)};")
for i in [(1, 2), (2, 3), (3, 0), (0, 1)]:
target.append(f"{i[0]} -> {i[1]} [key=0, label=a];")
for j in [(0, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 0)]:
target.append(f"{j[0]} -> {j[1]} [key=0, label=b];")
target.append("}")
target.append("")

with NamedTemporaryFile("w+") as tmp:
createBiSycleGraph(3, 5, ("a", "b"), tmp.name)
result = tmp.read()
assert result == "\n".join(target)

0 comments on commit db6c96c

Please sign in to comment.