Skip to content
Closed

Lab3 #1564

Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2311dec
2
YeeeeRE Nov 2, 2025
2d557f5
lab2 1st try
Kulebyak291 Nov 2, 2025
8775c18
lab2 1st 1st try
Kulebyak291 Nov 2, 2025
2f6677b
fix
Kulebyak291 Nov 3, 2025
b1e41a4
fix
Kulebyak291 Nov 3, 2025
00aced7
add vector n stack tests
Kulebyak291 Nov 11, 2025
d029fb8
777
Kulebyak291 Nov 16, 2025
35b8542
777
Nov 17, 2025
8f645ae
776
Nov 17, 2025
6211ca9
775
Nov 17, 2025
56012a1
774
Nov 17, 2025
cfdd4ef
lab3 1sttry
Nov 27, 2025
30db81c
lab3
Nov 27, 2025
9c404e0
lab3.1
Nov 27, 2025
838b259
lab3.2
Nov 27, 2025
c0a3cda
lab3.3
Nov 27, 2025
2e4b221
lab3.4
Nov 27, 2025
f6e863b
lab3.5
Nov 27, 2025
348182c
3.6
Dec 1, 2025
d29ac0d
3.6.1
Dec 1, 2025
15598c8
3.6.2
Dec 1, 2025
d8fa329
3.6.3
Dec 1, 2025
723478d
3.6.4
Dec 1, 2025
23ee5f0
3.6.5
Dec 1, 2025
46b2be9
fix path
Dec 3, 2025
1b85ba8
11
Dec 4, 2025
536ac1c
11/1
Dec 4, 2025
e39a5c8
11/2
Dec 4, 2025
7b017c6
11/3
Dec 4, 2025
207695b
11/4
Dec 5, 2025
5f54f6a
11/5
Dec 5, 2025
b2a831d
11/6
Dec 5, 2025
f33e939
12/1
Dec 6, 2025
f4c8018
12/2
Dec 6, 2025
f2bff6d
12/2
Dec 6, 2025
b988ae0
12/3
Dec 6, 2025
dbb58af
12/4
Dec 6, 2025
86f204b
13/1
Dec 7, 2025
4f81374
13/1
Dec 7, 2025
201a89a
13/1
Dec 7, 2025
328a26e
.
Dec 8, 2025
83d1dbe
..
Dec 8, 2025
a27b13c
...
Dec 8, 2025
d5509fb
...
Dec 8, 2025
2bfdf73
...
Dec 8, 2025
ca7766a
m
Dec 8, 2025
a58f79b
m
Dec 8, 2025
953b1e0
переделал
Dec 17, 2025
e805348
переделал 2
Dec 17, 2025
07ad071
переделал 2.1
Dec 17, 2025
abda0c3
переделал 3
Dec 17, 2025
d1c950c
переделал 3.1
Dec 17, 2025
1e46d9d
perdelal
Dec 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/clangtidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: cpp-linter

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
cpp-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file
tidy-checks: 'bugprone-*,performance-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-init-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-no-malloc,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-vararg,-bugprone-infinite-loop'
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=clang
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS_INIT="-fsanitize=address" -DCMAKE_C_FLAGS_INIT="-fsanitize=address" -DCMAKE_EXE_LINKER_FLAGS_INIT="-fsanitize=address"

- name: Build
# Build your program with the given configuration
Expand Down
1 change: 1 addition & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OLEG PAVLOV 4091 LAB2
1 change: 1 addition & 0 deletions 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LAB2 PAVLOV OLEG 4091
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ else()
endif()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опции компиляции удалять нельзя.

endif()

add_subdirectory(LibraryC)
#add_subdirectory(LibraryC)
add_subdirectory(LibraryCPP)
add_subdirectory(LibraryCPPClass)
add_subdirectory(LibraryCPPTemplate)
#add_subdirectory(LibraryCPPClass)
#add_subdirectory(LibraryCPPTemplate)

add_subdirectory(Lab1C)
#add_subdirectory(Lab1C)
add_subdirectory(Lab3CPP)
6 changes: 6 additions & 0 deletions Lab1CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_executable(Lab1CPP lab1.cpp)
target_include_directories(Lab1CPP PUBLIC ../LibraryCPP)
target_link_libraries(Lab1CPP LibraryCPP)

