Skip to content

Commit

Permalink
c++/luhn: 2nd iteration - c header -> c++ header
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jul 18, 2023
1 parent a6c7a02 commit b8c9ea8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 88 deletions.
6 changes: 3 additions & 3 deletions cpp/luhn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ endif()
# Use the common Catch library?
if(EXERCISM_COMMON_CATCH)
# For Exercism track development only
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp
$<TARGET_OBJECTS:catchlib>)
elseif(EXERCISM_TEST_SUITE)
# The Exercism test suite is being run, the Docker image already includes a
# pre-built version of Catch.
find_package(Catch2 REQUIRED)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp)
target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain)
# When Catch is installed system wide we need to include a different header,
# we need this define to use the correct one.
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
else()
# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp
test/tests-main.cpp)
endif()

Expand Down
8 changes: 1 addition & 7 deletions cpp/luhn/luhn.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#include "luhn.h"
#include <cctype>
#include <iterator>
#include <numeric>
#include <vector>

#include <iostream>
#include "luhn.hpp"

namespace luhn {

Expand Down
23 changes: 0 additions & 23 deletions cpp/luhn/luhn.h

This file was deleted.

23 changes: 23 additions & 0 deletions cpp/luhn/luhn.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !defined(LUHN_HPP)
#define LUHN_HPP

#include <array>
#include <cctype>
#include <iterator>
#include <numeric>
#include <string>
#include <vector>

namespace luhn {

bool valid(std::string number);

bool is_valid_input(std::string sequence);

int sum(std::array<int, 256> numbers);

std::array<int, 256> get_numbers(std::string data);

} // namespace luhn

#endif // LUHN_HPP
2 changes: 1 addition & 1 deletion cpp/luhn/luhn_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "luhn.h"
#include "luhn.hpp"
#ifdef EXERCISM_TEST_SUITE
#include <catch2/catch.hpp>
#else
Expand Down
94 changes: 40 additions & 54 deletions cpp/luhn/run-tests-cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Running automated test file(s):
Running: make clean
rm -rf ./build

real 0m0.012s
user 0m0.000s
sys 0m0.012s
real 0m0.009s
user 0m0.001s
sys 0m0.008s

===============================================================================

Expand Down Expand Up @@ -69,26 +69,26 @@ Directory: .
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
luhn.cpp 36 36 100%
luhn.cpp 37 37 100%
luhn_test.cpp 85 85 100%
test/catch.hpp 31 26 83% 1642-1643,2227,2229,2560
------------------------------------------------------------------------------
TOTAL 152 147 96%
TOTAL 153 148 96%
------------------------------------------------------------------------------
lines: 96.7% (147 out of 152)
lines: 96.7% (148 out of 153)
branches: 42.9% (150 out of 350)

real 0m9.731s
user 0m8.841s
sys 0m0.886s
real 0m9.443s
user 0m8.727s
sys 0m0.700s

===============================================================================

cmake-format --in-place CMakeLists.txt

real 0m0.154s
user 0m0.110s
sys 0m0.045s
real 0m0.141s
user 0m0.103s
sys 0m0.039s

===============================================================================

Expand All @@ -110,64 +110,50 @@ found lint:
Convention: 4


real 0m0.165s
user 0m0.107s
sys 0m0.059s
real 0m0.153s
user 0m0.109s
sys 0m0.045s

===============================================================================

Running: clang-format-16 -style=file -i ./luhn.cpp ./luhn_test.cpp ./luhn.h
Running: clang-format-16 -style=file -i ./luhn.cpp ./luhn_test.cpp

real 0m0.021s
user 0m0.013s
sys 0m0.008s
real 0m0.020s
user 0m0.010s
sys 0m0.010s

===============================================================================

Running: ../../.github/citools/cpp/clang-check
clang-check-16 --analyze ./luhn.cpp ./luhn_test.cpp ./luhn.h
error: argument unused during compilation: '-stdlib=libstdc++' [-Werror,-Wunused-command-line-argument]
error: invalid argument '-std=c++17' not allowed with 'C'
/home/vpayno/git_vpayno/exercism-workspace/cpp/luhn/luhn.h:4:10: fatal error: 'array' file not found
#include <array>
^~~~~~~
1 error generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/luhn/luhn.h.
clang-check-16 --analyze ./luhn.cpp ./luhn_test.cpp ./luhn.hpp

real 0m0.694s
user 0m0.638s
sys 0m0.056s
real 0m0.782s
user 0m0.750s
sys 0m0.032s


real 0m0.696s
user 0m0.640s
sys 0m0.056s
real 0m0.783s
user 0m0.751s
sys 0m0.032s

===============================================================================

Running: ../../.github/citools/cpp/clang-tidy | head -n 100
17049 warnings generated.
52427 warnings generated.
52427 warnings and 3 errors generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/luhn/luhn.h.
Suppressed 52433 warnings (52427 in non-user code, 6 NOLINT).
14669 warnings generated.
50086 warnings generated.
64732 warnings generated.
Suppressed 64737 warnings (64732 in non-user code, 5 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).

real 0m7.441s
user 0m7.371s
sys 0m0.069s
Running: clang-tidy-16 ./luhn.cpp ./luhn_test.cpp ./luhn.h
error: invalid argument '-std=c++17' not allowed with 'C' [clang-diagnostic-error]
error: argument unused during compilation: '-stdlib=libstdc++' [clang-diagnostic-unused-command-line-argument]
/home/vpayno/git_vpayno/exercism-workspace/cpp/luhn/luhn.h:4:10: error: 'array' file not found [clang-diagnostic-error]
#include <array>
^~~~~~~


real 0m7.444s
user 0m7.373s
sys 0m0.071s

real 0m8.297s
user 0m8.222s
sys 0m0.074s
Running: clang-tidy-16 ./luhn.cpp ./luhn_test.cpp ./luhn.hpp


real 0m8.299s
user 0m8.223s
sys 0m0.075s

===============================================================================

0 comments on commit b8c9ea8

Please sign in to comment.