Skip to content

Commit

Permalink
c++/vehicle-purchase: 3rd iteration - c header -> c++ header
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jul 17, 2023
1 parent cd12c10 commit 89d5a6f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 76 deletions.
6 changes: 3 additions & 3 deletions cpp/vehicle-purchase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,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
92 changes: 39 additions & 53 deletions cpp/vehicle-purchase/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.009s
user 0m0.003s
sys 0m0.006s
real 0m0.011s
user 0m0.004s
sys 0m0.008s

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

Expand Down Expand Up @@ -70,25 +70,25 @@ Directory: .
File Lines Exec Cover Missing
------------------------------------------------------------------------------
test/catch.hpp 59 44 74% 1642-1643,1710-1711,2227,2229,2301-2302,2560,3780-3784,3786
vehicle_purchase.cpp 16 15 93% 23
vehicle_purchase.cpp 16 15 93% 20
vehicle_purchase_test.cpp 81 81 100%
------------------------------------------------------------------------------
TOTAL 156 140 89%
------------------------------------------------------------------------------
lines: 89.7% (140 out of 156)
branches: 38.6% (139 out of 360)

real 0m8.737s
user 0m7.847s
sys 0m0.881s
real 0m8.324s
user 0m7.492s
sys 0m0.831s

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

cmake-format --in-place CMakeLists.txt

real 0m0.160s
user 0m0.113s
sys 0m0.048s
real 0m0.139s
user 0m0.095s
sys 0m0.046s

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

Expand All @@ -110,77 +110,63 @@ found lint:
Convention: 4


real 0m0.149s
user 0m0.111s
sys 0m0.039s
real 0m0.164s
user 0m0.107s
sys 0m0.058s

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

Running: clang-format-16 -style=file -i ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.h
Running: clang-format-16 -style=file -i ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp

real 0m0.022s
user 0m0.012s
sys 0m0.010s
real 0m0.023s
user 0m0.009s
sys 0m0.014s

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

Running: ../../.github/citools/cpp/clang-check
clang-check-16 --analyze ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.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/vehicle-purchase/vehicle_purchase.h:5:10: fatal error: 'cmath' file not found
#include <cmath>
^~~~~~~
1 error generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.h.
clang-check-16 --analyze ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.hpp

real 0m0.551s
user 0m0.513s
sys 0m0.038s
real 0m0.620s
user 0m0.579s
sys 0m0.041s


real 0m0.553s
user 0m0.513s
sys 0m0.040s
real 0m0.622s
user 0m0.579s
sys 0m0.042s

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

Running: ../../.github/citools/cpp/clang-tidy | head -n 100
15011 warnings generated.
50357 warnings generated.
50357 warnings and 3 errors generated.
Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.h.
Suppressed 50360 warnings (50355 in non-user code, 5 NOLINT).
15010 warnings generated.
50356 warnings generated.
65355 warnings generated.
Suppressed 65358 warnings (65353 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.503s
user 0m7.432s
sys 0m0.070s
Running: clang-tidy-16 ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.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/vehicle-purchase/vehicle_purchase.cpp:32:31: warning: 2 adjacent parameters of 'calculate_resell_price' of similar type ('double') are easily swapped by mistake [bugprone-easily-swappable-parameters]

real 0m9.103s
user 0m9.037s
sys 0m0.063s
Running: clang-tidy-16 ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.hpp
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:28:31: warning: 2 adjacent parameters of 'calculate_resell_price' of similar type ('double') are easily swapped by mistake [bugprone-easily-swappable-parameters]
double calculate_resell_price(double original_price, double age) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:32:38: note: the first parameter in the range is 'original_price'
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:28:38: note: the first parameter in the range is 'original_price'
double calculate_resell_price(double original_price, double age) {
^~~~~~~~~~~~~~
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:32:61: note: the last parameter in the range is 'age'
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:28:61: note: the last parameter in the range is 'age'
double calculate_resell_price(double original_price, double age) {
^~~
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.h:5:10: error: 'cmath' file not found [clang-diagnostic-error]
#include <cmath>
^~~~~~~
/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase_test.cpp:10:5: warning: variable 'kind' of type 'std::string' (aka 'basic_string<char>') can be declared 'const' [misc-const-correctness]
std::string kind{"car"};
^
const


real 0m7.506s
user 0m7.432s
sys 0m0.075s
real 0m9.104s
user 0m9.037s
sys 0m0.066s

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

6 changes: 1 addition & 5 deletions cpp/vehicle-purchase/vehicle_purchase.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#include "vehicle_purchase.h"

// didn't work when added to the C header file (why isn't it a c++ header
// file?????)
#include <cmath>
#include "vehicle_purchase.hpp"

namespace vehicle_purchase {

Expand Down
14 changes: 0 additions & 14 deletions cpp/vehicle-purchase/vehicle_purchase.h

This file was deleted.

15 changes: 15 additions & 0 deletions cpp/vehicle-purchase/vehicle_purchase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if !defined(VEHICLE_PURCHASE)
#define VEHICLE_PURCHASE

#include <cmath>
#include <string>

namespace vehicle_purchase {

bool needs_license(std::string kind);
std::string choose_vehicle(std::string option1, std::string option2);
double calculate_resell_price(double original_price, double age);

} // namespace vehicle_purchase

#endif
2 changes: 1 addition & 1 deletion cpp/vehicle-purchase/vehicle_purchase_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "vehicle_purchase.h"
#include "vehicle_purchase.hpp"
#ifdef EXERCISM_TEST_SUITE
#include <catch2/catch.hpp>
#else
Expand Down

0 comments on commit 89d5a6f

Please sign in to comment.