mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Merge pull request #3 from JonasG/master
TextTest version of GildedRose kata in C++
This commit is contained in:
commit
c307d9e5dc
@ -1,28 +1,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "GildedRose.h"
|
||||
|
||||
#include <string>
|
||||
GildedRose::GildedRose(vector<Item> & items) : items(items)
|
||||
{}
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Item
|
||||
void GildedRose::updateQuality()
|
||||
{
|
||||
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) : items (items)
|
||||
{}
|
||||
|
||||
void updateQuality()
|
||||
{
|
||||
for (int i = 0; i < items.size(); i++)
|
||||
{
|
||||
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
@ -95,29 +77,4 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
24
GildedRose/cpp/GildedRose.h
Normal file
24
GildedRose/cpp/GildedRose.h
Normal file
@ -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();
|
||||
};
|
||||
|
||||
38
GildedRose/cpp/GildedRoseTextTests.cc
Normal file
38
GildedRose/cpp/GildedRoseTextTests.cc
Normal file
@ -0,0 +1,38 @@
|
||||
#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("Backstage passes to a TAFKAL80ETC concert", 15, 20));
|
||||
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();
|
||||
}
|
||||
}
|
||||
24
GildedRose/cpp/GildedRoseUnitTests.cc
Normal file
24
GildedRose/cpp/GildedRoseUnitTests.cc
Normal file
@ -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();
|
||||
}
|
||||
@ -27,6 +27,8 @@ CXXFLAGS += -g -Wall -Wextra
|
||||
# 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 \
|
||||
@ -34,10 +36,10 @@ GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
|
||||
|
||||
# House-keeping build targets.
|
||||
|
||||
all : $(TESTS)
|
||||
all : $(TESTS) $(TEXTTESTS)
|
||||
|
||||
clean :
|
||||
rm -f $(TESTS) gtest.a gtest_main.a *.o
|
||||
rm -f $(TESTS) $(TEXTTESTS) gtest.a gtest_main.a *.o
|
||||
|
||||
# Builds gtest.a and gtest_main.a.
|
||||
|
||||
@ -67,9 +69,18 @@ gtest_main.a : gtest-all.o gtest_main.o
|
||||
# gtest_main.a, depending on whether it defines its own main()
|
||||
# function.
|
||||
|
||||
GildedRose.o : $(USER_DIR)/GildedRose.cc \
|
||||
$(GTEST_HEADERS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/GildedRose.cc
|
||||
GildedRose.o : $(USER_DIR)/GildedRose.cc
|
||||
$(CXX) -c $^
|
||||
|
||||
GildedRose : GildedRose.o gtest_main.a
|
||||
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 $@
|
||||
|
||||
Loading…
Reference in New Issue
Block a user