diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..79e170b --- /dev/null +++ b/.clang-format @@ -0,0 +1,148 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 8 +UseTab: Never +... + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed86553 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index a591a10..a389b19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,13 @@ project(cpp-opencv-example-1) add_executable(main main.cpp) - find_package(OpenCV REQUIRED) target_include_directories(main PRIVATE ${OpenCV_INCLUDE_DIRS}) target_link_libraries(main PRIVATE ${OpenCV_LIBS}) find_package(LibLZMA REQUIRED) target_include_directories(main PRIVATE ${LIBLZMA_INCLUDE_DIRS}) -target_link_libraries(main PRIVATE ${LIBLZMA_LIBRARIES}) \ No newline at end of file +target_link_libraries(main PRIVATE ${LIBLZMA_LIBRARIES}) + +add_subdirectory(lib/binops) +target_link_libraries(main PRIVATE binops) diff --git a/helper_functions.h b/helper_functions.h deleted file mode 100644 index 6f725b1..0000000 --- a/helper_functions.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// helper_functions.h -// cpp-opencv-example-1 -// -// Created by Javier on 01.10.18. -// - -#ifndef helper_functions_h -#define helper_functions_h - -int rgb2gray(int a, int b) { - return a + b; -} - -#endif /* helper_functions_h */ diff --git a/image.png b/image.png new file mode 100644 index 0000000..615dd93 Binary files /dev/null and b/image.png differ diff --git a/lib/binops/CMakeLists.txt b/lib/binops/CMakeLists.txt new file mode 100644 index 0000000..47b2729 --- /dev/null +++ b/lib/binops/CMakeLists.txt @@ -0,0 +1,8 @@ +include(GoogleTest) +add_executable(runtests test/main test/addition_tests.cpp) +find_package(GTest REQUIRED) +target_link_libraries(runtests PRIVATE GTest::GTest GTest::Main binops) +gtest_discover_tests(runtests) + +add_library(binops SHARED include/binops.hpp src/addition.cpp) +set_target_properties(binops PROPERTIES PUBLIC_HEADER include/binops.hpp) diff --git a/lib/binops/include/binops.hpp b/lib/binops/include/binops.hpp new file mode 100644 index 0000000..115034e --- /dev/null +++ b/lib/binops/include/binops.hpp @@ -0,0 +1,23 @@ +#ifndef binops_hpp +#define binops_hpp + +#include + +namespace BinOps { +class Addition { + public: + void setLHS(int lhs); + void setRHS(int rhs); + + int getLHS(); + int getRHS(); + + int perform(); + + private: + int lhs; + int rhs; +}; +} // namespace BinOps + +#endif diff --git a/lib/binops/src/addition.cpp b/lib/binops/src/addition.cpp new file mode 100644 index 0000000..210068f --- /dev/null +++ b/lib/binops/src/addition.cpp @@ -0,0 +1,13 @@ +#include "../include/binops.hpp" + +using namespace BinOps; + +void Addition::setLHS(int lhs) { this->lhs = lhs; } + +void Addition::setRHS(int rhs) { this->rhs = rhs; } + +int Addition::getLHS() { return this->lhs; } + +int Addition::getRHS() { return this->rhs; } + +int Addition::perform() { return this->lhs + this->rhs; } diff --git a/lib/binops/test/addition_tests.cpp b/lib/binops/test/addition_tests.cpp new file mode 100644 index 0000000..53a3e18 --- /dev/null +++ b/lib/binops/test/addition_tests.cpp @@ -0,0 +1,61 @@ +#include +#include +#include "../include/binops.hpp" + +using namespace BinOps; + +TEST(AdditionTests, TestItIsNotNil) { + // when + Addition a = Addition(); + + // then + ASSERT_NE(&a, nullptr); +} + +TEST(AdditionTests, TestItSetsTheLHS) { + // given + Addition a = Addition(); + + // when + a.setLHS(3); + + // then + ASSERT_EQ(a.getLHS(), 3); +} + +TEST(AdditionTests, TestItSetsTheRHS) { + // given + Addition a = Addition(); + + // when + a.setRHS(100); + + // then + ASSERT_EQ(a.getRHS(), 100); +} + +TEST(AdditionTests, TestItGivesTheExpectedResultFor3And5) { + // given + Addition a = Addition(); + a.setLHS(3); + a.setRHS(5); + + // when + int result = a.perform(); + + // then + ASSERT_EQ(result, 8); +} + +TEST(AdditionTests, TestItGivesTheExpectedResultFor1And2) { + // given + Addition a = Addition(); + a.setLHS(1); + a.setRHS(2); + + // when + int result = a.perform(); + + // then + ASSERT_EQ(result, 3); +} diff --git a/lib/binops/test/main.cpp b/lib/binops/test/main.cpp new file mode 100644 index 0000000..a82614a --- /dev/null +++ b/lib/binops/test/main.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/main.cpp b/main.cpp index e95a1c3..9706511 100644 --- a/main.cpp +++ b/main.cpp @@ -1,50 +1,52 @@ +#include #include #include #include -#include "helper_functions.h" -#include +#include "lib/binops/include/binops.hpp" using namespace cv; using namespace std; -int main(int argc, const char * argv[]) { - if (argc !=2) { - cout << "Usage wrong" << endl; - return -1; - } - - Mat image; - image = imread(argv[1], CV_LOAD_IMAGE_COLOR); - - if(! image.data ) - { - cout << "Could not open or find the image" << std::endl ; - return -1; - } - - namedWindow( "Display window", WINDOW_AUTOSIZE ); - imshow( "Display window", image ); - - waitKey(0); - - Mat image_bw; - cvtColor(image, image_bw, COLOR_RGB2GRAY); - - namedWindow( "Display window - b&w", WINDOW_AUTOSIZE ); - imshow( "Display window - b&w", image_bw); - - waitKey(0); - - Mat image_bin; - threshold(image_bw, image_bin, 125, 255, THRESH_BINARY); - - namedWindow( "Display window - bin", WINDOW_AUTOSIZE ); - imshow( "Display window - bin", image_bin); - - waitKey(0); - - int aux = rgb2gray(4, 4); - - std::cout << "Hello, Lena!\n" << aux << endl; - return 0; +int main(int argc, const char* argv[]) { + if (argc != 2) { + cout << "Usage wrong" << endl; + return -1; + } + + Mat image; + image = imread(argv[1], CV_LOAD_IMAGE_COLOR); + + if (!image.data) { + cout << "Could not open or find the image" << std::endl; + return -1; + } + + namedWindow("Display window", WINDOW_AUTOSIZE); + imshow("Display window", image); + + waitKey(0); + + Mat image_bw; + cvtColor(image, image_bw, COLOR_RGB2GRAY); + + namedWindow("Display window - b&w", WINDOW_AUTOSIZE); + imshow("Display window - b&w", image_bw); + + waitKey(0); + + Mat image_bin; + threshold(image_bw, image_bin, 125, 255, THRESH_BINARY); + + namedWindow("Display window - bin", WINDOW_AUTOSIZE); + imshow("Display window - bin", image_bin); + + waitKey(0); + + BinOps::Addition a = BinOps::Addition(); + a.setLHS(4); + a.setRHS(4); + int result = a.perform(); + + std::cout << "Hello, Lena!\n" << result << endl; + return 0; }