mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
C++ version with a vector to hold the items.
This commit is contained in:
parent
5b6c47ccc8
commit
5010475a2f
@ -1,30 +1,29 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
void example()
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Item
|
||||
{
|
||||
std::list<Item> items = new std::list<Item>();
|
||||
items.push_back(new Item("+5 Dexterity Vest", 10, 20));
|
||||
items.push_back(new Item("Aged Brie", 2, 0));
|
||||
items.push_back(new Item("Elixir of the Mongoose", 5, 7));
|
||||
items.push_back(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
|
||||
items.push_back(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
|
||||
items.push_back(new Item("Conjured Mana Cake", 3, 6));
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
}
|
||||
public:
|
||||
string name;
|
||||
int sellIn;
|
||||
int quality;
|
||||
Item(string name, int sellIn, int quality) : name(name), sellIn(sellIn), quality(quality)
|
||||
{}
|
||||
};
|
||||
|
||||
class GildedRose
|
||||
{
|
||||
public:
|
||||
std::list<Item> items;
|
||||
GildedRose(std::list items)
|
||||
{
|
||||
this.items = items;
|
||||
}
|
||||
vector<Item> items;
|
||||
GildedRose(vector<Item> items) : items (items)
|
||||
{}
|
||||
|
||||
void updateQuality()
|
||||
{
|
||||
for (int i = 0; i < items.length; i++)
|
||||
for (int i = 0; i < items.size(); i++)
|
||||
{
|
||||
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
@ -99,18 +98,25 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class Item
|
||||
|
||||
void example()
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
int sellIn;
|
||||
int quality;
|
||||
};
|
||||
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) {
|
||||
std::list<Item> items = new std::list<Item>();
|
||||
items.push_back(new Item("Foo", 0, 0));
|
||||
GildedRose app = new GildedRose(items);
|
||||
vector<Item> items;
|
||||
items.push_back(Item("Foo", 0, 0));
|
||||
GildedRose app(items);
|
||||
app.updateQuality();
|
||||
EXPECT_EQ("fixme", app.items[0].name);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user