mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-13 17:49:25 +00:00
Refactor C++ version of the Gilded Rose kata
* Make it possible to build and run tests in CLion
and Visual Studio 2019 out of the box
* Provide four types of initial test using different test frameworks:
* Catch2 test framework
* Traditional unit testing using Catch2
* Approval test using Catch2
* Google Test test framework
* Traditional unit testing using Google Test
* Approval test using Google Test
* The different types of initial test are located in separate folders
in the test folder.
* Remove scripts to build and run tests and replace
with instructions in the cpp README.md
* Use C++17
* Use CMake => 3.13
This commit is contained in:
1 parent
16dd174765
commit
1836cca836
30 files changed
+20786
-287
No files matched your search
@@ -0,0 +1,4 @@
|
||||
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})
|
||||
@@ -0,0 +1,80 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#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();
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user