diff --git a/io/.gitignore b/io/.gitignore new file mode 100644 index 00000000..f6089532 --- /dev/null +++ b/io/.gitignore @@ -0,0 +1,8 @@ +# C build +.transaction_lock +_bin +_build +_packs + +# Docio generated +docs/ diff --git a/io/README.md b/io/README.md new file mode 100644 index 00000000..1071fedf --- /dev/null +++ b/io/README.md @@ -0,0 +1,21 @@ +# Gilded Rose starting position in Io + +## Run the unit tests from the Command-Line + +```shell +io ./tests/correctness/run.io +``` + +## Run the TextTest Fixture from Command-Line + +```shell +io ./tests/correctness/TexttestFixture.io +``` + +### Specify Number of Days + +For e.g. 10 days: + +```shell +io ./tests/correctness/TexttestFixture.io 10 +``` diff --git a/io/io/GildedRose.io b/io/io/GildedRose.io new file mode 100644 index 00000000..cace3a17 --- /dev/null +++ b/io/io/GildedRose.io @@ -0,0 +1,65 @@ +GildedRose := Object clone do( + + init := method( + self items := list() + ) + + with := method(items, + result := self clone + result items = items + result + ) + + updateQuality := method( + for(i, 0, items size - 1, + if (items at(i) name != "Aged Brie" and + items at(i) name != "Backstage passes to a TAFKAL80ETC concert", + if (items at(i) quality > 0, + if (items at(i) name != "Sulfuras, Hand of Ragnaros", + items at(i) quality = items at(i) quality - 1 + ) + ) + , + if (items at(i) quality < 50, + items at(i) quality = items at(i) quality + 1 + + if (items at(i) name == "Backstage passes to a TAFKAL80ETC concert", + if (items at(i) sellIn < 11, + if (items at(i) quality < 50, + items at(i) quality = items at(i) quality + 1 + ) + ) + + if (items at(i) sellIn < 6, + if (items at(i) quality < 50, + items at(i) quality = items at(i) quality + 1 + ) + ) + ) + ) + ) + + if (items at(i) name != "Sulfuras, Hand of Ragnaros", + items at(i) sellIn = items at(i) sellIn - 1 + ) + + if (items at(i) sellIn < 0, + if (items at(i) name != "Aged Brie", + if (items at(i) name != "Backstage passes to a TAFKAL80ETC concert", + if (items at(i) quality > 0, + if (items at(i) name != "Sulfuras, Hand of Ragnaros", + items at(i) quality = items at(i) quality - 1 + ) + ) + , + items at(i) quality = items at(i) quality - items at(i) quality + ) + , + if (items at(i) quality < 50, + items at(i) quality = items at(i) quality + 1 + ) + ) + ) + ) + ) +) diff --git a/io/io/Item.io b/io/io/Item.io new file mode 100644 index 00000000..0f683975 --- /dev/null +++ b/io/io/Item.io @@ -0,0 +1,19 @@ +Item := Object clone do( + + name := "" + sellIn := 0 + quality := 0 + + with := method(name, sellIn, quality, + result := self clone + result name = name + result sellIn = sellIn + result quality = quality + result + ) + + asString = method( + self name .. ", " .. self sellIn .. ", " .. self quality + ) + +) diff --git a/io/package.json b/io/package.json new file mode 100644 index 00000000..8e17fd09 --- /dev/null +++ b/io/package.json @@ -0,0 +1,15 @@ +{ + "name": "gilded-rose-kata", + "version": "0.1.0", + "readme": "README.md", + "protos": [ + "GildedRose", + "Item" + ], + "dependencies": { + "libs": [], + "headers": [], + "protos": [], + "packages": [] + } +} \ No newline at end of file diff --git a/io/tests/correctness/GildedRoseTest.io b/io/tests/correctness/GildedRoseTest.io new file mode 100644 index 00000000..3d0f5009 --- /dev/null +++ b/io/tests/correctness/GildedRoseTest.io @@ -0,0 +1,13 @@ +doRelativeFile("../../io/Item.io") +doRelativeFile("../../io/GildedRose.io") + +GildedRoseTest := UnitTest clone do( + + testFoo := method( + items := list( Item with("foo", 0, 0) ) + app := GildedRose with(items) + app updateQuality + assertEquals("fixme", app items at(0) name) + ) + +) diff --git a/io/tests/correctness/TexttestFixture.io b/io/tests/correctness/TexttestFixture.io new file mode 100644 index 00000000..ecc6f7bd --- /dev/null +++ b/io/tests/correctness/TexttestFixture.io @@ -0,0 +1,34 @@ +doRelativeFile("../../io/Item.io") +doRelativeFile("../../io/GildedRose.io") + +writeln("OMGHAI!") + +items := list( + Item with("+5 Dexterity Vest", 10, 20), // + Item with("Aged Brie", 2, 0), // + Item with("Elixir of the Mongoose", 5, 7), // + Item with("Sulfuras, Hand of Ragnaros", 0, 80), // + Item with("Sulfuras, Hand of Ragnaros", -1, 80), + Item with("Backstage passes to a TAFKAL80ETC concert", 15, 20), + Item with("Backstage passes to a TAFKAL80ETC concert", 10, 49), + Item with("Backstage passes to a TAFKAL80ETC concert", 5, 49), + // this conjured item does not work properly yet + Item with("Conjured Mana Cake", 3, 6) +) + +app := GildedRose with(items) + +days := 2 +if (System args size > 1, + days = System args at(1) asNumber + 1 +) + +for(i, 0, days - 1, + writeln("-------- day " .. i .. " --------") + writeln("name, sellIn, quality") + items foreach(item, + writeln(item) + ) + writeln + app updateQuality +) diff --git a/io/tests/correctness/run.io b/io/tests/correctness/run.io new file mode 100644 index 00000000..57d03a51 --- /dev/null +++ b/io/tests/correctness/run.io @@ -0,0 +1,2 @@ +#!/usr/bin/env io +TestSuite clone setPath(System launchPath) run