From b8233e291d6177b7ca51ffd177c2284e18fc680a Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 20:31:26 +0100 Subject: [PATCH 01/16] Moves language specific Git ignores into language subfolders. --- .gitignore | 7 ------- elixir/.gitignore | 1 + perl6/.gitignore | 1 + python/.gitignore | 5 +++++ 4 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 .gitignore create mode 100644 elixir/.gitignore create mode 100644 perl6/.gitignore create mode 100644 python/.gitignore 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/elixir/.gitignore b/elixir/.gitignore new file mode 100644 index 00000000..69fa449d --- /dev/null +++ b/elixir/.gitignore @@ -0,0 +1 @@ +_build/ 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 From c41d122512d05b2c9fbc6633297469c4f6631817 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 20:32:26 +0100 Subject: [PATCH 02/16] Drops IntelliJ Idea configuration for Java because Java code is Maven project now, no special treatmeent needed. --- .idea/.name | 1 - .idea/compiler.xml | 23 ----------------------- .idea/copyright/profiles_settings.xml | 3 --- .idea/encodings.xml | 5 ----- .idea/misc.xml | 10 ---------- .idea/modules.xml | 8 -------- .idea/scopes/scope_settings.xml | 5 ----- .idea/vcs.xml | 8 -------- 8 files changed, 63 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml 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 @@ - - - - - - - - From e0373461c10c6e92f250abe76636c94231a309bb Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 20:39:39 +0100 Subject: [PATCH 03/16] Renames README files consistently. --- Ada/{README => README.txt} | 0 C/{README => README.txt} | 0 Groovy/{readme.txt => README.txt} | 0 cpp/{README => README.md} | 0 go/{readme.md => README.md} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename Ada/{README => README.txt} (100%) rename C/{README => README.txt} (100%) rename Groovy/{readme.txt => README.txt} (100%) rename cpp/{README => README.md} (100%) rename go/{readme.md => README.md} (100%) 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/cpp/README b/cpp/README.md similarity index 100% rename from cpp/README rename to cpp/README.md diff --git a/go/readme.md b/go/README.md similarity index 100% rename from go/readme.md rename to go/README.md From 027693ce8357d81bd827add90cae87b92b42e320 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 20:48:45 +0100 Subject: [PATCH 04/16] Renames Java with Spock language without blanks in folder name. --- {Java - Spock => Java-Spock}/.gitignore | 0 {Java - Spock => Java-Spock}/build.gradle | 0 .../gradle/wrapper/gradle-wrapper.jar | Bin .../gradle/wrapper/gradle-wrapper.properties | 0 {Java - Spock => Java-Spock}/gradlew | 0 {Java - Spock => Java-Spock}/gradlew.bat | 0 .../src/main/java/com/gildedrose/GildedRose.java | 0 .../src/main/java/com/gildedrose/Item.java | 0 .../main/java/com/gildedrose/TexttestFixture.java | 0 .../groovy/com/gildedrose/GildedRoseSpec.groovy | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {Java - Spock => Java-Spock}/.gitignore (100%) rename {Java - Spock => Java-Spock}/build.gradle (100%) rename {Java - Spock => Java-Spock}/gradle/wrapper/gradle-wrapper.jar (100%) rename {Java - Spock => Java-Spock}/gradle/wrapper/gradle-wrapper.properties (100%) rename {Java - Spock => Java-Spock}/gradlew (100%) rename {Java - Spock => Java-Spock}/gradlew.bat (100%) rename {Java - Spock => Java-Spock}/src/main/java/com/gildedrose/GildedRose.java (100%) rename {Java - Spock => Java-Spock}/src/main/java/com/gildedrose/Item.java (100%) rename {Java - Spock => Java-Spock}/src/main/java/com/gildedrose/TexttestFixture.java (100%) rename {Java - Spock => Java-Spock}/src/test/groovy/com/gildedrose/GildedRoseSpec.groovy (100%) 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 From 39b3534c6feebb2bba38b9d0ca3f3ae4899c5978 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 20:59:38 +0100 Subject: [PATCH 05/16] Splits JS Jasmine and Mocha starting points into separate toplevel folders similar to Java and Java-Spock. --- {js/jasmine => js-jasmine}/.gitignore | 0 {js/jasmine => js-jasmine}/package-lock.json | 0 {js/jasmine => js-jasmine}/package.json | 0 {js/jasmine => js-jasmine}/spec/gilded_rose_spec.js | 0 {js/jasmine => js-jasmine}/spec/support/jasmine.json | 0 {js/jasmine => js-jasmine}/src/gilded_rose.js | 0 {js/mocha => js-mocha}/.gitignore | 0 {js/mocha => js-mocha}/package-lock.json | 0 {js/mocha => js-mocha}/package.json | 0 {js/mocha => js-mocha}/src/gilded_rose.js | 0 {js/mocha => js-mocha}/test/test_gilded_rose.js | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename {js/jasmine => js-jasmine}/.gitignore (100%) rename {js/jasmine => js-jasmine}/package-lock.json (100%) rename {js/jasmine => js-jasmine}/package.json (100%) rename {js/jasmine => js-jasmine}/spec/gilded_rose_spec.js (100%) rename {js/jasmine => js-jasmine}/spec/support/jasmine.json (100%) rename {js/jasmine => js-jasmine}/src/gilded_rose.js (100%) rename {js/mocha => js-mocha}/.gitignore (100%) rename {js/mocha => js-mocha}/package-lock.json (100%) rename {js/mocha => js-mocha}/package.json (100%) rename {js/mocha => js-mocha}/src/gilded_rose.js (100%) rename {js/mocha => js-mocha}/test/test_gilded_rose.js (100%) 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-lock.json b/js-jasmine/package-lock.json similarity index 100% rename from js/jasmine/package-lock.json rename to js-jasmine/package-lock.json diff --git a/js/jasmine/package.json b/js-jasmine/package.json similarity index 100% rename from js/jasmine/package.json rename to js-jasmine/package.json 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 similarity index 100% rename from js/jasmine/spec/support/jasmine.json rename to js-jasmine/spec/support/jasmine.json 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-lock.json b/js-mocha/package-lock.json similarity index 100% rename from js/mocha/package-lock.json rename to js-mocha/package-lock.json diff --git a/js/mocha/package.json b/js-mocha/package.json similarity index 100% rename from js/mocha/package.json rename to js-mocha/package.json 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 From 68da5497513fb97c933d3d58f0ced17528c9b6f6 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 21:48:42 +0100 Subject: [PATCH 06/16] Fixes encoding Smalltalk source. --- Smalltalk/GildedRose.st | 161 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 1 deletion(-) 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 + ! ! From b881804cdac1ae13d3752dc1272e82c6d2dda47d Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 22:06:14 +0100 Subject: [PATCH 07/16] Use newer version of TypeScript. Use proper project name in project properties. --- TypeScript/package.json | 14 ++++++-------- TypeScript/tsconfig.json | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) 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 }, From ab83717690d8f614141a6c2c5d36af514ceaf907 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 2 Dec 2018 23:13:25 +0100 Subject: [PATCH 08/16] Adds Babel transpiler to JS projects so code runs on older versions of Node, --- js-jasmine/package-lock.json | 112 ------------ js-jasmine/package.json | 19 +- js-jasmine/spec/support/jasmine.json | 6 +- js-mocha/package-lock.json | 249 --------------------------- js-mocha/package.json | 9 +- 5 files changed, 24 insertions(+), 371 deletions(-) delete mode 100644 js-jasmine/package-lock.json delete mode 100644 js-mocha/package-lock.json 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/package.json b/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/support/jasmine.json b/js-jasmine/spec/support/jasmine.json index 370fc446..cfed10fd 100644 --- a/js-jasmine/spec/support/jasmine.json +++ b/js-jasmine/spec/support/jasmine.json @@ -4,8 +4,8 @@ "**/*[sS]pec.js" ], "helpers": [ - "helpers/**/*.js" + "../node_modules/babel-register/lib/node.js" ], - "stopSpecOnExpectationFailure": false, - "random": true + "oneFailurePerSpec": false, + "randomizeTests": 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/js-mocha/package.json b/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" } From 60b2549066d381adf32922e250bd1d9b7c63709b Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 00:12:00 +0100 Subject: [PATCH 09/16] Go: Extracts texttest_feature.go from main Gilded Rose, write test similar to other languages. --- go/README.md | 2 +- go/gilded-rose.go | 19 +----------------- go/gilded-rose_test.go | 12 ++++++++++-- go/texttest_feature.go | 44 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 go/texttest_feature.go diff --git a/go/README.md b/go/README.md index 6b894ed4..98dfd387 100644 --- a/go/README.md +++ b/go/README.md @@ -3,7 +3,7 @@ - Run : ```shell -go run gilded-rose.go +go run texttest_feature.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_feature.go b/go/texttest_feature.go new file mode 100644 index 00000000..a5b47a77 --- /dev/null +++ b/go/texttest_feature.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) + } +} From c0a68242757529dac0b344d3b214a93ec157359e Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 01:15:24 +0100 Subject: [PATCH 10/16] First draft of Scheme port. --- scheme/gilded-rose.scm | 46 +++++++++++++++++++++++++++++++++++++ scheme/texttest-feature.scm | 29 +++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 scheme/gilded-rose.scm create mode 100644 scheme/texttest-feature.scm diff --git a/scheme/gilded-rose.scm b/scheme/gilded-rose.scm new file mode 100644 index 00000000..28dc326d --- /dev/null +++ b/scheme/gilded-rose.scm @@ -0,0 +1,46 @@ +;;; Class ITEM + +(define-structure item + (name sell-in quality)) +;; defines make-item, item?, item-name, item-sell-in, item-quality, set-item-name!, set-item-sell-in!, set-item-quality! + +(define (item-to-string item) + (string-append (item-name item) + ", " + (number->string (item-sell-in item)) + ", " + (number->string (item-quality item)))) + +;;; Class 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")) + (set-item-quality! item (- (item-quality item) 1)))) + (cond ((< (item-quality item) 50) + (set-item-quality! item (+ (item-quality item) 1)) + (if (string-= (item-name item) "Backstage passes to a TAFKAL80ETC concert") + (if (< sell-in 11) + (if (< (item-quality item) 50) + (set-item-quality! item (+ (item-quality item) 1)))) + (if (< sell-in 6) + (if (< (item-quality item) 50) + (set-item-quality! item (+ (item-quality item) 1)))))))) + + (if (not (string-= (item-name item) "Sulfuras, Hand of Ragnaros")) + (set-item-sell-in! 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")) + (set-item-quality! item (- (item-quality item) 1)))) + (set-item-quality! item (- (item-quality item) (item-quality item)))) + (if (< (item-quality item) 50) + (set-item-quality! item (+ (item-quality item) 1)))))) + items)) diff --git a/scheme/texttest-feature.scm b/scheme/texttest-feature.scm new file mode 100644 index 00000000..8b9b4740 --- /dev/null +++ b/scheme/texttest-feature.scm @@ -0,0 +1,29 @@ +(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 (x day) + (cond ((<= day days) + (display "-------- day ~a --------~%" i) + (newline) + (display "name, sell-in, quality") + (newline) + (for-each (lambda (item) + (display (item-to-string item)) + (newline)) + items) + (update-quality items) + (x (- day 1))))) + (x 0)) From 1c530189bd6f366b9d4f9a7d60cb51a93ec7b215 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 21:03:48 +0100 Subject: [PATCH 11/16] Make Scheme version work. --- scheme/gilded-rose.scm | 46 ++++++++++++++++++------------------- scheme/texttest-feature.scm | 21 +++++++++-------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/scheme/gilded-rose.scm b/scheme/gilded-rose.scm index 28dc326d..8a72f50e 100644 --- a/scheme/gilded-rose.scm +++ b/scheme/gilded-rose.scm @@ -1,8 +1,8 @@ ;;; Class ITEM -(define-structure item - (name sell-in quality)) -;; defines make-item, item?, item-name, item-sell-in, item-quality, set-item-name!, set-item-sell-in!, set-item-quality! +(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) @@ -11,36 +11,36 @@ ", " (number->string (item-quality item)))) -;;; Class GILDED-ROSE +;;; 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 (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")) - (set-item-quality! item (- (item-quality item) 1)))) + (if (not (string=? (item-name item) "Sulfuras, Hand of Ragnaros")) + (item-quality-set! item (- (item-quality item) 1)))) (cond ((< (item-quality item) 50) - (set-item-quality! item (+ (item-quality item) 1)) - (if (string-= (item-name item) "Backstage passes to a TAFKAL80ETC concert") - (if (< sell-in 11) + (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) (if (< (item-quality item) 50) - (set-item-quality! item (+ (item-quality item) 1)))) - (if (< sell-in 6) + (item-quality-set! item (+ (item-quality item) 1)))) + (if (< (item-sell-in item) 6) (if (< (item-quality item) 50) - (set-item-quality! item (+ (item-quality item) 1)))))))) + (item-quality-set! item (+ (item-quality item) 1)))))))) - (if (not (string-= (item-name item) "Sulfuras, Hand of Ragnaros")) - (set-item-sell-in! item (- (item-sell-in 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 (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")) - (set-item-quality! item (- (item-quality item) 1)))) - (set-item-quality! item (- (item-quality item) (item-quality item)))) + (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) - (set-item-quality! item (+ (item-quality item) 1)))))) - items)) + (item-quality-set! item (+ (item-quality item) 1)))))) + items)) diff --git a/scheme/texttest-feature.scm b/scheme/texttest-feature.scm index 8b9b4740..ee15981e 100644 --- a/scheme/texttest-feature.scm +++ b/scheme/texttest-feature.scm @@ -2,6 +2,7 @@ (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) @@ -14,16 +15,18 @@ (make-item "Conjured Mana Cake" 3 6))) (days 2)) - (define (x day) - (cond ((<= day days) - (display "-------- day ~a --------~%" i) + (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) + (for-each + (lambda (item) + (display (item-to-string item)) + (newline)) + items) + (newline) (update-quality items) - (x (- day 1))))) - (x 0)) + (loop (+ day 1))))) + (loop 0)) From 745c004a8ba5c2de254448bdf9093b788619dd62 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 21:15:20 +0100 Subject: [PATCH 12/16] Adds foo test with minimal assertion library. --- scheme/assert.scm | 58 +++++++++++++++++++++++++++++++++++++ scheme/gilded-rose-test.scm | 7 +++++ 2 files changed, 65 insertions(+) create mode 100644 scheme/assert.scm create mode 100644 scheme/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))))) From 6e82156f6c55604858d12551d8c80a4c02107e80 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 21:16:10 +0100 Subject: [PATCH 13/16] Rename texttest fixture, fix type in name. --- scheme/{texttest-feature.scm => texttest-fixture.scm} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scheme/{texttest-feature.scm => texttest-fixture.scm} (100%) diff --git a/scheme/texttest-feature.scm b/scheme/texttest-fixture.scm similarity index 100% rename from scheme/texttest-feature.scm rename to scheme/texttest-fixture.scm From 6b492c223a6061e6588cad3ebdb8de734372c957 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 21:18:33 +0100 Subject: [PATCH 14/16] Rename Go's texttest fixture, fix type in name. --- go/README.md | 2 +- go/{texttest_feature.go => texttest_fixture.go} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename go/{texttest_feature.go => texttest_fixture.go} (100%) diff --git a/go/README.md b/go/README.md index 98dfd387..e22e3776 100644 --- a/go/README.md +++ b/go/README.md @@ -3,7 +3,7 @@ - Run : ```shell -go run texttest_feature.go gilded-rose.go +go run texttest_fixture.go gilded-rose.go ``` - Run tests : diff --git a/go/texttest_feature.go b/go/texttest_fixture.go similarity index 100% rename from go/texttest_feature.go rename to go/texttest_fixture.go From 2a64f7c46044a5c8340b3a1a06230e79fef2696f Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 21:23:06 +0100 Subject: [PATCH 15/16] Documents Scheme port how to run and test. --- scheme/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 scheme/README.md 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 +``` From 4807997dbabfdc9b94677939b028d40942850108 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Mon, 3 Dec 2018 22:45:26 +0100 Subject: [PATCH 16/16] Fixes bug in Scheme version, not deeply nested enough. --- scheme/gilded-rose.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scheme/gilded-rose.scm b/scheme/gilded-rose.scm index 8a72f50e..dac984fa 100644 --- a/scheme/gilded-rose.scm +++ b/scheme/gilded-rose.scm @@ -25,11 +25,11 @@ (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) - (if (< (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)))))))) + (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)))