Delete cpp directory

This commit is contained in:
Matt Decker 2022-06-26 09:14:12 -05:00 committed by GitHub
parent 110de4c8c8
commit 2152310df8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 0 additions and 20977 deletions

4
cpp/.gitignore vendored
View File

@ -1,4 +0,0 @@
.idea
.vs
cmake-build-debug
build

View File

@ -1,37 +0,0 @@
cmake_minimum_required(VERSION 3.13)
project(gilded-rose-refactoring-kata-cpp)
# Load FetchContent module.
include(FetchContent)
# Declare GoogleTest as the content to fetch
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
)
# Fetch GoogleTest amd make build scripts available
if (NOT googletest_POPULATED)
FetchContent_Populate(googletest)
endif()
#set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE)
# Force Google Test to link the C/C++ runtimes dynamically when
# building on Visual Studio
# Link:
# * https://github.com/google/googletest/tree/release-1.8.1/googletest#visual-studio-dynamic-vs-static-runtimes
if (MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
# Bring the populated content into the build
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
# uncomment this line to enable coverage measurements using gcov
# set(CMAKE_CXX_FLAGS "--coverage")
enable_testing()
add_subdirectory(src)
add_subdirectory(lib)
add_subdirectory(test)

View File

@ -1,68 +0,0 @@
# C++ version of Gilded Rose refactoring kata
## Introduction
The C++ version of the Gilded Rose refactoring kata is available in four variants using different test frameworks:
* Catch2 test framework
1. Traditional unit test with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_unittest` folder.
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_approvaltest` folder.
* Google Test framework
1. Traditional unit test with the [Googletest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_unittest` folder.
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Googletest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_approvaltest` folder.
The `GildedRose.cc` file, i.e. the code under test, is identical in all four variants.
## Prerequisites
* CMake version >= 3.13
* C++ compiler that support C++11
## How to build and run tests in a terminal
### Build tests
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
### Show available tests
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp/build
$ ctest -N
Test project ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp/build
Test #1: GildedRoseCatch2ApprovalTests
Test #2: GildedRoseCatch2UnitTests
Test #3: GildedRoseGoogletestApprovalTests
Test #4: GildedRoseGoogletestUnitTests
### Run all tests
$ ctest
### Run all tests with verbose output
$ ctest -VV
### Run a specific test with verbose output
$ ctest -VV --tests-regex Catch2Approval
## How to build and run tests using the [CLion IDE](https://www.jetbrains.com/clion/)
1. Start CLion
2. Select menu `File - Open...`
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
4. Select menu `Build - Build Project`
4. Select menu `Run - Run...`
4. Select what test variant to run, e.g. `GildedRoseCatch2ApprovalTests`.
## How to build and run tests using Visual Studio 2019
1. Start Visual Studio 2019
2. Select `Open a local folder`
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
4. Wait for message `CMake generation finished.` in the CMake output window at the bottom
5. Select what test variant to run in the drop down menu for Startup Items, e.g. `GildedRoseCatch2ApprovalTests.exe`.
6. Select menu `Debug - Start`

View File

@ -1,4 +0,0 @@
#ifndef APPROVAL_TEST_1_APPROVALTESTS_HPP
#define APPROVAL_TEST_1_APPROVALTESTS_HPP
#include "ApprovalTests.v.6.0.0.hpp"
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +0,0 @@
set(LIB_NAME lib)
add_library(${LIB_NAME} INTERFACE)
target_include_directories(${LIB_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +0,0 @@
set(SRC_LIB_NAME src)
add_library(${SRC_LIB_NAME})
target_sources(${SRC_LIB_NAME} PRIVATE GildedRose.cc)
target_include_directories(${SRC_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,80 +0,0 @@
#include "GildedRose.h"
GildedRose::GildedRose(vector<Item> & items) : items(items)
{}
void GildedRose::updateQuality()
{
for (int i = 0; i < items.size(); i++)
{
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].quality > 0)
{
if (items[i].name != "Sulfuras, Hand of Ragnaros")
{
items[i].quality = items[i].quality - 1;
}
}
}
else
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
if (items[i].name == "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].sellIn < 11)
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
}
}
if (items[i].sellIn < 6)
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
}
}
}
}
}
if (items[i].name != "Sulfuras, Hand of Ragnaros")
{
items[i].sellIn = items[i].sellIn - 1;
}
if (items[i].sellIn < 0)
{
if (items[i].name != "Aged Brie")
{
if (items[i].name != "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].quality > 0)
{
if (items[i].name != "Sulfuras, Hand of Ragnaros")
{
items[i].quality = items[i].quality - 1;
}
}
}
else
{
items[i].quality = items[i].quality - items[i].quality;
}
}
else
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
}
}
}
}
}

View File

@ -1,24 +0,0 @@
#include <string>
#include <vector>
using namespace std;
class Item
{
public:
string name;
int sellIn;
int quality;
Item(string name, int sellIn, int quality) : name(name), sellIn(sellIn), quality(quality)
{}
};
class GildedRose
{
public:
vector<Item> & items;
GildedRose(vector<Item> & items);
void updateQuality();
};

View File

@ -1,5 +0,0 @@
add_subdirectory(cpp_catch2_approvaltest)
add_subdirectory(cpp_catch2_unittest)
add_subdirectory(cpp_googletest_approvaltest)
add_subdirectory(cpp_googletest_unittest)
add_subdirectory(cpp_texttest)

View File

@ -1,15 +0,0 @@
set(TEST_NAME GildedRoseCatch2ApprovalTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc)
target_link_libraries(${TEST_NAME} lib src)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro is used by Catch2 to get the path to current test file.
# Links:
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
if (MSVC)
target_compile_options(${TEST_NAME} PRIVATE "/FC")
endif()

