diff --git a/dart/.gitignore b/dart/.gitignore new file mode 100644 index 00000000..33d0df0e --- /dev/null +++ b/dart/.gitignore @@ -0,0 +1,6 @@ +# Files and directories created by pub +.packages +.pub/ +packages +pubspec.lock # (Remove this pattern if you wish to check in your lock file) +.idea \ No newline at end of file diff --git a/dart/bin/main.dart b/dart/bin/main.dart new file mode 100644 index 00000000..240994c5 --- /dev/null +++ b/dart/bin/main.dart @@ -0,0 +1,35 @@ +import 'package:gilded_rose/gilded_rose.dart'; + +main(List args) { + print("OMGHAI!"); + + var items = [ + new Item("+5 Dexterity Vest", 10, 20), + new Item("Aged Brie", 2, 0), + new Item("Elixir of the Mongoose", 5, 7), + new Item("Sulfuras, Hand of Ragnaros", 0, 80), + new Item("Sulfuras, Hand of Ragnaros", -1, 80), + new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), + new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), + new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), + // this conjured item does not work properly yet + new Item("Conjured Mana Cake", 3, 6) + ]; + + GildedRose app = new GildedRose(items); + + int days = 2; + if (args.length > 0) { + days = int.parse(args[0]) + 1; + } + + for (int i = 0; i < days; i++) { + print("-------- day $i --------"); + print("name, sellIn, quality"); + for (var item in items) { + print(item); + } + print(''); + app.updateQuality(); + } +} diff --git a/dart/lib/gilded_rose.dart b/dart/lib/gilded_rose.dart new file mode 100644 index 00000000..94857b32 --- /dev/null +++ b/dart/lib/gilded_rose.dart @@ -0,0 +1,68 @@ +class GildedRose { + List items; + + GildedRose(this.items); + + 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; + } + } + } + } + } +} + +class Item { + String name; + int sellIn; + int quality; + + Item(this.name, this.sellIn, this.quality); + + String toString() => '$name, $sellIn, $quality'; +} diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml new file mode 100644 index 00000000..06814a33 --- /dev/null +++ b/dart/pubspec.yaml @@ -0,0 +1,6 @@ +name: gilded_rose +version: 0.0.1 +description: A simple console application. + +dev_dependencies: + test: '>=0.12.11 <0.13.0' diff --git a/dart/test/gilded_rose_test.dart b/dart/test/gilded_rose_test.dart new file mode 100644 index 00000000..69e4a489 --- /dev/null +++ b/dart/test/gilded_rose_test.dart @@ -0,0 +1,13 @@ +import 'package:test/test.dart'; +import 'package:gilded_rose/gilded_rose.dart'; + +main() { + test('foo', () { + var item = new Item('foo', 0, 0); + var items = [item]; + + GildedRose app = new GildedRose(items); + app.updateQuality(); + expect("fixme", app.items[0].name); + }); +}