Skip to content

Commit

Permalink
Add autotests to task 11
Browse files Browse the repository at this point in the history
  • Loading branch information
KubEF committed Apr 30, 2024
1 parent a06e1f8 commit 6c26b32
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tasks/task11.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edge_expr = '(' expr ',' expr ',' expr ')'
regexp = CHAR | VAR | '(' regexp ')' | (regexp '|' regexp) | (regexp '^' range) | (regexp '.' regexp) | (regexp '&' regexp)
range = '[' NUM '..' NUM? ']'
range = '[' NUM ('..' NUM)? ']'
select = v_filter? v_filter? 'return' VAR (',' VAR)? 'where' VAR 'reachable' 'from' VAR 'in' VAR 'by' expr
Expand All @@ -42,7 +42,6 @@ CHAR = '"' [a..z] '"'
```
let g is graph
add edge (1, "a", 2) to g
add edge (2, "a", 3) to g
add edge (3, "a", 1) to g
add edge (1, "c", 5) to g
Expand Down Expand Up @@ -200,3 +199,15 @@ _____________________________________
- [ ] С использованием ANTLR реализовать синтаксический анализатор предложенного выше языка. А именно, реализовать функцию, которая принимает строку и возвращает дерево разбора.
- [ ] Реализовать функцию, которая по дереву разбора возвращает количество узлов в нём.
- [ ] Реализовать функцию, которая по дереву разбора строит строку, которая была разобрана.

Требуемые функции:
```python
def prog_to_tree(program: str) -> ProgContex:
pass

def nodes_count(tree: ProgContex) -> int:
pass

def tree_to_prog(tree: ProgContex) -> str:
pass
```
36 changes: 36 additions & 0 deletions tests/autotests/test_task11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file contains test cases that you need to pass to get a grade
# You MUST NOT touch anything here except ONE block below
# You CAN modify this file IF AND ONLY IF you have found a bug and are willing to fix it
# Otherwise, please report it
import sys
from copy import deepcopy
import pytest

# Fix import statements in try block to run tests
try:
from project.task11 import prog_to_tree, nodes_count, tree_to_prog
except ImportError:
pytestmark = pytest.mark.skip("Task 11 is not ready to test!")

# it will be filled by script? In some way
INPUT_PROGRAMS = []


def fill_input(argv):
for file_path in argv:
with open(file_path, "r") as file:
program = file.read()
INPUT_PROGRAMS.append(program)


class TestParser:
@pytest.mark.parametrize("program", INPUT_PROGRAMS, ids=lambda x: x)
def id_test(self, program):
tree_before = prog_to_tree(program)
tree_after = prog_to_tree(tree_to_prog(tree_before))
assert nodes_count(tree_before) == nodes_count(tree_after)
assert program == tree_to_prog(tree_before)


if __name__ == "__main__":
fill_input(sys.argv[1::])

0 comments on commit 6c26b32

Please sign in to comment.