diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1ef5319f..00000000 --- a/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.idea/workspace.xml -*.pyc -/perl6/lib/.precomp -/elixir/_build/ -python/.cache -python/.coverage -**/.idea diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index c764764b..00000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -GuildedRose \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 217af471..00000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf33..00000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index e206d70d..00000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 6e367118..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 75acca37..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b8..00000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 9d32e507..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Ada/README b/Ada/README.txt similarity index 100% rename from Ada/README rename to Ada/README.txt diff --git a/C/README b/C/README.txt similarity index 100% rename from C/README rename to C/README.txt diff --git a/Groovy/readme.txt b/Groovy/README.txt similarity index 100% rename from Groovy/readme.txt rename to Groovy/README.txt diff --git a/Java - Spock/.gitignore b/Java-Spock/.gitignore similarity index 100% rename from Java - Spock/.gitignore rename to Java-Spock/.gitignore diff --git a/Java - Spock/build.gradle b/Java-Spock/build.gradle similarity index 100% rename from Java - Spock/build.gradle rename to Java-Spock/build.gradle diff --git a/Java - Spock/gradle/wrapper/gradle-wrapper.jar b/Java-Spock/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from Java - Spock/gradle/wrapper/gradle-wrapper.jar rename to Java-Spock/gradle/wrapper/gradle-wrapper.jar diff --git a/Java - Spock/gradle/wrapper/gradle-wrapper.properties b/Java-Spock/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from Java - Spock/gradle/wrapper/gradle-wrapper.properties rename to Java-Spock/gradle/wrapper/gradle-wrapper.properties diff --git a/Java - Spock/gradlew b/Java-Spock/gradlew similarity index 100% rename from Java - Spock/gradlew rename to Java-Spock/gradlew diff --git a/Java - Spock/gradlew.bat b/Java-Spock/gradlew.bat similarity index 100% rename from Java - Spock/gradlew.bat rename to Java-Spock/gradlew.bat diff --git a/Java - Spock/src/main/java/com/gildedrose/GildedRose.java b/Java-Spock/src/main/java/com/gildedrose/GildedRose.java similarity index 100% rename from Java - Spock/src/main/java/com/gildedrose/GildedRose.java rename to Java-Spock/src/main/java/com/gildedrose/GildedRose.java diff --git a/Java - Spock/src/main/java/com/gildedrose/Item.java b/Java-Spock/src/main/java/com/gildedrose/Item.java similarity index 100% rename from Java - Spock/src/main/java/com/gildedrose/Item.java rename to Java-Spock/src/main/java/com/gildedrose/Item.java diff --git a/Java - Spock/src/main/java/com/gildedrose/TexttestFixture.java b/Java-Spock/src/main/java/com/gildedrose/TexttestFixture.java similarity index 100% rename from Java - Spock/src/main/java/com/gildedrose/TexttestFixture.java rename to Java-Spock/src/main/java/com/gildedrose/TexttestFixture.java diff --git a/Java - Spock/src/test/groovy/com/gildedrose/GildedRoseSpec.groovy b/Java-Spock/src/test/groovy/com/gildedrose/GildedRoseSpec.groovy similarity index 100% rename from Java - Spock/src/test/groovy/com/gildedrose/GildedRoseSpec.groovy rename to Java-Spock/src/test/groovy/com/gildedrose/GildedRoseSpec.groovy diff --git a/Smalltalk/GildedRose.st b/Smalltalk/GildedRose.st index 8be7cd18..863e99e2 100644 --- a/Smalltalk/GildedRose.st +++ b/Smalltalk/GildedRose.st @@ -1 +1,160 @@ -Object subclass: #GildedRose instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'GildedRose'! !GildedRose commentStamp: 'AndreasLeidig 4/21/2012 15:38' prior: 0! This Kata was originally created by Terry Hughes (http://twitter.com/#!!/TerryHughes). It is already on GitHub as "GildedRose", a sample project for C#. I could have forked it again, but I thought other language users might not want to download a whole C# project environment. In this repository are starting code samples for Java, Python, Ruby, C# and C++. See also http://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/ ==================== How to use this Kata ==================== The simplest way is to just clone the code and start hacking away improving the design. You'll want to look at the "Gilded Rose Background Reading" (below) which explains what the code is for. I strongly advise you that you'll also need some tests if you want to make sure you don't break the code while you refactor. You could write some unit tests yourself, using the Kata Background Reading (below) to identify suitable test cases. I've provided a failing unit test in a popular test framework as a starting point for most languages. Alternatively, use the "Text-Based" tests provided in this repository. (Read more about that in the next section) Whichever testing approach you choose, the idea of the exercise is to do some deliberate practice, and improve your Refactoring skills. The idea is not to re-write the code from scratch, but rather to practice taking small steps, running the tests often, and incrementally improving the design. ================== Text-Based Testing ================== This is a testing approach which is very useful when refactoring legacy code. The basic idea is to create tests that use the text which the code produces. Before you change the code, you run it, and save the output as a "Golden Copy". Then after you change the code, you run it again, and compare the output against the Golden Copy. Any differences, and the test fails. It's basically the same idea as "assertEquals(expected, actual)" in a unit test, except the text you are comparing is typically much longer, and the "expected" value is saved from actual output, rather than being defined in advance. Typically a piece of legacy code may not produce suitable textual output from the start, so you may need to modify it before you can write your first text-based test. That could involve inserting log statements into the code, or just writing a "main" method that executes the code and prints out what the result is afterwards. It's this latter approach we are using here to test GildedRose. The Text-Based tests in this repository are designed to be used with the tool "TextTest" (http://texttest.org). This tool helps you to organize and run text-based tests. There is more information in the README file in the "texttests" subdirectory. =================================== Gilded Rose Kata Background Reading =================================== Hi and welcome to team Gilded Rose. As you know, we are a small inn with a prime location in a prominent city ran by a friendly innkeeper named Allison. We also buy and sell only the finest goods. Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We have a system in place that updates our inventory for us. It was developed by a no-nonsense type named Leeroy, who has moved on to new adventures. Your task is to add the new feature to our system so that we can begin selling a new category of items. First an introduction to our system: - All items have a SellIn value which denotes the number of days we have to sell the item - All items have a Quality value which denotes how valuable the item is - At the end of each day our system lowers both values for every item Pretty simple, right? Well this is where it gets interesting: - Once the sell by date has passed, Quality degrades twice as fast - The Quality of an item is never negative - "Aged Brie" actually increases in Quality the older it gets - The Quality of an item is never more than 50 - "Sulfuras", being a legendary item, never has to be sold or decreases in Quality - "Backstage passes", like aged brie, increases in Quality as it's SellIn value approaches; Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but Quality drops to 0 after the concert We have recently signed a supplier of conjured items. This requires an update to our system: - "Conjured" items degrade in Quality twice as fast as normal items Feel free to make any changes to the UpdateQuality method and add any new code as long as everything still works correctly. However, do not alter the Item class or Items property as those belong to the goblin in the corner who will insta-rage and one-shot you as he doesn't believe in shared code ownership (you can make the UpdateQuality method and Items property static if you like, we'll cover for you). Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a legendary item and as such its Quality is 80 and it never alters.! !GildedRose methodsFor: 'API' stamp: 'AndreasLeidig 4/21/2012 17:02'! updateQualityFor: items items do: [:item | (item name ~= 'Aged Brie' and: [item name ~= 'Backstage passes to a TAFKAL80ETC concert']) ifTrue: [item quality > 0 ifTrue: [item name ~= 'Sulfuras, Hand of Ragnaros' ifTrue: [item quality: item quality - 1]]] ifFalse: [item quality < 50 ifTrue: [item quality: item quality + 1. item name = 'Backstage passes to a TAFKAL80ETC concert' ifTrue: [item sellIn < 11 ifTrue: [item quality < 50 ifTrue: [item quality: item quality + 1]]. item sellIn < 6 ifTrue: [item quality < 50 ifTrue: [item quality: item quality + 1]]]]]. item name ~= 'Sulfuras, Hand of Ragnaros' ifTrue: [item sellIn: item sellIn - 1]. item sellIn < 0 ifTrue: [item name ~= 'Aged Brie' ifTrue: [item name ~= 'Backstage passes to a TAFKAL80ETC concert' ifTrue: [item quality > 0 ifTrue: [item name ~= 'Sulfuras, Hand of Ragnaros' ifTrue: [item quality: item quality - 1]]] ifFalse: [item quality: item quality - item quality]] ifFalse: [item quality < 50 ifTrue: [item quality: item quality + 1]]]]! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! GildedRose class instanceVariableNames: ''! !GildedRose class methodsFor: 'run Example' stamp: 'AndreasLeidig 4/21/2012 20:26'! runExamples "GildedRose runExamples" | items gildedRose | items := OrderedCollection new add: (Item new name: '+5 Dexterity Vest'; sellIn: 10; quality: 20; yourself); add: (Item new name: 'Aged Brie'; sellIn: 2; quality: 0; yourself); add: (Item new name: 'Elixir of the Mongoose'; sellIn: 5; quality: 7; yourself); add: (Item new name: 'Sulfuras, Hand of Ragnaros'; sellIn: 0; quality: 80; yourself); add: (Item new name: 'Sulfuras, Hand of Ragnaros'; sellIn: -1; quality: 80; yourself); add: (Item new name: 'Backstage passes to a TAFKAL80ETC concert'; sellIn: 15; quality: 20; yourself); add: (Item new name: 'Backstage passes to a TAFKAL80ETC concert'; sellIn: 10; quality: 49; yourself); add: (Item new name: 'Backstage passes to a TAFKAL80ETC concert'; sellIn: 5; quality: 49; yourself); add: (Item new name: 'Conjured Mana Cake'; sellIn: 3; quality: 6; yourself); "this conjured item does not work properly yet" yourself. gildedRose := GildedRose new. Transcript show: 'OMGHAI!!'; cr. 0 to: 30 do: [:idx | Transcript show: '-------- day ' , idx printString , ' --------'; cr; show: 'name, sellIn, quality'; cr. items do: [:item | Transcript show: item name , ', ' , item sellIn printString , ', ' , item quality printString; cr]. Transcript cr. gildedRose updateQualityFor: items]. Transcript cr! ! Object subclass: #Item instanceVariableNames: 'name sellIn quality' classVariableNames: '' poolDictionaries: '' category: 'GildedRose'! !Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:40'! name ^name! ! !Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:41'! name: aString name := aString! ! !Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:41'! quality ^quality! ! !Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:42'! quality: aNumber quality := aNumber! ! !Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:41'! sellIn ^sellIn! ! !Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:42'! sellIn: aNumber sellIn := aNumber ! ! \ No newline at end of file +Object subclass: #GildedRose + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'GildedRose'! +!GildedRose commentStamp: 'AndreasLeidig 4/21/2012 15:38' prior: 0! +This Kata was originally created by Terry Hughes (http://twitter.com/#!!/TerryHughes). It is already on GitHub as "GildedRose", a sample project for C#. I could have forked it again, but I thought other language users might not want to download a whole C# project environment. In this repository are starting code samples for Java, Python, Ruby, C# and C++. + +See also http://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/ + +==================== +How to use this Kata +==================== + +The simplest way is to just clone the code and start hacking away improving the design. You'll want to look at the "Gilded Rose Background Reading" (below) which explains what the code is for. I strongly advise you that you'll also need some tests if you want to make sure you don't break the code while you refactor. + +You could write some unit tests yourself, using the Kata Background Reading (below) to identify suitable test cases. I've provided a failing unit test in a popular test framework as a starting point for most languages. + +Alternatively, use the "Text-Based" tests provided in this repository. (Read more about that in the next section) + +Whichever testing approach you choose, the idea of the exercise is to do some deliberate practice, and improve your Refactoring skills. The idea is not to re-write the code from scratch, but rather to practice taking small steps, running the tests often, and incrementally improving the design. + +================== +Text-Based Testing +================== + +This is a testing approach which is very useful when refactoring legacy code. The basic idea is to create tests that use the text which the code produces. Before you change the code, you run it, and save the output as a "Golden Copy". Then after you change the code, you run it again, and compare the output against the Golden Copy. Any differences, and the test fails. + +It's basically the same idea as "assertEquals(expected, actual)" in a unit test, except the text you are comparing is typically much longer, and the "expected" value is saved from actual output, rather than being defined in advance. + +Typically a piece of legacy code may not produce suitable textual output from the start, so you may need to modify it before you can write your first text-based test. That could involve inserting log statements into the code, or just writing a "main" method that executes the code and prints out what the result is afterwards. It's this latter approach we are using here to test GildedRose. + +The Text-Based tests in this repository are designed to be used with the tool "TextTest" (http://texttest.org). This tool helps you to organize and run text-based tests. There is more information in the README file in the "texttests" subdirectory. + +=================================== +Gilded Rose Kata Background Reading +=================================== + +Hi and welcome to team Gilded Rose. As you know, we are a small inn with a prime location in a prominent city ran by a friendly innkeeper named Allison. We also buy and sell only the finest goods. Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We have a system in place that updates our inventory for us. It was developed by a no-nonsense type named Leeroy, who has moved on to new adventures. Your task is to add the new feature to our system so that we can begin selling a new category of items. First an introduction to our system: + + - All items have a SellIn value which denotes the number of days we have to sell the item + - All items have a Quality value which denotes how valuable the item is + - At the end of each day our system lowers both values for every item + +Pretty simple, right? Well this is where it gets interesting: + + - Once the sell by date has passed, Quality degrades twice as fast + - The Quality of an item is never negative + - "Aged Brie" actually increases in Quality the older it gets + - The Quality of an item is never more than 50 + - "Sulfuras", being a legendary item, never has to be sold or decreases in Quality + - "Backstage passes", like aged brie, increases in Quality as it's SellIn value approaches; Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but Quality drops to 0 after the concert + +We have recently signed a supplier of conjured items. This requires an update to our system: + + - "Conjured" items degrade in Quality twice as fast as normal items + +Feel free to make any changes to the UpdateQuality method and add any new code as long as everything still works correctly. However, do not alter the Item class or Items property as those belong to the goblin in the corner who will insta-rage and one-shot you as he doesn't believe in shared code ownership (you can make the UpdateQuality method and Items property static if you like, we'll cover for you). + +Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a legendary item and as such its Quality is 80 and it never alters.! + + +!GildedRose methodsFor: 'API' stamp: 'AndreasLeidig 4/21/2012 17:02'! +updateQualityFor: items + items + do: [:item | + (item name ~= 'Aged Brie' + and: [item name ~= 'Backstage passes to a TAFKAL80ETC concert']) + ifTrue: [item quality > 0 + ifTrue: [item name ~= 'Sulfuras, Hand of Ragnaros' + ifTrue: [item quality: item quality - 1]]] + ifFalse: [item quality < 50 + ifTrue: [item quality: item quality + 1. + item name = 'Backstage passes to a TAFKAL80ETC concert' + ifTrue: [item sellIn < 11 + ifTrue: [item quality < 50 + ifTrue: [item quality: item quality + 1]]. + item sellIn < 6 + ifTrue: [item quality < 50 + ifTrue: [item quality: item quality + 1]]]]]. + item name ~= 'Sulfuras, Hand of Ragnaros' + ifTrue: [item sellIn: item sellIn - 1]. + item sellIn < 0 + ifTrue: [item name ~= 'Aged Brie' + ifTrue: [item name ~= 'Backstage passes to a TAFKAL80ETC concert' + ifTrue: [item quality > 0 + ifTrue: [item name ~= 'Sulfuras, Hand of Ragnaros' + ifTrue: [item quality: item quality - 1]]] + ifFalse: [item quality: item quality - item quality]] + ifFalse: [item quality < 50 + ifTrue: [item quality: item quality + 1]]]]! ! + +"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! + +GildedRose class + instanceVariableNames: ''! + +!GildedRose class methodsFor: 'run Example' stamp: 'AndreasLeidig 4/21/2012 20:26'! +runExamples + "GildedRose runExamples" + | items gildedRose | + items := OrderedCollection new + add: (Item new name: '+5 Dexterity Vest'; sellIn: 10; quality: 20; yourself); + add: (Item new name: 'Aged Brie'; sellIn: 2; quality: 0; yourself); + add: (Item new name: 'Elixir of the Mongoose'; sellIn: 5; quality: 7; yourself); + add: (Item new name: 'Sulfuras, Hand of Ragnaros'; sellIn: 0; quality: 80; yourself); + add: (Item new name: 'Sulfuras, Hand of Ragnaros'; sellIn: -1; quality: 80; yourself); + add: (Item new name: 'Backstage passes to a TAFKAL80ETC concert'; sellIn: 15; quality: 20; yourself); + add: (Item new name: 'Backstage passes to a TAFKAL80ETC concert'; sellIn: 10; quality: 49; yourself); + add: (Item new name: 'Backstage passes to a TAFKAL80ETC concert'; sellIn: 5; quality: 49; yourself); + add: (Item new name: 'Conjured Mana Cake'; sellIn: 3; quality: 6; yourself); "this conjured item does not work properly yet" + yourself. + + gildedRose := GildedRose new. + Transcript show: 'OMGHAI!!'; + cr. + 0 to: 30 do: [:idx | + Transcript show: '-------- day ' , idx printString , ' --------'; + cr; + show: 'name, sellIn, quality'; + cr. + items + do: [:item | + Transcript show: item name , ', ' , item sellIn printString , ', ' , item quality printString; + cr]. + Transcript cr. + gildedRose updateQualityFor: items]. + Transcript cr! ! + + +Object subclass: #Item + instanceVariableNames: 'name sellIn quality' + classVariableNames: '' + poolDictionaries: '' + category: 'GildedRose'! + +!Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:40'! +name + ^name! ! + +!Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:41'! +name: aString + name := aString! ! + +!Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:41'! +quality + ^quality! ! + +!Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:42'! +quality: aNumber + quality := aNumber! ! + +!Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:41'! +sellIn + ^sellIn! ! + +!Item methodsFor: 'accessing' stamp: 'AndreasLeidig 4/21/2012 15:42'! +sellIn: aNumber + sellIn := aNumber + ! ! diff --git a/TypeScript/package.json b/TypeScript/package.json index 28b6bb3f..4494c786 100644 --- a/TypeScript/package.json +++ b/TypeScript/package.json @@ -1,17 +1,14 @@ { - "name": "typescript-mocha-kata-seed", - "version": "1.4.0", - "description": "Seed project for TDD code katas on TypeScript and mocha", - "main": "index.js", + "name": "gilded-rose-kata", + "version": "1.0.0", + "description": "Gilded Rose kata in TypeScript", "scripts": { "precompile": "rimraf app/**/*.js test/**/*.js", "compile": "tsc", "pretest": "rimraf app/**/*.js test/**/*.js", "test": "nyc mocha" }, - "author": "paucls", - "homepage": "https://github.com/paucls/typescript-mocha-kata-seed", - "license": "ISC", + "license": "MIT", "private": true, "devDependencies": { "@types/chai": "~3.5.2", @@ -21,8 +18,9 @@ "mocha": "~3.2.0", "nyc": "~11.0.3", "rimraf": "~2.5.2", + "source-map-support": "0.5.9", "ts-node": "~3.1.0", - "typescript": "~2.2.0" + "typescript": "~3.0.3" }, "nyc": { "extension": [ diff --git a/TypeScript/tsconfig.json b/TypeScript/tsconfig.json index 4f713921..84381f86 100644 --- a/TypeScript/tsconfig.json +++ b/TypeScript/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "module": "commonjs", "target": "es5", + "strict": true, "noImplicitAny": false, "sourceMap": false }, diff --git a/cpp/README b/cpp/README.md similarity index 100% rename from cpp/README rename to cpp/README.md diff --git a/elixir/.gitignore b/elixir/.gitignore new file mode 100644 index 00000000..69fa449d --- /dev/null +++ b/elixir/.gitignore @@ -0,0 +1 @@ +_build/ diff --git a/go/readme.md b/go/README.md similarity index 80% rename from go/readme.md rename to go/README.md index 6b894ed4..e22e3776 100644 --- a/go/readme.md +++ b/go/README.md @@ -3,7 +3,7 @@ - Run : ```shell -go run gilded-rose.go +go run texttest_fixture.go gilded-rose.go ``` - Run tests : diff --git a/go/gilded-rose.go b/go/gilded-rose.go index c5f35822..57d2f189 100644 --- a/go/gilded-rose.go +++ b/go/gilded-rose.go @@ -1,28 +1,11 @@ package main -import "fmt" - type Item struct { name string sellIn, quality int } -var items = []Item{ - Item{"+5 Dexterity Vest", 10, 20}, - Item{"Aged Brie", 2, 0}, - Item{"Elixir of the Mongoose", 5, 7}, - Item{"Sulfuras, Hand of Ragnaros", 0, 80}, - Item{"Backstage passes to a TAFKAL80ETC concert", 15, 20}, - Item{"Conjured Mana Cake", 3, 6}, -} - -func main() { - fmt.Println("OMGHAI!") - // fmt.Print(items) - GildedRose() -} - -func GildedRose() { +func UpdateQuality(items []*Item) { for i := 0; i < len(items); i++ { if items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert" { diff --git a/go/gilded-rose_test.go b/go/gilded-rose_test.go index 6b03bf25..24d64bdd 100644 --- a/go/gilded-rose_test.go +++ b/go/gilded-rose_test.go @@ -2,6 +2,14 @@ package main import "testing" -func Test_GildedRose(t *testing.T) { - main() +func Test_Foo(t *testing.T) { + var items = []*Item{ + &Item{"foo", 0, 0}, + } + + UpdateQuality(items) + + if items[0].name != "fixme" { + t.Errorf("Name: Expected %s but got %s ", "fixme", items[0].name) + } } diff --git a/go/texttest_fixture.go b/go/texttest_fixture.go new file mode 100644 index 00000000..a5b47a77 --- /dev/null +++ b/go/texttest_fixture.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "os" + "strconv" +) + +func main() { + fmt.Println("OMGHAI!") + + var items = []*Item{ + &Item{"+5 Dexterity Vest", 10, 20}, + &Item{"Aged Brie", 2, 0}, + &Item{"Elixir of the Mongoose", 5, 7}, + &Item{"Sulfuras, Hand of Ragnaros", 0, 80}, + &Item{"Sulfuras, Hand of Ragnaros", -1, 80}, + &Item{"Backstage passes to a TAFKAL80ETC concert", 15, 20}, + &Item{"Backstage passes to a TAFKAL80ETC concert", 10, 49}, + &Item{"Backstage passes to a TAFKAL80ETC concert", 5, 49}, + &Item{"Conjured Mana Cake", 3, 6}, // <-- :O + } + + days := 2 + var err error + if len(os.Args) > 1 { + days, err = strconv.Atoi(os.Args[1]) + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + days++ + } + + for day := 0; day < days; day++ { + fmt.Printf("-------- day %d --------\n", day) + fmt.Println("name, sellIn, quality") + for i := 0; i < len(items); i++ { + fmt.Println(items[i]) + } + fmt.Println("") + UpdateQuality(items) + } +} diff --git a/js/jasmine/.gitignore b/js-jasmine/.gitignore similarity index 100% rename from js/jasmine/.gitignore rename to js-jasmine/.gitignore diff --git a/js/jasmine/package.json b/js-jasmine/package.json similarity index 59% rename from js/jasmine/package.json rename to js-jasmine/package.json index 8f2ab748..2087266e 100644 --- a/js/jasmine/package.json +++ b/js-jasmine/package.json @@ -1,7 +1,7 @@ { - "name": "gilded-rose", + "name": "gilded-rose-kata", "version": "1.0.0", - "description": "gilded rose kata in javascript", + "description": "Gilded Rose kata in Javascript with Jasmine", "scripts": { "test": "jasmine" }, @@ -19,8 +19,21 @@ "bugs": { "url": "https://github.com/emilybache/GildedRose-Refactoring-Kata/issues" }, - "homepage": "https://github.com/emilybache/GildedRose-Refactoring-Kata#readme", + "homepage": "https://github.com/emilybache/GildedRose-Refactoring-Kata", "devDependencies": { + "babel-core": "^6.26.0", + "babel-preset-env": "1.7.0", + "babel-register": "^6.26.0", "jasmine": "^3.2.0" + }, + "babel": { + "presets": [ + [ + "env", { + "targets": { "node": "current" } + } + ] + ], + "plugins": [] } } diff --git a/js/jasmine/spec/gilded_rose_spec.js b/js-jasmine/spec/gilded_rose_spec.js similarity index 100% rename from js/jasmine/spec/gilded_rose_spec.js rename to js-jasmine/spec/gilded_rose_spec.js diff --git a/js-jasmine/spec/support/jasmine.json b/js-jasmine/spec/support/jasmine.json new file mode 100644 index 00000000..cfed10fd --- /dev/null +++ b/js-jasmine/spec/support/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "**/*[sS]pec.js" + ], + "helpers": [ + "../node_modules/babel-register/lib/node.js" + ], + "oneFailurePerSpec": false, + "randomizeTests": true +} diff --git a/js/jasmine/src/gilded_rose.js b/js-jasmine/src/gilded_rose.js similarity index 100% rename from js/jasmine/src/gilded_rose.js rename to js-jasmine/src/gilded_rose.js diff --git a/js/mocha/.gitignore b/js-mocha/.gitignore similarity index 100% rename from js/mocha/.gitignore rename to js-mocha/.gitignore diff --git a/js/mocha/package.json b/js-mocha/package.json similarity index 73% rename from js/mocha/package.json rename to js-mocha/package.json index 1f2ede94..391b48c3 100644 --- a/js/mocha/package.json +++ b/js-mocha/package.json @@ -1,9 +1,9 @@ { - "name": "gilded-rose", + "name": "gilded-rose-kata", "version": "1.0.0", - "description": "gilded rose kata in javascript", + "description": "Gilded Rose kata in Javascript with Mocha", "scripts": { - "test": "mocha" + "test": "mocha --compilers js:babel/register" }, "repository": { "type": "git", @@ -19,8 +19,9 @@ "bugs": { "url": "https://github.com/emilybache/GildedRose-Refactoring-Kata/issues" }, - "homepage": "https://github.com/emilybache/GildedRose-Refactoring-Kata#readme", + "homepage": "https://github.com/emilybache/GildedRose-Refactoring-Kata", "devDependencies": { + "babel": "^5.8.23", "chai": "^4.2.0", "mocha": "^5.2.0" } diff --git a/js/mocha/src/gilded_rose.js b/js-mocha/src/gilded_rose.js similarity index 100% rename from js/mocha/src/gilded_rose.js rename to js-mocha/src/gilded_rose.js diff --git a/js/mocha/test/test_gilded_rose.js b/js-mocha/test/test_gilded_rose.js similarity index 100% rename from js/mocha/test/test_gilded_rose.js rename to js-mocha/test/test_gilded_rose.js diff --git a/js/jasmine/package-lock.json b/js/jasmine/package-lock.json deleted file mode 100644 index be3709d4..00000000 --- a/js/jasmine/package-lock.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "name": "gilded-rose", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true - }, - "jasmine": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.2.0.tgz", - "integrity": "sha512-qv6TZ32r+slrQz8fbx2EhGbD9zlJo3NwPrpLK1nE8inILtZO9Fap52pyHk7mNTh4tG50a+1+tOiWVT3jO5I0Sg==", - "dev": true, - "requires": { - "glob": "7.1.2", - "jasmine-core": "3.2.1" - } - }, - "jasmine-core": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.2.1.tgz", - "integrity": "sha512-pa9tbBWgU0EE4SWgc85T4sa886ufuQdsgruQANhECYjwqgV4z7Vw/499aCaP8ZH79JDS4vhm8doDG9HO4+e4sA==", - "dev": true - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "requires": { - "brace-expansion": "1.1.11" - } - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - } - } -} diff --git a/js/jasmine/spec/support/jasmine.json b/js/jasmine/spec/support/jasmine.json deleted file mode 100644 index 370fc446..00000000 --- a/js/jasmine/spec/support/jasmine.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "spec_dir": "spec", - "spec_files": [ - "**/*[sS]pec.js" - ], - "helpers": [ - "helpers/**/*.js" - ], - "stopSpecOnExpectationFailure": false, - "random": true -} diff --git a/js/mocha/package-lock.json b/js/mocha/package-lock.json deleted file mode 100644 index 60c64c1c..00000000 --- a/js/mocha/package-lock.json +++ /dev/null @@ -1,249 +0,0 @@ -{ - "name": "gilded-rose", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true - }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, - "browser-stdout": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", - "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", - "dev": true - }, - "chai": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", - "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", - "dev": true, - "requires": { - "assertion-error": "1.1.0", - "check-error": "1.0.2", - "deep-eql": "3.0.1", - "get-func-name": "2.0.0", - "pathval": "1.1.0", - "type-detect": "4.0.8" - } - }, - "check-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", - "dev": true - }, - "commander": { - "version": "2.15.1", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", - "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "deep-eql": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", - "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", - "dev": true, - "requires": { - "type-detect": "4.0.8" - } - }, - "diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", - "dev": true - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", - "dev": true - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "growl": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", - "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", - "dev": true - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "he": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", - "dev": true - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "requires": { - "brace-expansion": "1.1.11" - } - }, - "minimist": { - "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - } - }, - "mocha": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", - "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", - "dev": true, - "requires": { - "browser-stdout": "1.3.1", - "commander": "2.15.1", - "debug": "3.1.0", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.5", - "he": "1.1.1", - "minimatch": "3.0.4", - "mkdirp": "0.5.1", - "supports-color": "5.4.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "pathval": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", - "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", - "dev": true - }, - "supports-color": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", - "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", - "dev": true, - "requires": { - "has-flag": "3.0.0" - } - }, - "type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - } - } -} diff --git a/perl6/.gitignore b/perl6/.gitignore new file mode 100644 index 00000000..4a5e4c71 --- /dev/null +++ b/perl6/.gitignore @@ -0,0 +1 @@ +lib/.precomp diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 00000000..8a0ce6bc --- /dev/null +++ b/python/.gitignore @@ -0,0 +1,5 @@ +*.pyc +.cache +.coverage +.idea/ +*.iml diff --git a/scheme/README.md b/scheme/README.md new file mode 100644 index 00000000..0318ef54 --- /dev/null +++ b/scheme/README.md @@ -0,0 +1,18 @@ +# Scheme port of the Gilded-Rose Kata + +This is a (Gambit) R5RS Scheme port of the *Gilded-Rose-Kata*. + +## Building and Running + +```shell +gsi texttest-fixture.scm +``` + +## Unit Test + +`assert.scm` is a minimalist implementation of xUnit in Scheme style. +There are two assertions available, e.g. `(assert=)` and `(assert-string=)`. + +```shell +gsi gilded-rose-test.scm +``` diff --git a/scheme/assert.scm b/scheme/assert.scm new file mode 100644 index 00000000..99828669 --- /dev/null +++ b/scheme/assert.scm @@ -0,0 +1,58 @@ +;;; +;;; Unit test framework for Scheme +;;; Copyright (c) 2018, Peter Kofler, http://www.code-cop.org/ +;;; BSD licensed. +;;; +;;; Non S5RS used functions: +;;; * (error) from R6RS +;;; + +;; SchemeUnit from http://c2.com/cgi/wiki?SchemeUnit + +(define (fail msg) + (error (string-append "AssertionError" ": " msg))) + +(define (check msg condition) + (if (not condition) + (fail msg) + #t)) + +(define (assert msg condition) + (lambda () (check msg condition))) + +;; extensions + +;; private +(define (make-string-message prefix to-string expected actual) + (make-message prefix + (to-string expected) + (to-string actual))) + +;; private +(define (make-message prefix expected actual) + (string-append prefix "expected:<" expected "> but was:<" actual ">")) + +(define (assert-equal to-string eq-op expected actual) + (assert (make-string-message "" to-string expected actual) + (eq-op expected actual))) + +(define (assert= expected actual) + (assert-equal number->string = expected actual)) + +(define (assert-string= expected actual) + (assert-equal values string=? expected actual)) + +;; private +(define (test-case-name name) + (display name) + (display " ... ")) + +;; private +(define (test-case-success) + (display "OK") + (newline)) + +(define (test-case name . assertions) + (test-case-name name) + (for-each (lambda (a) (a)) assertions) + (test-case-success)) diff --git a/scheme/gilded-rose-test.scm b/scheme/gilded-rose-test.scm new file mode 100644 index 00000000..b0d67e09 --- /dev/null +++ b/scheme/gilded-rose-test.scm @@ -0,0 +1,7 @@ +(include "assert.scm") +(include "gilded-rose.scm") + +(test-case "foo" + (let ((items (list (make-item "foo" 0 0)))) + (update-quality items) + (assert-string= "fixme" (item-name (car items))))) diff --git a/scheme/gilded-rose.scm b/scheme/gilded-rose.scm new file mode 100644 index 00000000..dac984fa --- /dev/null +++ b/scheme/gilded-rose.scm @@ -0,0 +1,46 @@ +;;; Class ITEM + +(define-record-type item (make-item name sell-in quality) item? name sell-in quality) +;; define-record-type ... SRFI-9 +;; creates make-item, item?, item-name, item-sell-in, item-quality, item-name-set!, item-sell-in-set!, item-quality-set! + +(define (item-to-string item) + (string-append (item-name item) + ", " + (number->string (item-sell-in item)) + ", " + (number->string (item-quality item)))) + +;;; GILDED-ROSE + +(define (update-quality items) + (for-each + (lambda (item) + (if (and (not (string=? (item-name item) "Aged Brie")) + (not (string=? (item-name item) "Backstage passes to a TAFKAL80ETC concert"))) + (if (> (item-quality item) 0) + (if (not (string=? (item-name item) "Sulfuras, Hand of Ragnaros")) + (item-quality-set! item (- (item-quality item) 1)))) + (cond ((< (item-quality item) 50) + (item-quality-set! item (+ (item-quality item) 1)) + (if (string=? (item-name item) "Backstage passes to a TAFKAL80ETC concert") + (if (< (item-sell-in item) 11) + (cond ((< (item-quality item) 50) + (item-quality-set! item (+ (item-quality item) 1)) + (if (< (item-sell-in item) 6) + (if (< (item-quality item) 50) + (item-quality-set! item (+ (item-quality item) 1))))))))))) + + (if (not (string=? (item-name item) "Sulfuras, Hand of Ragnaros")) + (item-sell-in-set! item (- (item-sell-in item) 1))) + + (if (< (item-sell-in item) 0) + (if (not (string=? (item-name item) "Aged Brie")) + (if (not (string=? (item-name item) "Backstage passes to a TAFKAL80ETC concert")) + (if (> (item-quality item) 0) + (if (not (string=? (item-name item) "Sulfuras, Hand of Ragnaros")) + (item-quality-set! item (- (item-quality item) 1)))) + (item-quality-set! item (- (item-quality item) (item-quality item)))) + (if (< (item-quality item) 50) + (item-quality-set! item (+ (item-quality item) 1)))))) + items)) diff --git a/scheme/texttest-fixture.scm b/scheme/texttest-fixture.scm new file mode 100644 index 00000000..ee15981e --- /dev/null +++ b/scheme/texttest-fixture.scm @@ -0,0 +1,32 @@ +(include "gilded-rose.scm") + +(display "OMGHAI!") +(newline) + +(let ((items (list (make-item "+5 Dexterity Vest" 10 20) + (make-item "Aged Brie" 2 0) + (make-item "Elixir of the Mongoose" 5 7) + (make-item "Sulfuras, Hand of Ragnaros" 0 80) + (make-item "Sulfuras, Hand of Ragnaros" -1 80) + (make-item "Backstage passes to a TAFKAL80ETC concert" 15 20) + (make-item "Backstage passes to a TAFKAL80ETC concert" 10 49) + (make-item "Backstage passes to a TAFKAL80ETC concert" 5 49) + ;; this conjured item does not work properly yet + (make-item "Conjured Mana Cake" 3 6))) + (days 2)) + + (define (loop day) + (cond ((< day days) + (display (string-append "-------- day " (number->string day) " --------")) + (newline) + (display "name, sell-in, quality") + (newline) + (for-each + (lambda (item) + (display (item-to-string item)) + (newline)) + items) + (newline) + (update-quality items) + (loop (+ day 1))))) + (loop 0))