From 1944945e4b170acf7cc033ddefe84aaba2d9ee37 Mon Sep 17 00:00:00 2001 From: IVANGMAI Date: Fri, 26 Sep 2025 20:33:06 +0300 Subject: [PATCH] Complete lab 1 --- .devcontainer/Dockerfile | 11 +++++++++ .devcontainer/devcontainer.json | 16 ++++++++++++ .gitignore | 43 ++------------------------------- .vscode/launch.json | 19 +++++++++++++++ .vscode/settings.json | 6 +++++ .vscode/tasks.json | 32 ++++++++++++++++++++++++ CMakeLists.txt | 7 ++++++ lab1/CMakeLists.txt | 34 ++++++++++++++++++++++++++ lab1/LABOOP.code-workspace | 7 ++++++ lab1/include/solution.hpp | 4 +++ lab1/main.cpp | 18 ++++++++++++++ lab1/src/solution.cpp | 25 +++++++++++++++++++ lab1/tests/tests.cpp | 25 +++++++++++++++++++ 13 files changed, 206 insertions(+), 41 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 lab1/CMakeLists.txt create mode 100644 lab1/LABOOP.code-workspace create mode 100644 lab1/include/solution.hpp create mode 100644 lab1/main.cpp create mode 100644 lab1/src/solution.cpp create mode 100644 lab1/tests/tests.cpp diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..6776ecd --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,11 @@ +FROM gcc:14 + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + cmake git build-essential gdb libgtest-dev tree\ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /workspace + +CMD ["bash"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..914e39e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,16 @@ +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + "customizations": { + "vscode": { + "extensions": [ + "llvm-vs-code-extensions.vscode-clangd", + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "DavidAnson.vscode-markdownlint" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 91b645d..d835f77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,41 +1,2 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Linker files -*.ilk - -# Debugger Files -*.pdb - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# debug information files -*.dwo \ No newline at end of file +build +.cache \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..cc0fbff --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch LABOOOP (GDB)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/${fileDirnameBasename}/${fileDirnameBasename}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb", + "preLaunchTask": "CMake Build" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7db248f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "C_Cpp.intelliSenseEngine": "disabled", + "clangd.arguments": [ + "--compile-commands-dir=${workspaceFolder}/build" + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ec353c8 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,32 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "CMake Configure", + "type": "shell", + "command": "cmake", + "args": [ + "-S", ".", + "-B", "build", + "-DCMAKE_C_COMPILER=gcc-14", + "-DCMAKE_CXX_COMPILER=g++-14", + "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" + ], + "problemMatcher": [] + }, + { + "label": "CMake Build", + "type": "shell", + "command": "cmake", + "args": [ + "--build", "build" + ], + "dependsOn": ["CMake Configure"], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..341fd76 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.10.0) +project(LABOOOP VERSION 0.1.0 LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_subdirectory(lab1) diff --git a/lab1/CMakeLists.txt b/lab1/CMakeLists.txt new file mode 100644 index 0000000..8713718 --- /dev/null +++ b/lab1/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.10.0) +project(lab1 VERSION 0.1.0 LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include_directories(include) + +add_executable(lab1 + main.cpp + src/solution.cpp +) + +include(FetchContent) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.15.0 + TLS_VERIFY false +) + +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(run_tests + tests/tests.cpp + src/solution.cpp +) + +target_link_libraries(run_tests GTest::gtest_main) + +include(GoogleTest) +gtest_discover_tests(run_tests) \ No newline at end of file diff --git a/lab1/LABOOP.code-workspace b/lab1/LABOOP.code-workspace new file mode 100644 index 0000000..2a0ed79 --- /dev/null +++ b/lab1/LABOOP.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": ".." + } + ] +} \ No newline at end of file diff --git a/lab1/include/solution.hpp b/lab1/include/solution.hpp new file mode 100644 index 0000000..507e6f4 --- /dev/null +++ b/lab1/include/solution.hpp @@ -0,0 +1,4 @@ +#pragma once +#include + +bool is_clean_number(const std::string& input_raw); \ No newline at end of file diff --git a/lab1/main.cpp b/lab1/main.cpp new file mode 100644 index 0000000..8c2033b --- /dev/null +++ b/lab1/main.cpp @@ -0,0 +1,18 @@ +#include +#include +#include "solution.hpp" + +using namespace std; + +int main() { + string input; + cin >> input; + + if (is_clean_number(input)) { + cout << "Result is 1\n"; + } else { + cout << "Result is 0\n"; + } + + return 0; +} diff --git a/lab1/src/solution.cpp b/lab1/src/solution.cpp new file mode 100644 index 0000000..10d0ac2 --- /dev/null +++ b/lab1/src/solution.cpp @@ -0,0 +1,25 @@ +#include "solution.hpp" +#include +#include + +bool is_clean_number(const std::string& input_raw) { + std::string input = input_raw; + + if (input_raw.empty()) { + return false; + } + if (input_raw[0] == '0') return false; + if (input_raw[0] == '-') input[0] = '0'; + for (char c : input) { + if (!isdigit(c)) { + return false; + } + } + for (size_t i = 1; i + 1 < input.size(); ++i) { + if (input[i] > input[i + 1]) { + return false; + } + + } + return true; +} diff --git a/lab1/tests/tests.cpp b/lab1/tests/tests.cpp new file mode 100644 index 0000000..10b4d0e --- /dev/null +++ b/lab1/tests/tests.cpp @@ -0,0 +1,25 @@ +#include +#include + +TEST(CleanNumberTest, PositiveCases) { + EXPECT_TRUE(is_clean_number("123")); + EXPECT_TRUE(is_clean_number("000")); + EXPECT_TRUE(is_clean_number("112233")); +} + +TEST(CleanNumberTest, NegativeCases) { + EXPECT_FALSE(is_clean_number("321")); + EXPECT_FALSE(is_clean_number("132")); + EXPECT_FALSE(is_clean_number("12a3")); + EXPECT_FALSE(is_clean_number("")); +} + +TEST(CleanNumberTest, NegativeNumbers) { + EXPECT_TRUE(is_clean_number("-123")); + EXPECT_FALSE(is_clean_number("-321")); +} + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}