Compare commits
2 Commits
ec366013bb
...
76d836691b
Author | SHA1 | Date | |
---|---|---|---|
76d836691b | |||
83c618f861 |
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright [2023] Jiří Štefka <jiriks74>
|
||||
* Copyright [2024] Jiří Štefka <jiriks74>
|
||||
* Project: AdventOfCode
|
||||
* @file main.c
|
||||
* @brief Main entry point
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define INC_CHUNK = 64
|
||||
|
||||
@ -75,6 +76,8 @@ int main(int argc, char *argv[])
|
||||
if (getline(&buffer, &bufferSize, file) == -1)
|
||||
break;
|
||||
|
||||
if(strcmp(buffer, "")) continue;
|
||||
|
||||
sscanf(buffer, "%d %d", &array1[i], &array2[i]);
|
||||
}
|
||||
|
||||
|
14
02/.editorconfig
Normal file
14
02/.editorconfig
Normal file
@ -0,0 +1,14 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# Project files
|
||||
# Matches multiple files with brace expansion notation
|
||||
[*.{c,h,cc}]
|
||||
|
||||
# Set charset
|
||||
charset = utf-8
|
||||
max_line_length = 80
|
||||
|
||||
# 2 space indentation
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
82
02/.gitignore
vendored
Normal file
82
02/.gitignore
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
# ClangD
|
||||
.cache
|
||||
|
||||
# Nix files
|
||||
.direnv
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# Vscode
|
||||
.vscode/
|
||||
|
||||
# CMake
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
.cache/
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
build/
|
||||
output/
|
||||
|
||||
lib/
|
||||
bin/
|
||||
*.swp
|
||||
|
52
02/CMakeLists.txt
Normal file
52
02/CMakeLists.txt
Normal file
@ -0,0 +1,52 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
# Generate compile_commands.json
|
||||
set(PROJECT_NAME 02)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# Turn on testing by default
|
||||
option(BUILD_TESTING "Build tests" ON)
|
||||
# Turn off documentation build by default
|
||||
option(BUILD_DOC "Build documentation" OFF)
|
||||
# Turn off coverage by default
|
||||
option(ENABLE_COVERAGE "Enable test coverage" ON)
|
||||
|
||||
# Set C standard to C99
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-std=c99 -Wall -Wextra -Wunreachable-code -g -O0")
|
||||
|
||||
# Set the project name and version number. This allows for a user of your
|
||||
project(${PROJECT_NAME} VERSION 0.1)
|
||||
set(${PROJECT_NAME} 0.1)
|
||||
|
||||
# Function to prepend the subdirectory to source files in subdirectories
|
||||
FUNCTION(PREPEND var )
|
||||
SET(listVar "")
|
||||
FOREACH(f ${${var}})
|
||||
LIST(APPEND listVar "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
|
||||
ENDFOREACH(f)
|
||||
SET(${var} "${listVar}" PARENT_SCOPE)
|
||||
ENDFUNCTION(PREPEND)
|
||||
|
||||
# Include source code and headers. This calls the CMakeLists.txt in each
|
||||
# subdirectory. These can define their own libraries, executables, etc. as targets,
|
||||
# but here we define all exportable targets in the root CMakeLists.txt.
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(include)
|
||||
|
||||
# enable unit testing via "make test" once the code has been compiled.
|
||||
# TODO: Google Test
|
||||
|
||||
if(BUILD_TESTING)
|
||||
message("Testing enabled")
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
target_include_directories(tests PRIVATE include)
|
||||
endif()
|
||||
|
||||
# Add PROJECT_NAME as an executable target.
|
||||
add_executable(${PROJECT_NAME} ${SRC} ${INC})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||
|
||||
if(BUILD_DOC)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
20
02/docs/CMakeLists.txt
Normal file
20
02/docs/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# check if Doxygen is installed
|
||||
find_package(Doxygen)
|
||||
if (DOXYGEN_FOUND)
|
||||
# set input and output files
|
||||
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile)
|
||||
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
|
||||
# request to configure the file
|
||||
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
|
||||
message("Doxygen build started")
|
||||
|
||||
# note the option ALL which allows to build the docs together with the application
|
||||
add_custom_target(doc ALL
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating documentation with Doxygen"
|
||||
VERBATIM )
|
||||
else (DOXYGEN_FOUND)
|
||||
message("Doxygen needs to be installed to generate the documentation")
|
||||
endif (DOXYGEN_FOUND)
|
2826
02/docs/Doxyfile
Normal file
2826
02/docs/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
16
02/include/CMakeLists.txt
Normal file
16
02/include/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
# Make an explicit list of all source files in IFJ23_INC. This is important
|
||||
# because CMake is not a build system: it is a build system generator. Suppose
|
||||
# you add a file foo.cpp to src/ after running cmake .. . If you set
|
||||
# IFJ23_INC with `file(GLOB ... )`, this is not passed to the makefile; it
|
||||
# doesn't know that foo.cpp exists and will not re-run cmake. Your
|
||||
# collaborator's builds will fail and it will be unclear why. Whether you use
|
||||
# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit
|
||||
# file list, you know beforehand why your code isn't compiling.
|
||||
set(INC
|
||||
)
|
||||
|
||||
# Form the full path to the source files...
|
||||
PREPEND(INC)
|
||||
# ... and pass the variable to the parent scope.
|
||||
set(INC ${INC} PARENT_SCOPE)
|
1000
02/puzzle.input
Normal file
1000
02/puzzle.input
Normal file
File diff suppressed because it is too large
Load Diff
17
02/src/CMakeLists.txt
Normal file
17
02/src/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
# Make an explicit list of all source files in `CMakeDemo_SRC`. This is important
|
||||
# because CMake is not a build system: it is a build system generator. Suppose
|
||||
# you add a file foo.cpp to src/ after running cmake .. . If you set
|
||||
# `CMakeDemo_SRC` with `file(GLOB ... )`, this is not passed to the makefile;
|
||||
# the makefile doesn't know that foo.cpp exists and will not re-run cmake. Your
|
||||
# collaborator's builds will fail and it will be unclear why. Whether you use
|
||||
# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit
|
||||
# file list, you know beforehand why your code isn't compiling.
|
||||
set(SRC
|
||||
main.c
|
||||
)
|
||||
|
||||
# Form the full path to the source files...
|
||||
PREPEND(SRC)
|
||||
# ... and pass the variable to the parent scope.
|
||||
set(SRC ${SRC} PARENT_SCOPE)
|
25
02/src/main.c
Normal file
25
02/src/main.c
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright [2023] Jiří Štefka <jiriks74>
|
||||
* Project: AdventOfCode
|
||||
* @file main.c
|
||||
* @brief Main entry point
|
||||
* @author jiriks74
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* @brief Main entry point
|
||||
* @param argc Number of command-line arguments.
|
||||
* @param argv Array of command-line arguments.
|
||||
*/
|
||||
#ifndef TESTING
|
||||
int main(int argc, char *argv[])
|
||||
#endif
|
||||
#ifdef TESTING
|
||||
int main_test(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
6
02/test.input
Normal file
6
02/test.input
Normal file
@ -0,0 +1,6 @@
|
||||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
83
02/tests/CMakeLists.txt
Normal file
83
02/tests/CMakeLists.txt
Normal file
@ -0,0 +1,83 @@
|
||||
set(PROJECT_NAME ${PROJECT_NAME} PARENT_SCOPE )
|
||||
# GoogleTest requires at least C++14
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Get GoogleTest
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_executable(tests ${TESTS})
|
||||
|
||||
# Link test executable against gtest & gtest_main
|
||||
target_link_libraries(
|
||||
tests
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(tests PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
# Discover tests
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(tests)
|
||||
add_dependencies(tests ${PROJECT_NAME})
|
||||
|
||||
# The following section is inspired by https://github.com/cmake-modules/lcov
|
||||
if(ENABLE_COVERAGE)
|
||||
message("Test coverage enabled")
|
||||
# set(exclude_dir "*/tests/* */_deps/* /usr/include/c++/11/**/* /usr/include/c++/**/*")
|
||||
# set(exclude_dir "*/tests/* */_deps/* /usr/include/c++/11/tuple /usr/include/c++/11/**/*")
|
||||
|
||||
# Check for lcov, gcov and genhtml
|
||||
find_program(GCOV gcov)
|
||||
if (NOT GCOV)
|
||||
message(WARNING "gcov not found")
|
||||
endif()
|
||||
find_program(LCOV lcov)
|
||||
if (NOT LCOV)
|
||||
message(WARNING "lcov not found")
|
||||
endif()
|
||||
find_program(GENHTML genhtml)
|
||||
if (NOT GENHTML)
|
||||
message(WARNING "genhtml not found")
|
||||
endif()
|
||||
|
||||
if (GCOV AND LCOV AND GENHTML)
|
||||
# Set C compiler flags
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
|
||||
# Set C++ compiler flags
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
|
||||
|
||||
set(covname cov.info)
|
||||
add_custom_target(coverage DEPENDS ${covname})
|
||||
add_dependencies(coverage tests ${PROJECT_NAME})
|
||||
add_custom_command(
|
||||
OUTPUT ${covname}
|
||||
COMMAND rm -rf **/coverage
|
||||
COMMAND ${LCOV} -c -o ${covname} -d ${CMAKE_BINARY_DIR}/tests/CMakeFiles/tests.dir/ -b . --gcov-tool ${GCOV}
|
||||
COMMAND ${LCOV} -r ${covname} -o ${covname} "*/tests/*" "*/_deps/**/*" "/usr/include/c++/**/*" "/usr/include/c++/11/**/*"
|
||||
COMMAND ${LCOV} -l ${covname}
|
||||
COMMAND ${GENHTML} ${covname} -output coverage
|
||||
COMMAND ${LCOV} -l ${covname} 2>/dev/null | grep Total | sed 's/|//g' | sed 's/Total://g' | awk '{print $1}' | sed s/%//g > coverage/total
|
||||
COMMAND rm -rf CMakeFiles/tests.dir/src/*.gcda CMakeFiles/tests.dir/src/*.gcno
|
||||
COMMAND rm -f ${covname}
|
||||
)
|
||||
set_directory_properties(PROPERTIES
|
||||
ADDITIONAL_CLEAN_FILES ${covname}
|
||||
)
|
||||
set_directory_properties(PROPERTIES
|
||||
ADDITIONAL_CLEAN_FILES coverage/
|
||||
)
|
||||
else()
|
||||
message(WARNING "Cannot enable coverage. Missing the required tools")
|
||||
endif()
|
||||
endif()
|
17
02/tests/src/CMakeLists.txt
Normal file
17
02/tests/src/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
# Make an explicit list of all source files in `IFJ23_TESTS`. This is important
|
||||
# because CMake is not a build system: it is a build system generator. Suppose
|
||||
# you add a file foo.cpp to src/ after running cmake .. . If you set
|
||||
# `IFJ23_TESTS` with `file(GLOB ... )`, this is not passed to the makefile;
|
||||
# the makefile doesn't know that foo.cpp exists and will not re-run cmake. Your
|
||||
# collaborator's builds will fail and it will be unclear why. Whether you use
|
||||
# file(GLOB ...) or not, you will need to re-run cmake, but with an explicit
|
||||
# file list, you know beforehand why your code isn't compiling.
|
||||
set(TESTS
|
||||
test.cpp
|
||||
)
|
||||
|
||||
# Form the full path to the source files...
|
||||
PREPEND(TESTS)
|
||||
# ... and pass the variable to the parent scope.
|
||||
set(TESTS ${TESTS} PARENT_SCOPE)
|
31
02/tests/src/test.cpp
Normal file
31
02/tests/src/test.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define TESTING
|
||||
|
||||
// Include the source file(s) to be tested.
|
||||
#include "main.c"
|
||||
|
||||
// Create a test fixture class template - this will be like a "conlection" of
|
||||
// tests. the : public ::testing::Test part is important! Add it to your fixture
|
||||
// class.
|
||||
class HelloTest : public ::testing::Test {
|
||||
HelloTest() {}
|
||||
|
||||
~HelloTest() {}
|
||||
|
||||
void SetUp() {}
|
||||
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
// Add tests to the test fixture class.
|
||||
// @param fixture_class_name The name of the test fixture class.
|
||||
// @param test_name The name of the test.
|
||||
TEST(HelloTest, BasicAssertions) {
|
||||
// Execute the code to be tested.
|
||||
// Expect two strings not to be equal.
|
||||
EXPECT_STRNE("hello", "world");
|
||||
// Expect equality.
|
||||
EXPECT_EQ(7 * 6, 42);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright [2023] Jiří Štefka <jiriks74>
|
||||
* Copyright [2024] Jiří Štefka <jiriks74>
|
||||
* Project: AdventOfCode
|
||||
* @file main.c
|
||||
* @brief Main entry point
|
||||
|
Loading…
x
Reference in New Issue
Block a user