Initial Dart

This commit is contained in:
Joel Trottier-Hebert 2016-02-29 21:30:33 -05:00
parent 17f213d103
commit fa9e551902
6 changed files with 336 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';
}

208
dart/pubspec.lock Normal file
View File

@ -0,0 +1,208 @@
# Generated by pub
# See http://pub.dartlang.org/doc/glossary.html#lockfile
packages:
analyzer:
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.27.2"
args:
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.3+4"
async:
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
barback:
description:
name: barback
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.2+7"
boolean_selector:
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
charcode:
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection:
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
crypto:
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.1"
csslib:
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.2"
glob:
description:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
html:
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.2+1"
http_multi_server:
description:
name: http_multi_server
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
http_parser:
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
logging:
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.2"
matcher:
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+1"
mime:
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.3"
package_config:
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
path:
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.9"
plugin:
description:
name: plugin
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
pool:
description:
name: pool
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
pub_semver:
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.3"
shelf:
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.5"
shelf_static:
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3+3"
shelf_web_socket:
description:
name: shelf_web_socket
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
source_map_stack_trace:
description:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
source_maps:
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.1"
source_span:
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
stack_trace:
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.1"
stream_channel:
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
string_scanner:
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4+1"
test:
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
utf:
description:
name: utf
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.0+3"
watcher:
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.7"
yaml:
description:
name: yaml
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.8"
sdk: ">=1.14.0 <1.16.0"

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);
});
}