View File

@ -1,2 +0,0 @@
(Foo, 1, 1) => name: Foo, sellIn: 0, quality: 0

View File

@ -1,29 +0,0 @@
#define APPROVALS_CATCH
#include "ApprovalTests.hpp"
#include "GildedRose.h"
std::ostream& operator<<(std::ostream& os, const Item& obj)
{
return os
<< "name: " << obj.name
<< ", sellIn: " << obj.sellIn
<< ", quality: " << obj.quality;
}
TEST_CASE("GildedRoseApprovalTests", "VerifyCombinations")
{
std::vector<string> names { "Foo" };
std::vector<int> sellIns { 1 };
std::vector<int> qualities { 1 };
auto f = [](string name, int sellIn, int quality) {
vector<Item> items = {Item(name, sellIn, quality)};
GildedRose app(items);
app.updateQuality();
return items[0];
};
ApprovalTests::CombinationApprovals::verifyAllCombinations(
f,
names, sellIns, qualities);
}

View File

@ -1,15 +0,0 @@
set(TEST_NAME GildedRoseCatch2UnitTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc)
target_link_libraries(${TEST_NAME} lib src)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro is used by Catch2 to get the path to current test file.
# Links:
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
if (MSVC)
target_compile_options(${TEST_NAME} PRIVATE "/FC")
endif()

View File

@ -1,12 +0,0 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "Catch.hpp"
#include "GildedRose.h"
TEST_CASE("GildedRoseUnitTest", "Foo")
{
vector<Item> items;
items.push_back(Item("Foo", 0, 0));
GildedRose app(items);
app.updateQuality();
REQUIRE("fixme" == app.items[0].name);
}

View File

@ -1,15 +0,0 @@
set(TEST_NAME GildedRoseGoogletestApprovalTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE googletest_approval_main.cc GildedRoseGoogletestApprovalTests.cc)
target_link_libraries(${TEST_NAME} lib src gtest)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro can be used to get the path to current test file.
# Links:
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
if (MSVC)
target_compile_options(${TEST_NAME} PRIVATE "/FC")
endif()

View File

@ -1,33 +0,0 @@
// Include header files for test frameworks
#include <gtest/gtest.h>
#include <ApprovalTests.hpp>
// Include code to be tested
#include "GildedRose.h"
std::ostream& operator<<(std::ostream& os, const Item& obj)
{
return os
<< "name: " << obj.name
<< ", sellIn: " << obj.sellIn
<< ", quality: " << obj.quality;
}
TEST(GildedRoseApprovalTests, VerifyCombinations) {
std::vector<string> names { "Foo" };
std::vector<int> sellIns { 1 };
std::vector<int> qualities { 1 };
auto f = [](string name, int sellIn, int quality) {
vector<Item> items = {Item(name, sellIn, quality)};
GildedRose app(items);
app.updateQuality();
return items[0];
};
ApprovalTests::CombinationApprovals::verifyAllCombinations(
f,
names, sellIns, qualities);
}

View File

@ -1,2 +0,0 @@
#define APPROVALS_GOOGLETEST // This tells Approval Tests to provide a main() - only do this in one cpp file
#include "ApprovalTests.hpp"

View File

@ -1,15 +0,0 @@
set(TEST_NAME GildedRoseGoogletestUnitTests)
add_executable(${TEST_NAME})
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestUnitTests.cc)
target_link_libraries(${TEST_NAME} src gtest gtest_main)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro can be used to get the path to current test file.
# Links:
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
if (MSVC)
target_compile_options(${TEST_NAME} PRIVATE "/FC")
endif()

View File

@ -1,10 +0,0 @@
#include <gtest/gtest.h>
#include "GildedRose.h"
TEST(GildedRoseTest, Foo) {
vector<Item> items;
items.push_back(Item("Foo", 0, 0));
GildedRose app(items);
app.updateQuality();
EXPECT_EQ("fixme", app.items[0].name);
}

View File

@ -1,15 +0,0 @@
set(TEST_NAME GildedRoseTextTests)
add_executable(${TEST_NAME} GildedRoseTextTests.cc)
target_sources(${TEST_NAME} PRIVATE GildedRoseTextTests.cc)
target_link_libraries(${TEST_NAME} lib src)
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
# The __FILE__ macro is used by Catch2 to get the path to current test file.
# Links:
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
if (MSVC)
target_compile_options(${TEST_NAME} PRIVATE "/FC")
endif()

View File

@ -1,43 +0,0 @@
#include <iostream>
#include "GildedRose.h"
void print_item(Item& item)
{
std::cout << item.name << ", " << item.sellIn << ", " << item.quality << std::endl;
}
int main()
{
vector<Item> items;
items.push_back({"+5 Dexterity Vest", 10, 20});
items.push_back({"Aged Brie", 2, 0});
items.push_back({"Elixir of the Mongoose", 5, 7});
items.push_back({"Sulfuras, Hand of Ragnaros", 0, 80});
items.push_back({"Sulfuras, Hand of Ragnaros", -1, 80});
items.push_back({"Backstage passes to a TAFKAL80ETC concert", 15, 20});
items.push_back({"Backstage passes to a TAFKAL80ETC concert", 10, 49});
items.push_back({"Backstage passes to a TAFKAL80ETC concert", 5, 49});
// this Conjured item doesn't yet work properly
items.push_back({"Conjured Mana Cake", 3, 6});
std::cout << "OMGHAI!" << std::endl;
GildedRose app(items);
for (int day = 0; day <= 30; day++)
{
std::cout << "-------- day " << day << " --------" << std::endl;
std::cout << "name, sellIn, quality" << std::endl;
for (auto& item : items)
{
print_item(item);
}
std::cout << std::endl;
app.updateQuality();
}
return 0;
}