feat(EditorConfig): Add .editorconfig files

This commit is contained in:
Jiří Štefka 2023-12-10 01:25:53 +01:00
parent 1f8dce3a86
commit 96477dfba3
Signed by: jiriks74
GPG key ID: 1D5E30D3DB2264DE
12 changed files with 400 additions and 0 deletions

13
.editorconfig Normal file
View file

@ -0,0 +1,13 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Every file
[*]
# Unix-style newlines with a newline ending every file
end_of_line = lf
# Remove any trailing whitespace characters
trim_trailing_whitespace = true
# Ensure every file ends with a newline
insert_final_newline = true

14
01/.editorconfig Normal file
View 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

74
01/.gitignore vendored Normal file
View file

@ -0,0 +1,74 @@
# 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/
lib/
bin/
*.swp

52
01/CMakeLists.txt Normal file
View file

@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.14)
# Generate compile_commands.json
set(PROJECT_NAME 01)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Turn on testing by default
option(BUILD_TESTING "Build tests" ON)
# 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 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)
# After a normal build, we can specify the location of various outputs of the
# build. We put executables and static libraries outside the build directory in
# bin/ and lib/, respectively.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
# 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)

47
01/README.md Normal file
View file

@ -0,0 +1,47 @@
# [Day 1](https://adventofcode.com/2023/day/1)
## Assignment
### Day 1: Trebuchet?!
Something is wrong with global snow production,
and you've been selected to take a look.
The Elves have even given you a map; on it,
they've used stars to mark the top fifty locations that are likely to be having problems.
You've been doing this long enough to know that to restore snow operations,
you need to check all fifty stars by December 25th.
Collect stars by solving puzzles.
Two puzzles will be made available on each day in the Advent calendar;
the second puzzle is unlocked when you complete the first.
Each puzzle grants one star. Good luck!
You try to ask why they can't just use a weather machine ("not powerful enough")
and where they're even sending you ("the sky") and why your map looks mostly blank
("you sure ask a lot of questions") and hang on did you just say the sky
("of course, where do you think snow comes from") when you realize
that the Elves are already loading you into a trebuchet
("please hold still, we need to strap you in").
As they're making the final adjustments,
they discover that their calibration document (your puzzle input)
has been amended by a very young Elf who was apparently just excited to show off
her art skills.
Consequently, the Elves are having trouble reading the values on the document.
The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
For example:
```
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
```
In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.
Consider your entire calibration document. What is the sum of all of the calibration values?

16
01/include/CMakeLists.txt Normal file
View 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)

17
01/src/CMakeLists.txt Normal file
View 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
01/src/main.c Normal file
View 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;
}

80
01/tests/CMakeLists.txt Normal file
View file

@ -0,0 +1,80 @@
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 ${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
)
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()

View 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
01/tests/src/test.cpp Normal file
View 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);
}

14
C_Tempate/.editorconfig Normal file
View 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