mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-15 10:33:53 +00:00
Removed all the code except for the GildedRose kata from this repo
This commit is contained in:
1 parent
b31a5436cc
commit
567c27854a
112 files changed
+35
-4801
No files matched your search
@@ -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();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "GildedRose.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ostream& operator<<(ostream& s, Item& item)
|
||||
{
|
||||
s << item.name << ", " << item.sellIn << ", " << item.quality;
|
||||
return s;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
vector<Item> items;
|
||||
items.push_back(Item("+5 Dexterity Vest", 10, 20));
|
||||
items.push_back(Item("Aged Brie", 2, 0));
|
||||
items.push_back(Item("Elixir of the Mongoose", 5, 7));
|
||||
items.push_back(Item("Sulfuras, Hand of Ragnaros", 0, 80));
|
||||
items.push_back(Item("Sulfuras, Hand of Ragnaros", -1, 80));
|
||||
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
|
||||
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 10, 49));
|
||||
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 5, 49));
|
||||
// this Conjured item doesn't yet work properly
|
||||
items.push_back(Item("Conjured Mana Cake", 3, 6));
|
||||
GildedRose app(items);
|
||||
|
||||
cout << "OMGHAI!" << endl;
|
||||
|
||||
for (int day = 0; day <= 30; day++)
|
||||
{
|
||||
cout << "-------- day " << day << " --------" << endl;
|
||||
cout << "name, sellIn, quality" << endl;
|
||||
for (vector<Item>::iterator i = items.begin(); i != items.end(); i++)
|
||||
{
|
||||
cout << *i << endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
void example()
|
||||
{
|
||||
vector<Item> items;
|
||||
items.push_back(Item("+5 Dexterity Vest", 10, 20));
|
||||
items.push_back(Item("Aged Brie", 2, 0));
|
||||
items.push_back(Item("Elixir of the Mongoose", 5, 7));
|
||||
items.push_back(Item("Sulfuras, Hand of Ragnaros", 0, 80));
|
||||
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
|
||||
items.push_back(Item("Conjured Mana Cake", 3, 6));
|
||||
GildedRose app(items);
|
||||
app.updateQuality();
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
# Makefile for building the kata file with the Google Testing Framework
|
||||
#
|
||||
# SYNOPSIS:
|
||||
#
|
||||
# make [all] - makes everything.
|
||||
# make TARGET - makes the given target.
|
||||
# make clean - removes all files generated by make.
|
||||
|
||||
# Please tweak the following variable definitions as needed by your
|
||||
# project, except GTEST_HEADERS, which you can use in your own targets
|
||||
# but shouldn't modify.
|
||||
|
||||
# Points to the root of Google Test, relative to where this file is.
|
||||
# Remember to tweak this if you move this file.
|
||||
GTEST_DIR = gtest
|
||||
|
||||
# Where to find user code.
|
||||
USER_DIR = .
|
||||
|
||||
# Flags passed to the preprocessor.
|
||||
CPPFLAGS += -I$(GTEST_DIR)/include
|
||||
|
||||
# Flags passed to the C++ compiler.
|
||||
CXXFLAGS += -g -Wall -Wextra
|
||||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
TESTS = GildedRose
|
||||
|
||||
TEXTTESTS = GildedRoseTextTests
|
||||
|
||||
# All Google Test headers. Usually you shouldn't change this
|
||||
# definition.
|
||||
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
|
||||
$(GTEST_DIR)/include/gtest/internal/*.h
|
||||
|
||||
# House-keeping build targets.
|
||||
|
||||
all : $(TESTS) $(TEXTTESTS)
|
||||
|
||||
clean :
|
||||
rm -f $(TESTS) $(TEXTTESTS) gtest.a gtest_main.a *.o
|
||||
|
||||
# Builds gtest.a and gtest_main.a.
|
||||
|
||||
# Usually you shouldn't tweak such internal variables, indicated by a
|
||||
# trailing _.
|
||||
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
|
||||
|
||||
# For simplicity and to avoid depending on Google Test's
|
||||
# implementation details, the dependencies specified below are
|
||||
# conservative and not optimized. This is fine as Google Test
|
||||
# compiles fast and for ordinary users its source rarely changes.
|
||||
gtest-all.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
|
||||
$(GTEST_DIR)/src/gtest-all.cc
|
||||
|
||||
gtest_main.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
|
||||
$(GTEST_DIR)/src/gtest_main.cc
|
||||
|
||||
gtest.a : gtest-all.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
gtest_main.a : gtest-all.o gtest_main.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
# Builds a sample test. A test should link with either gtest.a or
|
||||
# gtest_main.a, depending on whether it defines its own main()
|
||||
# function.
|
||||
|
||||
GildedRose.o : $(USER_DIR)/GildedRose.cc
|
||||
$(CXX) -c $^
|
||||
|
||||
GildedRoseUnitTests.o : $(USER_DIR)/GildedRoseUnitTests.cc \
|
||||
$(GTEST_HEADERS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/GildedRoseUnitTests.cc
|
||||
|
||||
GildedRose : GildedRoseUnitTests.o GildedRose.o gtest_main.a
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -pthread $^ -o $@
|
||||
|
||||
GildedRoseTextTests.o : $(USER_DIR)/GildedRoseTextTests.cc
|
||||
$(CXX) -c $^
|
||||
|
||||
GildedRoseTextTests : GildedRoseTextTests.o GildedRose.o
|
||||
$(CXX) -pthread $^ -o $@
|
||||
@@ -0,0 +1,7 @@
|
||||
run-once.sh runs your tests once
|
||||
|
||||
Assumptions:
|
||||
- make and a C++ compiler (like gcc) is installed on your system and is in the PATH
|
||||
- The GTest framework is in the directory gtest.
|
||||
- If your IDE does the compilation and linking, you should remove the first 3 lines
|
||||
in the run-once.sh file.
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
rm GildedRose
|
||||
rm GildedRose.o
|
||||
make
|
||||
./GildedRose
|
||||
Reference in new issue
Block a user