add_test(NAME TestLab1CPP COMMAND $<TARGET_FILE:Lab1CPP> ${CMAKE_CURRENT_SOURCE_DIR}/input.txt)
set_property(TEST TestLab1CPP PROPERTY PASS_REGULAR_EXPRESSION "Max odd sequence length: 3.*Array after right shift by 2: 0 0 1 3 5 2 7 9 11 4")
4 changes: 4 additions & 0 deletions Lab1CPP/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
10
1 3 5 2 7 9 11 4 6 8
2
right
101 changes: 101 additions & 0 deletions Lab1CPP/lab1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "array.h"

Check failure on line 1 in Lab1CPP/lab1.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Lab1CPP/lab1.cpp:1:10 [clang-diagnostic-error]

'array.h' file not found
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

size_t longest_odd_sequence(const Array* arr) {
size_t max_len = 0;
size_t current_len = 0;

for (size_t i = 0; i < array_size(arr); ++i) {
if (array_get(arr, i) % 2 != 0) {
current_len++;
if (current_len > max_len) max_len = current_len;
}
else {
current_len = 0;
}
}

return max_len;
}

void shift_array(Array* arr, int steps, bool left) {
ssize_t n = static_cast<ssize_t>(array_size(arr));
if (left) {
for (ssize_t i = 0; i < n - steps; ++i) {
array_set(arr, i, array_get(arr, i + steps));
}
for (ssize_t i = n - steps; i < n; ++i) {
array_set(arr, i, 0);
}
}
else { //vpravo
for (ssize_t i = n - 1; i >= steps; --i) {
array_set(arr, i, array_get(arr, i - steps));
}
for (ssize_t i = 0; i < steps; ++i) {
array_set(arr, i, 0);
}
}
}

int main(int argc, char* argv[])
{
string input_filename = (argc > 1) ? argv[1] : "input.txt";
ifstream input(input_filename);
if (!input.is_open()) {
cerr << "Cannot open " << input_filename << endl;
return 1;
}

size_t n;
input >> n;

Array* arr = array_create(n);

for (size_t i = 0; i < n; ++i) {
int sdvig;
input >> sdvig;
array_set(arr, i, sdvig);
}

int steps;
input >> steps;

string napravlenie;
input >> napravlenie;
bool left = (napravlenie == "left");

ofstream output("output.txt");
if (!output.is_open()) {
cerr << "Cannot create output.txt" << endl;
array_delete(arr);
return 1;
}

size_t max_len = longest_odd_sequence(arr);
cout << "Max odd sequence length: " << max_len << endl;
output << max_len << endl;

Array* shifted_arr = array_create(n);
for (size_t i = 0; i < n; ++i) {
array_set(shifted_arr, i, array_get(arr, i));
}
shift_array(shifted_arr, steps, left);
cout << "Array after " << napravlenie << " shift by " << steps << ": ";
for (size_t i = 0; i < array_size(shifted_arr); ++i) {
cout << array_get(shifted_arr, i) << " ";
output << array_get(shifted_arr, i) << " ";
}
cout << endl;

output << endl;

array_delete(arr);
array_delete(shifted_arr);

return 0;
}
18 changes: 18 additions & 0 deletions Lab2CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_executable(Lab2CPP main.cpp)
target_include_directories(Lab2CPP PUBLIC ../LibraryCPP)
target_link_libraries(Lab2CPP LibraryCPP)

add_test(NAME TestLab2_1 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input1.txt)
set_property(TEST TestLab2_1 PROPERTY PASS_REGULAR_EXPRESSION "9")

add_test(NAME TestLab2_2 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input2.txt)
set_property(TEST TestLab2_2 PROPERTY PASS_REGULAR_EXPRESSION "3")

add_test(NAME TestLab2_3 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input3.txt)
set_property(TEST TestLab2_3 PROPERTY PASS_REGULAR_EXPRESSION "1")

add_test(NAME TestLab2_4 COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input4.txt)
set_property(TEST TestLab2_4 PROPERTY PASS_REGULAR_EXPRESSION "14")

