Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
43 changes: 2 additions & 41 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
build
.cache
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"C_Cpp.intelliSenseEngine": "disabled",
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build"
]
}
32 changes: 32 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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": []
}
]
}
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions lab1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions lab1/LABOOP.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": ".."
}
]
}
4 changes: 4 additions & 0 deletions lab1/include/solution.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include <string>

bool is_clean_number(const std::string& input_raw);
18 changes: 18 additions & 0 deletions lab1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include <string>
#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;
}
25 changes: 25 additions & 0 deletions lab1/src/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "solution.hpp"
#include <cctype>
#include <string>

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;
}
25 changes: 25 additions & 0 deletions lab1/tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <gtest/gtest.h>
#include <solution.hpp>

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();
}