Skip to content

Commit

Permalink
Move all regexes to table
Browse files Browse the repository at this point in the history
  • Loading branch information
KubEF committed May 10, 2024
1 parent 14b4bc8 commit c5f5c4d
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 67 deletions.
4 changes: 2 additions & 2 deletions tests/autotests/fixtures.py
@@ -1,10 +1,10 @@
import pytest
from helper import generate_rnd_graph, generate_rnd_thick_graph
from helper import generate_rnd_graph, generate_rnd_dense_graph
from networkx import MultiDiGraph
from constants import LABELS
import random

funcs = [generate_rnd_thick_graph, generate_rnd_graph]
funcs = [generate_rnd_dense_graph, generate_rnd_graph]


@pytest.fixture(scope="function", params=range(8))
Expand Down
81 changes: 70 additions & 11 deletions tests/autotests/grammars_constants.py
Expand Up @@ -3,7 +3,63 @@

GRAMMARS_TABLE: list[dict[str, list[str | cfg.CFG]]] = [
{
REGEXP: ["a"],
REGEXP: ["(a | b | c)*(d | e | f)*"],
CFG: [],
EBNF: ["S -> (a | b | c)*(d | e | f)*"],
},
{REGEXP: ["(a b) | (a c)"], CFG: [], EBNF: ["S -> (a b) | (a c)"]},
{REGEXP: ["a b c*"], CFG: [], EBNF: ["S -> a b c*"]},
{REGEXP: ["(a b d) | (a b c)"], CFG: [], EBNF: ["S -> (a b d) | (a b c)"]},
{
REGEXP: ["(a|b|c|d|e)(a|b|c|d|e)*"],
CFG: [],
EBNF: ["S -> (a|b|c|d|e)(a|b|c|d|e)*"],
},
{REGEXP: ["(a|b)*(c|d)*"], CFG: [], EBNF: ["S -> (a|b)*(c|d)*"]},
{REGEXP: ["(a|b|c|d|e)f*"], CFG: [], EBNF: ["S -> (a|b|c|d|e)f*"]},
{REGEXP: ["a a"], CFG: [], EBNF: ["S -> a a"]},
{REGEXP: ["a b*"], CFG: [], EBNF: ["S -> a b*"]},
{REGEXP: ["a b"], CFG: [], EBNF: ["S -> a b"]},
{REGEXP: ["(a b) | (a b c)"], CFG: [], EBNF: ["S -> (a b) | (a b c)"]},
{REGEXP: ["a|c"], CFG: [], EBNF: ["S -> a|c"]},
{REGEXP: ["(a|c)(b|d)"], CFG: [], EBNF: ["S -> (a|c)(b|d)"]},
{REGEXP: ["b"], CFG: [cfg.CFG.from_text("S -> b")], EBNF: ["S -> b"]},
{REGEXP: ["a*a*b"], CFG: [], EBNF: ["S -> a*a*b"]},
{
REGEXP: ["((a | b)*c)*((d | e)*f)*"],
CFG: [],
EBNF: ["S -> ((a | b)*c)*((d | e)*f)*"],
},
{REGEXP: ["((a b d) | (a b c))*"], CFG: [], EBNF: ["S -> ((a b d) | (a b c))*"]},
{REGEXP: ["(a|c)*"], CFG: [], EBNF: ["S -> (a|c)*"]},
{REGEXP: ["(a | c)*(a | b)*"], CFG: [], EBNF: ["S -> (a | c)*(a | b)*"]},
{
REGEXP: ["(a | b)*(c | d)*(e | f)*"],
CFG: [],
EBNF: ["S -> (a | b)*(c | d)*(e | f)*"],
},
{
REGEXP: ["a*(a | b)*", "(a|b)*", "a* | (a | b)*"],
CFG: [],
EBNF: ["S -> a*(a | b)*"],
},
{REGEXP: ["(a b d)* | (a b c)*"], CFG: [], EBNF: ["S -> (a b d)* | (a b c)*"]},
{REGEXP: ["a b* c"], CFG: [], EBNF: ["S -> a b* c"]},
{REGEXP: ["(a a)*"], CFG: [], EBNF: ["S -> (a a)*"]},
{REGEXP: ["((a|b)*c)*"], CFG: [], EBNF: ["S -> ((a|b)*c)*"]},
{REGEXP: ["a b c d"], CFG: [], EBNF: ["S -> a b c d"]},
{
REGEXP: [
"b b b",
],
CFG: [],
EBNF: [
"S -> b b b",
],
},
{REGEXP: ["(a b d*) | (a b c*)"], CFG: [], EBNF: ["S -> (a b d*) | (a b c*)"]},
{
REGEXP: ["a", "a | a"],
CFG: [
cfg.CFG.from_text("S -> a"),
cfg.CFG.from_text(
Expand All @@ -17,7 +73,7 @@
EBNF: ["S -> a"],
},
{
REGEXP: ["a*"],
REGEXP: ["a*", "a* a*", "a* | a"],
CFG: [
cfg.CFG.from_text("S -> $ | a S"),
cfg.CFG.from_text("S -> $ | S S | a"),
Expand Down Expand Up @@ -127,7 +183,7 @@
EBNF: ["S -> ((a | b) * c)*(d | e)"],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text("S -> $ | a S b | S S"),
cfg.CFG.from_text("S -> $ | a S b S"),
Expand All @@ -137,7 +193,7 @@
EBNF: ["S -> $ | a S b | S S"],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text("S -> $ | a S b | c S d | S S"),
cfg.CFG.from_text("S -> $ | a S b S | c S d S"),
Expand All @@ -147,7 +203,7 @@
EBNF: ["S -> $ | a S b | c S d | S S"],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text(
"""
Expand Down Expand Up @@ -175,7 +231,7 @@
EBNF: ["S -> $ | S a S b | S a S d | S c S d | S c S b"],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text(
"""
Expand Down Expand Up @@ -212,7 +268,7 @@
],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text("S -> a S | $"),
cfg.CFG.from_text(
Expand All @@ -225,7 +281,7 @@
EBNF: ["S -> a S | $"],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text(
"""
Expand All @@ -246,12 +302,12 @@
],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [cfg.CFG.from_text("S -> a | b | S c S | S d S | e S f | g S")],
EBNF: ["S -> a | b | (S ( c | d ) S ) | ( e S f ) | ( g S )"],
},
{
REGEXP: set(),
REGEXP: [],
CFG: [
cfg.CFG.from_text(
"S -> $ | a S b | b S a | e S f | S S | c S d | d S c | f S e"
Expand All @@ -267,7 +323,10 @@
(regexp, ds[CFG]) for ds in GRAMMARS_TABLE for regexp in ds[REGEXP]
]
GRAMMARS: list[list[cfg.CFG]] = [ds[CFG] for ds in GRAMMARS_TABLE if len(ds[CFG]) > 1]
GRAMMARS_DIFFERENT: list[cfg.CFG] = [ds[CFG][0] for ds in GRAMMARS_TABLE]
GRAMMARS_DIFFERENT: list[cfg.CFG] = [
ds[CFG][0] for ds in GRAMMARS_TABLE if len(ds[CFG]) >= 1
]
CFG_EBNF: list[tuple[list[cfg.CFG], list[str]]] = [
(ds[CFG], ds[EBNF]) for ds in GRAMMARS_TABLE
]
REGEXES = [regex_str for ds in GRAMMARS_TABLE for regex_str in ds[REGEXP]]
2 changes: 1 addition & 1 deletion tests/autotests/helper.py
Expand Up @@ -14,7 +14,7 @@ def generate_rnd_graph(
return cfpq_data.graphs.labeled_scale_free_graph(n_of_nodes, labels=labels)


def generate_rnd_thick_graph(
def generate_rnd_dense_graph(
min_size: int, max_size: int, labels: list[str]
) -> MultiDiGraph:
n_of_nodes = random.randint(min_size, max_size)
Expand Down
43 changes: 0 additions & 43 deletions tests/autotests/regex_constants.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/autotests/test_task2.py
Expand Up @@ -11,7 +11,7 @@
from helper import GraphWordsHelper, generate_rnd_start_and_final
from constants import IS_FINAL, IS_START
from fixtures import graph
from regex_constants import REGEXES
from grammars_constants import REGEXES

# Fix import statements in try block to run tests
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/autotests/test_task3.py
Expand Up @@ -7,7 +7,7 @@
import pytest
import random
import itertools
from regex_constants import REGEXES
from grammars_constants import REGEXES

# Fix import statements in try block to run tests
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/autotests/test_task4.py
Expand Up @@ -5,7 +5,7 @@
import random
from copy import deepcopy
import pytest
from regex_constants import REGEXES
from grammars_constants import REGEXES
from helper import generate_rnd_start_and_final, rpq_dict_to_set
from fixtures import graph

Expand Down
8 changes: 1 addition & 7 deletions tests/autotests/test_task8.py
Expand Up @@ -4,13 +4,7 @@
# Otherwise, please report it
from copy import deepcopy
import pytest
from grammars_constants import (
REGEXP_CFG,
GRAMMARS,
GRAMMARS_DIFFERENT,
CFG_EBNF,
CFG_EBNF_MANY,
)
from grammars_constants import REGEXP_CFG, GRAMMARS, GRAMMARS_DIFFERENT, CFG_EBNF
from helper import generate_rnd_start_and_final
from rpq_template_test import (
rpq_cfpq_test,
Expand Down

0 comments on commit c5f5c4d

Please sign in to comment.