add_test(NAME TestLab2_Invalid COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input_invalid.txt)
set_property(TEST TestLab2_Invalid PROPERTY PASS_REGULAR_EXPRESSION "Invalid expression")
1 change: 1 addition & 0 deletions Lab2CPP/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 + 3 *
1 change: 1 addition & 0 deletions Lab2CPP/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 + 3 *
1 change: 1 addition & 0 deletions Lab2CPP/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 10 9 - +
1 change: 1 addition & 0 deletions Lab2CPP/input3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 5 /
1 change: 1 addition & 0 deletions Lab2CPP/input4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3 4 + 2 *
1 change: 1 addition & 0 deletions Lab2CPP/input_invalid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +
77 changes: 77 additions & 0 deletions Lab2CPP/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "stack.h"

Check failure on line 1 in Lab2CPP/main.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Lab2CPP/main.cpp:1:10 [clang-diagnostic-error]

'stack.h' file not found
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
string input_filename = (argc > 1) ? argv[1] : "input.txt";
ifstream input(input_filename);
if (!input.is_open()) {
cerr << "Cannot open " << input_filename << endl;
return 1;
}

string line;
if (!getline(input, line)) {
cerr << "Empty input file" << endl;
return 1;
}

istringstream iss(line);
Stack* stk = stack_create();
string token;

while (iss >> token) {
if (token == "+" || token == "-" || token == "*" || token == "/") {

if (stack_empty(stk)) {
cerr << "Invalid expression" << endl; //минимум один элемент перед a (вторым элементом; aka 1 2 +, - > b=1 - >...
stack_delete(stk);
return 1;
}
Data b = stack_get(stk);
stack_pop(stk);
if (stack_empty(stk)) {
cerr << "Invalid expression" << endl; // стек пуст после b (второй операнд) - > элементов (<2) - > ошибка
stack_delete(stk);
return 1;
}
Data a = stack_get(stk);
stack_pop(stk); //...- > a=1, b=2)
Data res = 0;
if (token == "+") res = a + b;
else if (token == "-") res = a - b;
else if (token == "*") res = a * b;
else if (token == "/") {
if (b == 0) {
cerr << "Division by zero" << endl;
stack_delete(stk);
return 1;
}
res = a / b;
}
stack_push(stk, res);
} else {
try {
Data num = stoi(token);
stack_push(stk, num);
} catch (...) {
cerr << "Invalid number: " << token << endl;
stack_delete(stk);
return 1;
}
}
}

if (stack_empty(stk)) {
cerr << "Empty expression" << endl;
} else {
cout << stack_get(stk) << endl;
}

stack_delete(stk);
return 0;
}
59 changes: 59 additions & 0 deletions Lab3CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
add_executable(Lab3CPP main.cpp)
target_include_directories(Lab3CPP PRIVATE ../LibraryCPP)
target_link_libraries(Lab3CPP LibraryCPP)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input.txt ${CMAKE_CURRENT_BINARY_DIR}/input.txt COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input1.txt ${CMAKE_CURRENT_BINARY_DIR}/input1.txt COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input2.txt ${CMAKE_CURRENT_BINARY_DIR}/input2.txt COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input3.txt ${CMAKE_CURRENT_BINARY_DIR}/input3.txt COPYONLY)

enable_testing()

############################
add_test(NAME TestLab3 COMMAND ${CMAKE_COMMAND} -E echo "Running TestLab3")
set_tests_properties(TestLab3 PROPERTIES FIXTURES_SETUP TestLab3Fixture)

add_test(NAME TestLab3_Run COMMAND $<TARGET_FILE:Lab3CPP> ${CMAKE_CURRENT_SOURCE_DIR}/input.txt)
set_tests_properties(TestLab3_Run PROPERTIES FIXTURES_REQUIRED TestLab3Fixture)
set_property(TEST TestLab3_Run PROPERTY ENVIRONMENT "TEST_OUTPUT=${CMAKE_CURRENT_BINARY_DIR}/testlab3_output.txt")
set_property(TEST TestLab3_Run PROPERTY PASS_REGULAR_EXPRESSION ".*")

add_test(NAME TestLab3_Verify COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/testlab3_output.txt
${CMAKE_CURRENT_SOURCE_DIR}/expected_testlab3.txt
)
set_tests_properties(TestLab3_Verify PROPERTIES FIXTURES_CLEANUP TestLab3Fixture DEPENDS TestLab3_Run)

########################
add_test(NAME TestLab3_1 COMMAND ${CMAKE_COMMAND} -E echo "Running TestLab3_1")
set_tests_properties(TestLab3_1 PROPERTIES FIXTURES_SETUP TestLab3_1Fixture)

