Commit 8e866228d083c33fa53e53376543fedb51ec5e4f

Authored by Hakeem
0 parents

my commit

.clang-format 0 → 100644
  1 +++ a/.clang-format
  1 +---
  2 +Language: Cpp
  3 +# BasedOnStyle: LLVM
  4 +AccessModifierOffset: -2
  5 +AlignAfterOpenBracket: Align
  6 +AlignConsecutiveAssignments: true
  7 +AlignConsecutiveDeclarations: true
  8 +AlignEscapedNewlinesLeft: false
  9 +AlignOperands: true
  10 +AlignTrailingComments: true
  11 +AllowAllParametersOfDeclarationOnNextLine: true
  12 +AllowShortBlocksOnASingleLine: false
  13 +AllowShortCaseLabelsOnASingleLine: false
  14 +AllowShortFunctionsOnASingleLine: All
  15 +AllowShortIfStatementsOnASingleLine: true
  16 +AllowShortLoopsOnASingleLine: true
  17 +AlwaysBreakAfterDefinitionReturnType: None
  18 +AlwaysBreakAfterReturnType: None
  19 +AlwaysBreakBeforeMultilineStrings: false
  20 +AlwaysBreakTemplateDeclarations: true
  21 +BinPackArguments: true
  22 +BinPackParameters: true
  23 +BraceWrapping:
  24 + AfterClass: false
  25 + AfterControlStatement: false
  26 + AfterEnum: false
  27 + AfterFunction: true
  28 + AfterNamespace: true
  29 + AfterObjCDeclaration: false
  30 + AfterStruct: false
  31 + AfterUnion: false
  32 + BeforeCatch: true
  33 + BeforeElse: true
  34 + IndentBraces: false
  35 +BreakBeforeBinaryOperators: All
  36 +BreakBeforeBraces: Custom
  37 +BreakBeforeTernaryOperators: true
  38 +BreakConstructorInitializersBeforeComma: false
  39 +ColumnLimit: 80
  40 +#CommentPragmas: '^ IWYU pragma:'
  41 +ConstructorInitializerAllOnOneLineOrOnePerLine: false
  42 +ConstructorInitializerIndentWidth: 2
  43 +ContinuationIndentWidth: 2
  44 +Cpp11BracedListStyle: true
  45 +DerivePointerAlignment: false
  46 +DisableFormat: false
  47 +ExperimentalAutoDetectBinPacking: false
  48 +FixNamespaceComments: true
  49 +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
  50 +#IncludeCategories:
  51 +# - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
  52 +# Priority: 2
  53 +# - Regex: '^(<|"(gtest|isl|json)/)'
  54 +# Priority: 3
  55 +# - Regex: '.*'
  56 +# Priority: 1
  57 +IndentCaseLabels: true
  58 +IndentWidth: 2
  59 +IndentWrappedFunctionNames: false
  60 +KeepEmptyLinesAtTheStartOfBlocks: true
  61 +MacroBlockBegin: ''
  62 +MacroBlockEnd: ''
  63 +MaxEmptyLinesToKeep: 10
  64 +NamespaceIndentation: All
  65 +ObjCBlockIndentWidth: 2
  66 +ObjCSpaceAfterProperty: false
  67 +ObjCSpaceBeforeProtocolList: true
  68 +PenaltyBreakBeforeFirstCallParameter: 19
  69 +PenaltyBreakComment: 300
  70 +PenaltyBreakFirstLessLess: 120
  71 +PenaltyBreakString: 1000
  72 +PenaltyExcessCharacter: 1000000
  73 +PenaltyReturnTypeOnItsOwnLine: 60
  74 +PointerAlignment: Left
  75 +ReflowComments: true
  76 +SortIncludes: false
  77 +SpaceAfterCStyleCast: false
  78 +SpaceBeforeAssignmentOperators: true
  79 +SpaceBeforeParens: ControlStatements
  80 +SpaceInEmptyParentheses: false
  81 +SpacesBeforeTrailingComments: 3
  82 +SpacesInAngles: false
  83 +SpacesInContainerLiterals: true
  84 +SpacesInCStyleCastParentheses: false
  85 +SpacesInParentheses: false
  86 +SpacesInSquareBrackets: false
  87 +Standard: Auto
  88 +TabWidth: 2
  89 +UseTab: Never
  90 +...
  91 +
