-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from lib import Test, Dataset | ||
|
||
class DB: | ||
Task1 = Dataset( | ||
Test( | ||
";<) \n ;<) \=;<)", | ||
3 | ||
), | ||
Test( | ||
";<);<);<);<);<);<)", | ||
6 | ||
), | ||
Test( | ||
";<)\;<)\l;<)", | ||
3 | ||
), | ||
Test( | ||
";<)fghjk;;;;;:;;<))))) m:<(", | ||
2 | ||
), | ||
Test( | ||
";<)fcclkkyuaew8;<)", | ||
2 | ||
), | ||
name = "Tsk1" | ||
) | ||
Task2 = Dataset( | ||
Test( | ||
"Довольно распространённая ошибка ошибка – это лишний повтор повтор слова слова. Смешно, не не правда ли? Не нужно портить хор хоровод.", | ||
"Довольно распространённая ошибка – это лишний повтор слова. Смешно, не правда ли? Не нужно портить хор хоровод." | ||
), | ||
Test( | ||
"W W W W W", | ||
"W" | ||
), | ||
Test( | ||
"W W W W W", | ||
"W" | ||
), | ||
Test( | ||
"a a", | ||
"a" | ||
), | ||
Test( | ||
"a а", | ||
"a а", | ||
flags=["SPACES_MODE"] | ||
), | ||
name = "Tsk2" | ||
) | ||
Task3 = Dataset( | ||
Test( | ||
"Классное слово – обороноспособность, которое должно идти после слов: трава и молоко.", | ||
"""и | ||
идти | ||
слов | ||
слово | ||
трава | ||
должно | ||
молоко | ||
обороноспособность""" | ||
), | ||
Test( | ||
"Е а", | ||
"а\nЕ" | ||
), | ||
Test( | ||
"АА а ААА", | ||
"а\nАА\nААА" | ||
), | ||
Test( | ||
"СССР КПСС", | ||
"" | ||
), | ||
Test( | ||
"мне лень придумывать тест", | ||
"мне\nлень\nтест" | ||
), | ||
name = "Tsk3" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .regex.main import Main as regex | ||
|
||
from .test.main import Main as test | ||
|
||
from .test.dataset.test_obj import Test | ||
from .test.dataset.dataset import Dataset |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import re | ||
|
||
class Main(): | ||
def __init__(self, smile: str = r"\;\<\)") -> None: | ||
self.regex = re.compile(smile) | ||
|
||
def count_matches(self, inp: str) -> int: | ||
return len(re.findall(self.regex, inp)) | ||
|
||
def findall(self, inp: str) -> list: | ||
return re.findall(self.regex, inp) | ||
|
||
def sub(self, inp: str) -> str: | ||
return re.sub(self.regex, "", inp) |
Binary file not shown.
Binary file added
BIN
+1.12 KB
informatics/sem1/lab3/lib/test/dataset/__pycache__/dataset.cpython-312.pyc
Binary file not shown.
Binary file added
BIN
+676 Bytes
informatics/sem1/lab3/lib/test/dataset/__pycache__/test_obj.cpython-312.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .test_obj import Test | ||
|
||
class Dataset(): | ||
def __init__(self, *args, name: str = "Test") -> None: | ||
self.tests_array = args | ||
self.name = name | ||
|
||
def __len__(self): | ||
return len(self.tests_array) | ||
|
||
def __getitem__(self, idx): | ||
_ = self.tests_array[idx] | ||
return (idx+1, _.test, _.result, _.flags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from dataclasses import dataclass | ||
from typing import List, Union, Optional | ||
|
||
@dataclass | ||
class Test: | ||
test: str | ||
result: str | int | ||
|
||
# Possible flags - IGNORE_ERROR, SPACES_MODE | ||
flags: Optional[Union[List[str]]] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class Main(): | ||
def __init__(self, tests: object, test_name: str = None) -> None: | ||
self.tests = tests | ||
self.test_name = test_name if test_name is not None else tests.name | ||
|
||
def run(self, func: object) -> None: | ||
|
||
def inner() -> int: | ||
print( | ||
f"\n{func.__name__} тестируется на наборе тестов {self.test_name}" | ||
) | ||
for idx, test, result, flags in self.tests: | ||
if func(test) == result: print(f"\t✅ Тест {idx} пройден успешно") | ||
else: | ||
print(f"\t❌ Тест {idx} провален") | ||
|
||
if flags is not None and "SPACES_MODE" in flags: | ||
R, L = "<", ">" | ||
else: R, L = "", "" | ||
|
||
print( | ||
"\t\t" + f"Ввод: {L}{test}{R}", | ||
f"Ожидаемый результат: {L}{result}{R}", | ||
f"Полученный результат: {L}{func(test)}{R}", | ||
sep = "\n\t\t" | ||
) | ||
|
||
|
||
if flags is not None and "IGNORE_ERROR" in flags: | ||
print("\t\tIGNORE_ERROR flag activated!") | ||
continue | ||
|
||
break | ||
else: return -1 | ||
return idx | ||
|
||
_ = inner() | ||
print("✅ Ошибок не обнаружено!" if _==-1 else f"❌ Ошибка на тесте {_}!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from lib import regex, test | ||
from db import DB | ||
|
||
def main() -> None: | ||
# Task 1 | ||
Regex1 = regex(r"\;\<\)") | ||
@test(DB.Task1).run | ||
def count_smiles(inp): | ||
return Regex1.count_matches(inp) | ||
|
||
def count_smiles1(inp): | ||
return Regex1.count_matches(inp) | ||
|
||
# Task 2 | ||
Regex2 = regex(r"\b(\w+)\s+(?=\1(\b))") | ||
@test(DB.Task2).run | ||
def del_repeats(inp): | ||
return Regex2.sub(inp) | ||
|
||
def del_repeats1(inp): | ||
return Regex2.sub(inp) | ||
|
||
# Task 3 - только русский! | ||
Regex3 = regex(r"(?i)\b([^оуэыияеёю ]+|[^ауэыияеёю ]+|[^аоэыияеёю ]+|[^аоуыияеёю ]+|[^аоуэияеёю ]+|[^аоуэыяеёю ]+|[^аоуэыиеёю ]+|[^аоуэыияёю ]+|[^аоуэыияею ]+|[^аоуэыияеё ]+)\b") | ||
Regex4 = regex(r"(?i)\b[^оуэыияеёюа ]+\b") | ||
@test(DB.Task3).run | ||
def vowel_find(inp): | ||
words = list(set(Regex3.findall(inp)) - set(Regex4.findall(inp))) | ||
return "\n".join( | ||
sorted( | ||
words, | ||
key=lambda x: (len(x), x.lower()) | ||
) | ||
) | ||
|
||
def vowel_find1(inp): | ||
words = list(set(Regex3.findall(inp)) - set(Regex4.findall(inp))) | ||
return "\n".join( | ||
sorted( | ||
words, | ||
key=lambda x: (len(x), x.lower()) | ||
) | ||
) | ||
|
||
print() | ||
|
||
print("MANUAL TEST MODE") | ||
regex_array = [count_smiles1, del_repeats1, vowel_find1] | ||
while True: | ||
_ = input("Введите номер регулярки: ") | ||
inp = input("Введите текст: ") | ||
|
||
if _ == "1": print(regex_array[int(_)-1](inp)) | ||
elif _ == "2": print(regex_array[int(_)-1](inp)) | ||
elif _ == "3": print(regex_array[int(_)-1](inp)) | ||
else: print("Нет такой регулярки") | ||
|
||
if __name__ == "__main__": | ||
main() |
Binary file not shown.
File renamed without changes.