Merge pull request #580 from codecop/master

Port to Io language.
This commit is contained in:
Emily Bache 2024-12-13 08:14:09 +01:00 committed by GitHub
commit c4cfa7b38e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 177 additions and 0 deletions

8
io/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# C build
.transaction_lock
_bin
_build
_packs
# Docio generated
docs/

21
io/README.md Normal file
View File

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

65
io/io/GildedRose.io Normal file
View File

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

19
io/io/Item.io Normal file
View File

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

15
io/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "gilded-rose-kata",
"version": "0.1.0",
"readme": "README.md",
"protos": [
"GildedRose",
"Item"
],
"dependencies": {
"libs": [],
"headers": [],
"protos": [],
"packages": []
}
}

View File

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

View File

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

View File

@ -0,0 +1,2 @@
#!/usr/bin/env io
TestSuite clone setPath(System launchPath) run