... ...
CMakeLists.txt 0 → 100644
  1 +++ a/CMakeLists.txt
  1 +# Minimum CMake version required
  2 +cmake_minimum_required(VERSION 3.8)
  3 +
  4 +# Project
  5 +project(othello_testing VERSION 0.1 LANGUAGES CXX)
  6 +
  7 +
  8 +
  9 +
  10 +##############################
  11 +# Configure othello interfaces
  12 +find_package(othello_interfaces REQUIRED CONFIG NO_DEFAULT_PATH)
  13 +
  14 +###############################
  15 +# Configure othello game engine
  16 +find_package(othello_game_engine REQUIRED CONFIG NO_DEFAULT_PATH)
  17 +
  18 +#################
  19 +# Configure GTest
  20 +find_package(GTest REQUIRED)
  21 +if(NOT GTEST_FOUND)
  22 + message(FATAL_ERROR "GTest not found!")
  23 +endif()
  24 +
  25 +# Add GTest include folder and libraries
  26 +include_directories(${GTEST_INCLUDE_DIR})
  27 +link_libraries(${GTEST_BOTH_LIBRARIES})
  28 +
  29 +# Enable cmake testing framework; ctest
  30 +enable_testing()
  31 +
  32 +
  33 +
  34 +
  35 +
  36 +
  37 +
  38 +
  39 +######################
  40 +# Unit tests
  41 +
  42 +# Tests
  43 +set(TESTS
  44 + predefined_game_engine_unittests
  45 + predefined_utility_unittests
  46 + )
  47 +
  48 +# Add tests
  49 +foreach(TEST ${TESTS})
  50 +
  51 + add_executable( ${TEST} ${TEST}.cpp )
  52 +
  53 + # TURN ON C++17 FEATURES
  54 + target_compile_features(${TEST} PUBLIC cxx_std_17 )
  55 +
  56 + # Compiler spesific options
  57 + target_compile_options(${TEST}
  58 + PUBLIC $<$<CXX_COMPILER_ID:Clang>:
  59 + # Mandatory compiler flags
  60 + -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic
  61 + -pedantic -Werror
  62 +
  63 + # GTest
  64 + -Wno-missing-prototypes
  65 + -Wno-missing-variable-declarations
  66 +
  67 + # Disable clangs overtidyness for documentation
  68 + -Wno-documentation
  69 +
  70 + # Stuff we want to deal with later
  71 + -Wno-weak-vtables
  72 + >
  73 + PUBLIC $<$<CXX_COMPILER_ID:GNU>:
  74 + # Mandatory compiler flags
  75 + -pedantic -Wall -Werror
  76 + >
  77 + )
  78 +
  79 + target_link_libraries(${TEST}
  80 + othello::othello_interfaces
  81 + othello::othello_game_engine
  82 + ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}
  83 + pthread
  84 + )
  85 + gtest_add_tests( ${TEST} "" AUTO )
  86 +endforeach(TEST)
  87 +
  88 +
... ...
cmake/othello_testing-config.cmake.in 0 → 100644
  1 +++ a/cmake/othello_testing-config.cmake.in
  1 +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
  2 +message(STATUS "Found @PROJECT_NAME@")
... ...
predefined_game_engine_unittests.cpp 0 → 100644
  1 +++ a/predefined_game_engine_unittests.cpp
  1 +// gtest
  2 +#include <gtest/gtest.h> // googletest header file
  3 +
  4 +// cc library
  5 +#include <engine.h>
  6 +#include <orangemonkey_ai.h>
  7 +
  8 +// Testing fixture
  9 +struct PredefinedGameEngineTest : testing::Test {
  10 +
  11 + std::unique_ptr<othello::OthelloGameEngine> engine;
  12 +
  13 + PredefinedGameEngineTest();
  14 + ~PredefinedGameEngineTest() override;
  15 +};
  16 +
  17 +
  18 +PredefinedGameEngineTest::PredefinedGameEngineTest()
  19 +{
  20 + // fixture initialization
  21 +}
  22 +
  23 +PredefinedGameEngineTest::~PredefinedGameEngineTest()
  24 +{
  25 + // fixture teardown
  26 +}
  27 +
  28 +
  29 +TEST_F(PredefinedGameEngineTest, InitialCurrentPlayerIdIsOne)
  30 +{
  31 + engine->initPlayerType<othello::HumanPlayer, othello::PlayerId::One>();
  32 + engine->initPlayerType<othello::monkey_ais::OrangeMonkeyAI,
  33 + othello::PlayerId::Two>();
  34 +
  35 + EXPECT_EQ(engine->currentPlayerId(), othello::PlayerId::One);
  36 +}
... ...
predefined_utility_unittests.cpp 0 → 100644
  1 +++ a/predefined_utility_unittests.cpp
  1 +// gtest
  2 +#include <gtest/gtest.h> // googletest header file
  3 +
  4 +// cc library
  5 +#include <engine.h>
  6 +#include <orangemonkey_ai.h>
  7 +
  8 +using BitPos = othello::BitPos;
  9 +using MoveDir = othello::MoveDirection;
  10 +
  11 +// Testing fixture
  12 +struct UtilityBoardTestParams {
  13 + BitPos pos;
  14 + MoveDir dir;
  15 + BitPos expected_next_pos;
  16 +};
  17 +
  18 +struct UtilityBoardTest : testing::Test, testing::WithParamInterface<UtilityBoardTestParams> {
  19 + UtilityBoardTest() {}
  20 + ~UtilityBoardTest() override;
  21 +};
  22 +UtilityBoardTest::~UtilityBoardTest() {}
  23 +
  24 +
  25 +TEST_P(UtilityBoardTest, NextPosition)
  26 +{
  27 + auto params = GetParam();
  28 +
  29 + auto next_pos = othello::utility::nextPosition(params.pos,params.dir);
  30 + EXPECT_EQ(params.expected_next_pos,next_pos);
  31 +}
  32 +
  33 +INSTANTIATE_TEST_CASE_P(
  34 + ValidMoves, UtilityBoardTest,
  35 + testing::Values(UtilityBoardTestParams{BitPos(0), MoveDir::N, BitPos(8)},
  36 + UtilityBoardTestParams{BitPos(9), MoveDir::S, BitPos(1)}), );
  37 +
  38 +INSTANTIATE_TEST_CASE_P(
  39 + InvalidMoves, UtilityBoardTest,
  40 + testing::Values(
  41 + UtilityBoardTestParams{BitPos(1), MoveDir::S, BitPos::invalid()},
  42 + UtilityBoardTestParams{BitPos(61), MoveDir::N, BitPos::invalid()}), );
... ...