From 1406987c447442958085f0b710ee2b381147b785 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Fri, 13 Dec 2024 00:27:13 +0100 Subject: [PATCH 1/3] Empty Io project. --- io/.gitignore | 8 ++++++++ io/README.md | 21 +++++++++++++++++++++ io/package.json | 15 +++++++++++++++ io/tests/correctness/run.io | 2 ++ 4 files changed, 46 insertions(+) create mode 100644 io/.gitignore create mode 100644 io/README.md create mode 100644 io/package.json create mode 100644 io/tests/correctness/run.io 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..df1c741b --- /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/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/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 From a91a6ef6953f40308bad17d8c5bfc5ffca000c16 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Fri, 13 Dec 2024 01:33:28 +0100 Subject: [PATCH 2/3] Initial port. --- io/io/GildedRose.io | 65 ++++++++++++++++++++++++++ io/io/Item.io | 19 ++++++++ io/tests/correctness/GildedRoseTest.io | 13 ++++++ 3 files changed, 97 insertions(+) create mode 100644 io/io/GildedRose.io create mode 100644 io/io/Item.io create mode 100644 io/tests/correctness/GildedRoseTest.io 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/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) + ) + +) From 3b7cb71b7781a1d4c282824be88cdf0258ae1357 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Fri, 13 Dec 2024 01:46:44 +0100 Subject: [PATCH 3/3] Port TextTestFixture. --- io/README.md | 6 ++--- io/tests/correctness/TexttestFixture.io | 34 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 io/tests/correctness/TexttestFixture.io diff --git a/io/README.md b/io/README.md index df1c741b..1071fedf 100644 --- a/io/README.md +++ b/io/README.md @@ -3,13 +3,13 @@ ## Run the unit tests from the Command-Line ```shell -io tests/correctness/run.io +io ./tests/correctness/run.io ``` ## Run the TextTest Fixture from Command-Line ```shell -io tests/correctness/TexttestFixture.io +io ./tests/correctness/TexttestFixture.io ``` ### Specify Number of Days @@ -17,5 +17,5 @@ io tests/correctness/TexttestFixture.io For e.g. 10 days: ```shell -io tests/correctness/TexttestFixture.io 10 +io ./tests/correctness/TexttestFixture.io 10 ``` 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 +)