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
32 changes: 32 additions & 0 deletions .github/workflows/homework_1_task_01.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CMake

on:
push: {}
pull_request:
branches: [ "main" ]

env:
BUILD_TYPE: Release

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- name: Install gtest manually
run: sudo apt-get install libgtest-dev

- uses: actions/checkout@v3

- name: run cmake
working-directory: ${{github.workspace}}/homework_01
run: cmake -B./build .

- name: make
working-directory: ${{github.workspace}}/homework_01/build
run: make

- name: tests
working-directory: ${{github.workspace}}/homework_01/build
run: ./task_01/tests_1_01

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install gtest manually
run: sudo apt-get install libgtest-dev

- uses: actions/checkout@v3

- name: run cmake
Expand All @@ -23,11 +26,7 @@ jobs:
working-directory: ${{github.workspace}}/homework_01/build
run: make

- name: test task 01
working-directory: ${{github.workspace}}/homework_01/build
run: ./task_01/tests_01

- name: test task 02
- name: tests
working-directory: ${{github.workspace}}/homework_01/build
run: ./task_02/tests_02
run: ./task_02/tests_1_02

3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ cmake_minimum_required(VERSION 3.10)

project(homeworks)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/homework_01)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/homework_01)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/homework_02)
22 changes: 13 additions & 9 deletions homework_01/task_01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

set(PROJECT_NAME task_01)
set(PROJECT_NAME task_1_01)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 20)
Expand All @@ -18,15 +18,19 @@ include_directories(${PROJECT_NAME} PUBLIC src)

add_executable(${PROJECT_NAME} ${source_list})

Include(FetchContent)
# Locate GTest
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.1.0
# Link runTests with what we want to test and the GTest and pthread library
add_executable(tests_1_01 ${test_source_list})
target_link_libraries(
tests_1_01
GTest::gtest_main
)

FetchContent_MakeAvailable(Catch2)
include(GoogleTest)
gtest_discover_tests(tests_1_01)

add_executable(tests_01 ${test_source_list})
target_link_libraries(tests_01 PRIVATE Catch2::Catch2WithMain)
# target_link_libraries(tests_1_02 ${GTEST_LIBRARIES} pthread)
24 changes: 13 additions & 11 deletions homework_01/task_01/src/split_string_test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include <catch2/catch_test_macros.hpp>
#include <gtest/gtest.h>

#include "utils.hpp"

TEST_CASE("SplitString", "[simple]") {
CHECK(SplitString("") == std::vector<std::string>{});
CHECK(SplitString("aaa") == std::vector<std::string>{"aaa"});
CHECK(SplitString("aaa aaa") == std::vector<std::string>{"aaa", "aaa"});
CHECK(SplitString("aaa aaa ") == std::vector<std::string>{"aaa", "aaa"});
CHECK(SplitString(" ") == std::vector<std::string>{});
CHECK(SplitString("??? ??") == std::vector<std::string>{"???", "??"});
CHECK(SplitString("a\na\ta a") == std::vector<std::string>{"a\na", "a", "a"});
CHECK(SplitString("a (a a)") == std::vector<std::string>{"a", "(a a)"});
CHECK(SplitString("a (a a) b (asd as) ") == std::vector<std::string>{"a", "(a a)", "b", "(asd as)"});
TEST(SplitStringTest, Simple) {
ASSERT_EQ(SplitString(""), std::vector<std::string>{});
ASSERT_EQ(SplitString("aaa"), std::vector<std::string>{"aaa"});
ASSERT_EQ(SplitString("aaa aaa"), (std::vector<std::string>{"aaa", "aaa"}));
ASSERT_EQ(SplitString("aaa aaa "), (std::vector<std::string>{"aaa", "aaa"}));
ASSERT_EQ(SplitString(" "), std::vector<std::string>{});
ASSERT_EQ(SplitString("??? ??"), (std::vector<std::string>{"???", "??"}));
ASSERT_EQ(SplitString("a\na\ta a"),
(std::vector<std::string>{"a\na", "a", "a"}));
ASSERT_EQ(SplitString("a (a a)"), (std::vector<std::string>{"a", "(a a)"}));
ASSERT_EQ(SplitString("a (a a) b (asd as) "),
(std::vector<std::string>{"a", "(a a)", "b", "(asd as)"}));
}
1 change: 0 additions & 1 deletion homework_01/task_01/src/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <string>
#include <string_view>
#include <vector>

std::vector<std::string> SplitString(const std::string& data);
24 changes: 14 additions & 10 deletions homework_01/task_02/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.10)

