Merge pull request #104 from codecop/master

Minor cleanups and a brand new port to Scheme language
This commit is contained in:
Emily Bache authored and GitHub committed 2018-12-04 09:09:13 +01:00
commit 8fed3395d7
50 files changed
+423 -479

No files matched your search

-7
View File
@@ -1,7 +0,0 @@
.idea/workspace.xml
*.pyc
/perl6/lib/.precomp
/elixir/_build/
python/.cache
python/.coverage
**/.idea
Generated
-1
View File
@@ -1 +0,0 @@
GuildedRose
-23
View File
@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
-3
View File
@@ -1,3 +0,0 @@
<component name="CopyrightManager">
<settings default="" />
</component>
-5
View File
@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
-10
View File
@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Java/Java.iml" filepath="$PROJECT_DIR$/Java/Java.iml" />
</modules>
</component>
</project>
-5
View File
@@ -1,5 +0,0 @@
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>
Generated
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
View File
File renamed without changes.
View File
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View File
File renamed without changes.
File renamed without changes.
+160 -1
View File
@@ -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 ILine truncated
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
! !
+6 -8
View File
@@ -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": [
+1
View File
@@ -2,6 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"strict": true,
"noImplicitAny": false,
"sourceMap": false
},
View File
File renamed without changes.
+1
View File
@@ -0,0 +1 @@
_build/
+1 -1
View File
@@ -3,7 +3,7 @@
- Run :
```shell
go run gilded-rose.go
go run texttest_fixture.go gilded-rose.go
```
- Run tests :
+1 -18
View File
@@ -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" {
+10 -2
View File
@@ -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)
}
}
+44
View File
@@ -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)
}
}
File renamed without changes.
@@ -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": []
}
}
File renamed without changes.
+11
View File
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"../node_modules/babel-register/lib/node.js"
],
"oneFailurePerSpec": false,
"randomizeTests": true
}
File renamed without changes.
File renamed without changes.
@@ -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"
}
File renamed without changes.
File renamed without changes.
-112
View File
@@ -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
}
}
}
-11
View File
@@ -1,11 +0,0 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}
-249
View File
@@ -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
}
}
}
+1
View File
@@ -0,0 +1 @@
lib/.precomp
+5
View File
@@ -0,0 +1,5 @@
*.pyc
.cache
.coverage
.idea/
*.iml
+18
View File
@@ -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
```
+58
View File
@@ -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))
+7
View File
@@ -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)))))
+46
View File
@@ -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))
+32
View File
@@ -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))