mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
commit
eb184b0d57
6
dart/.gitignore
vendored
Normal file
6
dart/.gitignore
vendored
Normal 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
35
dart/bin/main.dart
Normal 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
68
dart/lib/gilded_rose.dart
Normal 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
6
dart/pubspec.yaml
Normal 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'
|
||||
13
dart/test/gilded_rose_test.dart
Normal file
13
dart/test/gilded_rose_test.dart
Normal 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);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user