set(PROJECT_NAME task_02)
set(PROJECT_NAME task_1_02)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp")
Expand All @@ -18,15 +18,19 @@ include_directories(${PROJECT_NAME} PUBLIC src)

add_executable(${PROJECT_NAME} ${source_list})

Include(FetchContent)
# Locate GTest
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.1.0
# Link runTests with what we want to test and the GTest and pthread library
add_executable(tests_1_02 ${test_source_list})
target_link_libraries(
tests_1_02
GTest::gtest_main
)

FetchContent_MakeAvailable(Catch2)
include(GoogleTest)
gtest_discover_tests(tests_1_02)

add_executable(tests_02 ${test_source_list})
target_link_libraries(tests_02 PRIVATE Catch2::Catch2WithMain)
# target_link_libraries(tests_1_02 ${GTEST_LIBRARIES} pthread)
32 changes: 16 additions & 16 deletions homework_01/task_02/src/calculate_test.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include <catch2/catch_test_macros.hpp>
#include <gtest/gtest.h>

#include "utils.hpp"

TEST_CASE("Calculate", "[simple_sum]") {
CHECK(Calculate("1+2") == 3);
CHECK(Calculate("2+2") == 4);
CHECK(Calculate("1+0") == 1);
CHECK(Calculate("0+0") == 0);
TEST(CalculateTest, simple_sum) {
ASSERT_EQ(Calculate("1+2"), 3);
ASSERT_EQ(Calculate("2+2"), 4);
ASSERT_EQ(Calculate("1+0"), 1);
ASSERT_EQ(Calculate("0+0"), 0);
}

TEST_CASE("Calculate", "[simple_difference]") {
CHECK(Calculate("5-2") == 3);
CHECK(Calculate("2-2") == 0);
CHECK(Calculate("1-0") == 1);
CHECK(Calculate("0-0") == 0);
TEST(CalculateTest, simple_difference) {
ASSERT_EQ(Calculate("5-2"), 3);
ASSERT_EQ(Calculate("2-2"), 0);
ASSERT_EQ(Calculate("1-0"), 1);
ASSERT_EQ(Calculate("0-0"), 0);
}

TEST_CASE("Calculate", "[simple_multiply]") {
CHECK(Calculate("5*2") == 10);
CHECK(Calculate("2*2") == 4);
CHECK(Calculate("1*0") == 0);
CHECK(Calculate("0*0") == 0);
TEST(CalculateTest, simple_multiply) {
ASSERT_EQ(Calculate("5*2"), 10);
ASSERT_EQ(Calculate("2*2"), 4);
ASSERT_EQ(Calculate("1*0"), 0);
ASSERT_EQ(Calculate("0*0"), 0);
}
5 changes: 5 additions & 0 deletions homework_02/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.10)

project(homework_02)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/task_2_01)
36 changes: 36 additions & 0 deletions homework_02/task_2_01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.10)

set(PROJECT_NAME task_2_01)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp")
file(GLOB_RECURSE main_source_list "src/main.cpp")
file(GLOB_RECURSE test_source_list "src/*.cpp")
file(GLOB_RECURSE test_list "src/*test.cpp")

list(REMOVE_ITEM test_source_list ${main_source_list})
list(REMOVE_ITEM source_list ${test_list})

include_directories(${PROJECT_NAME} PUBLIC src)

add_executable(${PROJECT_NAME} ${source_list})

# Locate GTest
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# Link runTests with what we want to test and the GTest and pthread library
add_executable(tests_2_01 ${test_source_list})
target_link_libraries(
tests_2_01
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(tests_2_01)

# target_link_libraries(tests_2_01 ${GTEST_LIBRARIES} pthread)
3 changes: 3 additions & 0 deletions homework_02/task_2_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <utils.hpp>

int main() { return 0; }
6 changes: 6 additions & 0 deletions homework_02/task_2_01/src/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <gtest/gtest.h>

#include "utils.hpp"

TEST(HelloTest, BasicAssertions) {
ASSERT_EQ(true, true); }
3 changes: 3 additions & 0 deletions homework_02/task_2_01/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "utils.hpp"

double Calculate(const std::string& str) { return 0; }
5 changes: 5 additions & 0 deletions homework_02/task_2_01/src/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <string>

double Calculate(const std::string& str);