mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
commit
50418bb1b1
1
d/.gitignore
vendored
Normal file
1
d/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.dub
|
||||||
16
d/dub.json
Normal file
16
d/dub.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "GildedRose",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "GuildedRose",
|
||||||
|
"targetType": "executable",
|
||||||
|
"mainSourceFile": "src/GildedRoseTextTests.d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "unittest",
|
||||||
|
"targetType": "executable",
|
||||||
|
"sourcePaths": ["test"],
|
||||||
|
"mainSourceFile": "test/GildedRoseUnitTests.d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
93
d/src/GildedRose.d
Normal file
93
d/src/GildedRose.d
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
struct Item
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
int sellIn;
|
||||||
|
int quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
class GildedRose
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Item[] items;
|
||||||
|
this(Item[] items)
|
||||||
|
{
|
||||||
|
this.items = items.dup;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateQuality()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < items.length; 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
d/src/GildedRoseTextTests.d
Normal file
38
d/src/GildedRoseTextTests.d
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import GildedRose;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
import std.stdio : writefln, writeln;
|
||||||
|
|
||||||
|
Item[] items = [
|
||||||
|
Item("+5 Dexterity Vest", 10, 20),
|
||||||
|
Item("Aged Brie", 2, 0),
|
||||||
|
Item("Elixir of the Mongoose", 5, 7),
|
||||||
|
Item("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||||
|
Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||||
|
Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||||
|
Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||||
|
Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||||
|
// this Conjured item doesn't yet work properly
|
||||||
|
Item("Conjured Mana Cake", 3, 6),
|
||||||
|
];
|
||||||
|
|
||||||
|
auto app = new GildedRose(items);
|
||||||
|
|
||||||
|
writeln("OMGHAI!");
|
||||||
|
|
||||||
|
for (int day = 0; day <= 30; day++)
|
||||||
|
{
|
||||||
|
writefln!"-------- day %s --------"(day);
|
||||||
|
writeln("Item(name, sellIn, quality)");
|
||||||
|
foreach (item; app.items)
|
||||||
|
{
|
||||||
|
writeln(item);
|
||||||
|
}
|
||||||
|
writeln;
|
||||||
|
|
||||||
|
app.updateQuality;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
d/test/GildedRoseUnitTests.d
Normal file
25
d/test/GildedRoseUnitTests.d
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import GildedRose;
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Item[] items = [ Item("Foo", 0, 0)];
|
||||||
|
auto app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.updateQuality;
|
||||||
|
|
||||||
|
assert("fixme" == app.items[0].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void example()
|
||||||
|
{
|
||||||
|
Item[] items = [
|
||||||
|
Item("+5 Dexterity Vest", 10, 20),
|
||||||
|
Item("Aged Brie", 2, 0),
|
||||||
|
Item("Elixir of the Mongoose", 5, 7),
|
||||||
|
Item("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||||
|
Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||||
|
Item("Conjured Mana Cake", 3, 6),
|
||||||
|
];
|
||||||
|
auto app = new GildedRose(items);
|
||||||
|
app.updateQuality;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user