add_test(NAME TestLab3_1_Run COMMAND $<TARGET_FILE:Lab3CPP> ${CMAKE_CURRENT_SOURCE_DIR}/input1.txt)
set_tests_properties(TestLab3_1_Run PROPERTIES FIXTURES_REQUIRED TestLab3_1Fixture)
set_property(TEST TestLab3_1_Run PROPERTY ENVIRONMENT "TEST_OUTPUT=${CMAKE_CURRENT_BINARY_DIR}/testlab3_1_output.txt")
set_property(TEST TestLab3_1_Run PROPERTY PASS_REGULAR_EXPRESSION ".*")

add_test(NAME TestLab3_1_Verify COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/testlab3_1_output.txt
${CMAKE_CURRENT_SOURCE_DIR}/expected_testlab3_1.txt
)
set_tests_properties(TestLab3_1_Verify PROPERTIES FIXTURES_CLEANUP TestLab3_1Fixture DEPENDS TestLab3_1_Run)

##########################
add_test(NAME TestLab3_2 COMMAND ${CMAKE_COMMAND} -E echo "Running TestLab3_2")
set_tests_properties(TestLab3_2 PROPERTIES FIXTURES_SETUP TestLab3_2Fixture)

add_test(NAME TestLab3_2_Run COMMAND $<TARGET_FILE:Lab3CPP> ${CMAKE_CURRENT_SOURCE_DIR}/input2.txt)
set_tests_properties(TestLab3_2_Run PROPERTIES FIXTURES_REQUIRED TestLab3_2Fixture)
set_property(TEST TestLab3_2_Run PROPERTY ENVIRONMENT "TEST_OUTPUT=${CMAKE_CURRENT_BINARY_DIR}/testlab3_2_output.txt")
set_property(TEST TestLab3_2_Run PROPERTY PASS_REGULAR_EXPRESSION ".*")

add_test(NAME TestLab3_2_Verify COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/testlab3_2_output.txt
${CMAKE_CURRENT_SOURCE_DIR}/expected_testlab3_2.txt
)
set_tests_properties(TestLab3_2_Verify PROPERTIES FIXTURES_CLEANUP TestLab3_2Fixture DEPENDS TestLab3_2_Run)

###################
add_test(NAME TestLab3_3 COMMAND $<TARGET_FILE:Lab3CPP> ${CMAKE_CURRENT_SOURCE_DIR}/input3.txt)
set_property(TEST TestLab3_3 PROPERTY PASS_REGULAR_EXPRESSION "^-1\n$")
16 changes: 16 additions & 0 deletions Lab3CPP/expected_testlab3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
7
Path: (0,0) -> (0,1) -> (0,2) -> (0,3) -> (0,4) -> (1,4) -> (1,5) -> (2,5)
Maze with path:
/ \ / \ / \ / \ / \ / \
| S | . | # | . | . | . |
\ / \ / \ / \ / \ / \ /
| x | # | . | E | . | . |
\ / \ / \ / \ / \ / \ /
| x | . | # | . | . | . |
\ / \ / \ / \ / \ / \ /
| x | # | . | . | # | . |
\ / \ / \ / \ / \ / \ /
| x | x | . | # | . | . |
\ / \ / \ / \ / \ / \ /
| # | x | E | . | . | . |

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут шаг по диагонали, который не был предусмотрен правилами.

\ / \ / \ / \ / \ / \ /
8 changes: 8 additions & 0 deletions Lab3CPP/expected_testlab3_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
2
Path: (0,0) -> (1,0) -> (2,0)
Maze with path:
/ \ / \ / \
| S | x | E |
\ / \ / \ /
| . | . | . |
\ / \ / \ /
12 changes: 12 additions & 0 deletions Lab3CPP/expected_testlab3_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
6
Path: (0,0) -> (0,1) -> (0,2) -> (0,3) -> (1,3) -> (2,3) -> (3,3)
Maze with path:
/ \ / \ / \ / \
| S | . | . | . |
\ / \ / \ / \ /
| x | # | . | . |
\ / \ / \ / \ /
| x | . | # | . |
\ / \ / \ / \ /
| x | x | x | E |
\ / \ / \ / \ /
6 changes: 6 additions & 0 deletions Lab3CPP/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
S.#...
.#.E..
..#...
.#..#.
...#..
#.E...
2 changes: 2 additions & 0 deletions Lab3CPP/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
S.E
...
Loading