Merge pull request #29 from Pacane/master

Code in Dart
This commit is contained in:
Emily Bache 2016-03-19 16:10:45 +01:00
commit eb184b0d57
5 changed files with 128 additions and 0 deletions

6
dart/.gitignore vendored Normal file
View File

@ -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

35
dart/bin/main.dart Normal file
View File

@ -0,0 +1,35 @@
import 'package:gilded_rose/gilded_rose.dart';
main(List<String> 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();
}
}

68
dart/lib/gilded_rose.dart Normal file
View File

@ -0,0 +1,68 @@
class GildedRose {
List<Item> 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';
}

6
dart/pubspec.yaml Normal file
View File

@ -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'

View File

@ -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>[item];
GildedRose app = new GildedRose(items);
app.updateQuality();
expect("fixme", app.items[0].name);
});
}