mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
commit
e487ebeaf9
@ -6,4 +6,3 @@
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ Pretty simple, right? Well this is where it gets interesting:
|
||||
- "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;
|
||||
- "Backstage passes", like aged brie, increases in Quality as its 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
|
||||
|
||||
|
||||
43
GildedRoseRequirements_ru.txt
Normal file
43
GildedRoseRequirements_ru.txt
Normal file
@ -0,0 +1,43 @@
|
||||
======================================
|
||||
Технические требования «Gilded Rose»
|
||||
======================================
|
||||
|
||||
Привет и добро пожаловать в команду «Gilded Rose». Как вы знаете, мы небольшая гостиница удобно расположенная
|
||||
в известном городе под руководством дружественного управляющего по имени Эллисон. Также мы занимаемся покупкой
|
||||
и продажей только самых лучших товаров. К несчастью, качество наших товаров постоянно ухудшается по мере приближения
|
||||
к максимальному сроку хранения. Существует информационная система, которая ведет переучет всех товаров. Система
|
||||
была разработана рубаха-парнем, по имени Leeroy, который отправился за поисками новых приключений. Ваша задача
|
||||
заключается в том, чтобы добавить новый функционал в нашу систему, чтобы мы могли начать продавать новую категорию
|
||||
товаров.
|
||||
|
||||
В общих чертах система работает следующим образом:
|
||||
|
||||
- Все товары имеют свойство «sellIn» (срок хранения), которое обозначает количество
|
||||
дней в течение которых мы должны продать товар;
|
||||
- Все товары имеют свойство «Quality» (качество), которое обозначает насколько качественным является товар;
|
||||
- В конце дня наша система снижает значение обоих свойств для каждого товара.
|
||||
|
||||
Довольно просто, не правда ли? Тут-то и начинается самое интересное:
|
||||
|
||||
- После того, как срок храния прошел, качество товара ухудшается в два раза быстрее;
|
||||
- Качество товара никогда не может быть отрицательным;
|
||||
- Для товара «Aged Brie» качество увеличивается пропорционально возрасту;
|
||||
- Качество товара никогда не может быть больше, чем 50;
|
||||
- «Sulfuras» является легендарным товаром, поэтому у него нет срока хранения и не подвержен ухудшению качества;
|
||||
- Качество «Backstage passes» также, как и «Aged Brie», увеличивается по мере приближения к сроку хранения.
|
||||
Качество увеличивается на 2, когда до истечения срока хранения 10 или менее дней и на 3,
|
||||
если до истечения 5 или менее дней. При этом качество падает до 0 после даты проведения концерта.
|
||||
|
||||
Недавно мы нашли поставщика магических товаров. Для того, чтобы продавать его товары необходимо обновить нашу
|
||||
систему следующим образом:
|
||||
|
||||
- «Conjured» товары теряют качество в два раза быстрее, чем обычные товары.
|
||||
|
||||
Не стесняйтесь вносить любые изменения в метод «UpdateQuality» и добавлять любой новый код до тех пор,
|
||||
пока система работает корректно. Тем не менее, не меняйте класс «Item» или его свойства, так как он принадлежит
|
||||
сидящему в углу гоблину, который очень яростен и поэтому выстрелит в вас поскольку не верит в принцип
|
||||
совместного владения кодом (вы можете сделать метод «UpdateQuality» и свойства класса «Item» статическими
|
||||
если хотите, мы вас прикроем).
|
||||
|
||||
Просто для уточнения, товар никогда не может иметь качество выше чем 50, однако легендарный товар «Sulfuras»
|
||||
имеет качество 80 и оно никогда не меняется.
|
||||
32
GildedRoseRequirements_zh.txt
Normal file
32
GildedRoseRequirements_zh.txt
Normal file
@ -0,0 +1,32 @@
|
||||
======================================
|
||||
Gilded Rose 需求描述
|
||||
======================================
|
||||
|
||||
|
||||
欢迎来到镶金玫瑰(Gilded Rose)团队。如你所知,我们是主城中的一个小旅店,店主非常友好,名叫Allison。我们也售卖最好的物品。不幸的是,物品品质会随着销售期限的接近而不断下降。
|
||||
我们有一个系统来更新库存信息。系统是由一个无名之辈Leeroy所开发的,他已经不在这了。
|
||||
你的任务是添加新功能,这样我们就可以售卖新的物品。
|
||||
|
||||
先介绍一下我们的系统:
|
||||
|
||||
- 每种物品都具备一个`SellIn`值,表示我们要在多少天之前把物品卖出去,即销售期
|
||||
- 每种的物品都具备一个`Quality`值,表示物品的品质
|
||||
- 每天结束时,系统会降低每种物品的这两个数值
|
||||
|
||||
很简单吧?这还有些更有意思的:
|
||||
|
||||
- 一旦销售期限过期,品质`Quality`会以双倍速度加速下降
|
||||
- 物品的品质`Quality`永远不会为负值
|
||||
- "Aged Brie"的品质`Quality`会随着时间推移而提高
|
||||
- 物品的品质`Quality`永远不会超过50
|
||||
- 传奇物品"Sulfuras"永不到期,也不会降低品质`Quality`
|
||||
- "Backstage passes"与aged brie类似,其品质`Quality`会随着时间推移而提高;当还剩10天或更少的时候,品质`Quality`每天提高2;当还剩5天或更少的时候,品质`Quality`每天提高3;但一旦过期,品质就会降为0
|
||||
|
||||
|
||||
我们最近签约了一个召唤物品供应商。这需要对我们的系统进行升级:
|
||||
|
||||
- "Conjured"物品的品质`Quality`下降速度比正常物品快一倍
|
||||
|
||||
请随意对UpdateQuality函数进行修改和添加新代码,只要系统还能正常工作。然而,不要修改Item类或其属性,因为那属于角落里的地精,他会非常愤怒地爆你头,因为他不相信代码共享所有制(如果你愿意,你可以将UpdateQuality方面和Items属性改为静态的,我们会掩护你的)。
|
||||
|
||||
再次澄清,每种物品的品质不会超过50,然而"Sulfuras"是一个传奇物品,因此它的品质是80且永远不变。
|
||||
124
Groovy/.gitignore
vendored
Normal file
124
Groovy/.gitignore
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/groovy,intellij,eclipse,vim
|
||||
|
||||
#!! ERROR: groovy is undefined. Use list command to see defined gitignore types !!#
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/dictionaries
|
||||
.idea/vcs.xml
|
||||
.idea/jsLibraryMappings.xml
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/dataSources.ids
|
||||
.idea/dataSources.xml
|
||||
.idea/dataSources.local.xml
|
||||
.idea/sqlDataSources.xml
|
||||
.idea/dynamic.xml
|
||||
.idea/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/gradle.xml
|
||||
.idea/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
|
||||
### Vim ###
|
||||
# swap
|
||||
[._]*.s[a-w][a-z]
|
||||
[._]s[a-w][a-z]
|
||||
# session
|
||||
Session.vim
|
||||
# temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# auto-generated tag files
|
||||
tags
|
||||
|
||||
22
Groovy/.idea/compiler.xml
Normal file
22
Groovy/.idea/compiler.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<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" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
3
Groovy/.idea/copyright/profiles_settings.xml
Normal file
3
Groovy/.idea/copyright/profiles_settings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
||||
26
Groovy/.idea/misc.xml
Normal file
26
Groovy/.idea/misc.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="MavenImportPreferences">
|
||||
<option name="generalSettings">
|
||||
<MavenGeneralSettings>
|
||||
<option name="mavenHome" value="Bundled (Maven 3)" />
|
||||
</MavenGeneralSettings>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
Groovy/.idea/modules.xml
Normal file
8
Groovy/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Groovy.iml" filepath="$PROJECT_DIR$/Groovy.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
12
Groovy/Groovy.iml
Normal file
12
Groovy/Groovy.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Current Groovy (sdkman)" level="application" />
|
||||
</component>
|
||||
</module>
|
||||
17
Groovy/readme.txt
Normal file
17
Groovy/readme.txt
Normal file
@ -0,0 +1,17 @@
|
||||
Welcome to the Groovy Gilded Rose
|
||||
=================================
|
||||
|
||||
to run the test, you can either:
|
||||
- run them from your favorite IDE
|
||||
- make sure you have installed language support for Groovy
|
||||
- IntelliJ:
|
||||
- open project
|
||||
- choose this folder (Groovy)
|
||||
- Eclipse:
|
||||
- new Groovy Project
|
||||
- choose this folder (Groovy) as the project folder
|
||||
- add JUnit to build path
|
||||
- run the test from the src/ folder in your shell:
|
||||
- $ cd src/
|
||||
- $ groovy com/gildedrose/GildedRoseTest.groovy
|
||||
|
||||
62
Groovy/src/com/gildedrose/GildedRose.groovy
Normal file
62
Groovy/src/com/gildedrose/GildedRose.groovy
Normal file
@ -0,0 +1,62 @@
|
||||
package com.gildedrose
|
||||
|
||||
class GildedRose {
|
||||
Item[] items
|
||||
|
||||
GildedRose(Item[] items) {
|
||||
this.items = items
|
||||
}
|
||||
|
||||
void updateQuality() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (!items[i].name.equals("Aged Brie")
|
||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
|
||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].sellIn < 11) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].sellIn = items[i].sellIn - 1
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 0) {
|
||||
if (!items[i].name.equals("Aged Brie")) {
|
||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Groovy/src/com/gildedrose/GildedRoseTest.groovy
Normal file
15
Groovy/src/com/gildedrose/GildedRoseTest.groovy
Normal file
@ -0,0 +1,15 @@
|
||||
package com.gildedrose
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void "foo"() {
|
||||
def items = [ new Item("foo", 0, 0) ] as Item[]
|
||||
def app = new GildedRose(items)
|
||||
app.updateQuality()
|
||||
assert "fixme" == app.items[0].name
|
||||
}
|
||||
|
||||
}
|
||||
21
Groovy/src/com/gildedrose/Item.groovy
Normal file
21
Groovy/src/com/gildedrose/Item.groovy
Normal file
@ -0,0 +1,21 @@
|
||||
package com.gildedrose
|
||||
|
||||
class Item {
|
||||
|
||||
String name
|
||||
|
||||
int sellIn
|
||||
|
||||
int quality
|
||||
|
||||
Item(String name, int sellIn, int quality) {
|
||||
this.name = name
|
||||
this.sellIn = sellIn
|
||||
this.quality = quality
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
return this.name + ", " + this.sellIn + ", " + this.quality
|
||||
}
|
||||
}
|
||||
32
Groovy/src/com/gildedrose/TexttestFixture.groovy
Normal file
32
Groovy/src/com/gildedrose/TexttestFixture.groovy
Normal file
@ -0,0 +1,32 @@
|
||||
package com.gildedrose
|
||||
|
||||
println("OMGHAI!")
|
||||
|
||||
Item[] items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20),
|
||||
new Item("Aged Brie", 2, 0),
|
||||
new Item("Elixir of the Mongoose", 5, 7),
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)] as Item[]
|
||||
|
||||
GildedRose app = new GildedRose(items)
|
||||
|
||||
int days = 2
|
||||
if (args.length > 0) {
|
||||
days = Integer.parseInt(args[0]) + 1
|
||||
}
|
||||
|
||||
for (int i = 0; i < days; i++) {
|
||||
println("-------- day " + i + " --------")
|
||||
println("name, sellIn, quality")
|
||||
for (Item item in items) {
|
||||
println(item)
|
||||
}
|
||||
println ""
|
||||
app.updateQuality()
|
||||
}
|
||||
@ -2,11 +2,11 @@ This Kata was originally created by Terry Hughes (http://twitter.com/#!/TerryHug
|
||||
|
||||
I translated the original C# into a few other languages, (with a little help from my friends!), and slightly changed the starting position. This means I've actually done a small amount of refactoring already compared with the original form of the kata, and made it easier to get going with writing tests by giving you one failing unit test to start with. I also added test fixtures for Text-Based approval testing with TextTest (see [the TextTests](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/master/texttests))
|
||||
|
||||
As Bobby Johnson points out in his article ["Why Most Solutions to Gilded Rose Miss The Bigger Picture"](http://iamnotmyself.com/2012/12/07/why-most-solutions-to-gilded-rose-miss-the-bigger-picture/), it'll actually give you
|
||||
As Bobby Johnson points out in his article ["Why Most Solutions to Gilded Rose Miss The Bigger Picture"](http://iamnotmyself.com/2012/12/07/why-most-solutions-to-gilded-rose-miss-the-bigger-picture), it'll actually give you
|
||||
better practice at handling a legacy code situation if you do this Kata in the original C#. However, I think this kata
|
||||
is also really useful for practicing writing good tests using different frameworks and approaches, and the small changes I've made help with that. I think it's also interesting to compare what the refactored code and tests look like in different programming languages.
|
||||
|
||||
I wrote this article ["Writing Good Tests for the Gilded Rose Kata"](http://emilybache.blogspot.se/2013/03/writing-good-tests-for-gilded-rose-kata.html) about how you could use this kata in a [coding dojo](https://leanpub.com/codingdojohandbook).
|
||||
I wrote this article ["Writing Good Tests for the Gilded Rose Kata"](http://coding-is-like-cooking.info/2013/03/writing-good-tests-for-the-gilded-rose-kata/) about how you could use this kata in a [coding dojo](https://leanpub.com/codingdojohandbook).
|
||||
|
||||
## How to use this Kata
|
||||
|
||||
@ -34,6 +34,7 @@ I've also set this kata up on [cyber-dojo](http://cyber-dojo.org) for several la
|
||||
|
||||
- [JUnit, Java](http://cyber-dojo.org/forker/fork/751DD02C4C?avatar=snake&tag=4)
|
||||
- [C#](http://cyber-dojo.org/forker/fork/5C5AC766B0?avatar=koala&tag=1)
|
||||
- [C++](http://cyber-dojo.org/forker/fork/AA86ECBCC9?avatar=rhino&tag=7)
|
||||
- [Ruby](http://cyber-dojo.org/forker/fork/A8943EAF92?avatar=hippo&tag=9)
|
||||
- [RSpec, Ruby](http://cyber-dojo.org/forker/fork/8E58B0AD16?avatar=raccoon&tag=3)
|
||||
- [Python](http://cyber-dojo.org/forker/fork/297041AA7A?avatar=lion&tag=4)
|
||||
|
||||
140
clisp/gilded-rose.lisp
Normal file
140
clisp/gilded-rose.lisp
Normal file
@ -0,0 +1,140 @@
|
||||
; 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.
|
||||
|
||||
; https://github.com/emilybache/GildedRose-Refactoring-Kata
|
||||
|
||||
; Common Lisp version: Rainer Joswig, joswig@lisp.de, 2016
|
||||
|
||||
; Example from the command line:
|
||||
; sbcl --script gildedrose.lisp 10
|
||||
|
||||
;;; ================================================================
|
||||
;;; Code
|
||||
|
||||
(defpackage "GILDED-ROSE"
|
||||
(:use "CL"))
|
||||
|
||||
(in-package "GILDED-ROSE")
|
||||
|
||||
|
||||
;;; Class ITEM
|
||||
|
||||
(defclass item ()
|
||||
((name :initarg :name :type string)
|
||||
(sell-in :initarg :sell-in :type integer)
|
||||
(quality :initarg :quality :type integer)))
|
||||
|
||||
(defmethod to-string ((i item))
|
||||
(with-slots (name quality sell-in) i
|
||||
(format nil "~a, ~a, ~a" name sell-in quality)))
|
||||
|
||||
;;; Class GILDED-ROSE
|
||||
|
||||
(defclass gilded-rose ()
|
||||
((items :initarg :items)))
|
||||
|
||||
(defmethod update-quality ((gr gilded-rose))
|
||||
(with-slots (items) gr
|
||||
(dotimes (i (length items))
|
||||
(with-slots (name quality sell-in)
|
||||
(elt items i)
|
||||
(if (and (not (equalp name "Aged Brie"))
|
||||
(not (equalp name "Backstage passes to a TAFKAL80ETC concert")))
|
||||
(if (> quality 0)
|
||||
(if (not (equalp name "Sulfuras, Hand of Ragnaros"))
|
||||
(setf quality (- quality 1))))
|
||||
(when (< quality 50)
|
||||
(setf quality (+ quality 1))
|
||||
(when (equalp name "Backstage passes to a TAFKAL80ETC concert")
|
||||
(if (< sell-in 11)
|
||||
(if (< quality 50)
|
||||
(setf quality (+ quality 1))))
|
||||
(if (< sell-in 6)
|
||||
(if (< quality 50)
|
||||
(setf quality (+ quality 1)))))))
|
||||
|
||||
(if (not (equalp name "Sulfuras, Hand of Ragnaros"))
|
||||
(setf sell-in (- sell-in 1)))
|
||||
|
||||
(if (< sell-in 0)
|
||||
(if (not (equalp name "Aged Brie"))
|
||||
(if (not (equalp name "Backstage passes to a TAFKAL80ETC concert"))
|
||||
(if (> quality 0)
|
||||
(if (not (equalp name "Sulfuras, Hand of Ragnaros"))
|
||||
(setf quality (- quality 1))))
|
||||
(setf quality (- quality quality)))
|
||||
(if (< quality 50)
|
||||
(setf quality (+ quality 1)))))))))
|
||||
|
||||
;;; Example
|
||||
|
||||
(defun run-gilded-rose ()
|
||||
(write-line "OMGHAI!")
|
||||
(let* ((descriptions '(("+5 Dexterity Vest" 10 20)
|
||||
("Aged Brie" 2 0)
|
||||
("Elixir of the Mongoose" 5 7)
|
||||
("Sulfuras, Hand of Ragnaros" 0 80)
|
||||
("Sulfuras, Hand of Ragnaros" -1 80)
|
||||
("Backstage passes to a TAFKAL80ETC concert" 15 20)
|
||||
("Backstage passes to a TAFKAL80ETC concert" 10 49)
|
||||
("Backstage passes to a TAFKAL80ETC concert" 5 49)
|
||||
;; this conjured item does not work properly yet
|
||||
("Conjured Mana Cake" 3 6)))
|
||||
(items (loop for (name sell-in quality) in descriptions
|
||||
collect (make-instance 'item
|
||||
:name name
|
||||
:sell-in sell-in
|
||||
:quality quality)))
|
||||
(app (make-instance 'gilded-rose :items items))
|
||||
(days 2))
|
||||
#+sbcl
|
||||
(if (second sb-ext:*posix-argv*)
|
||||
(setf days (parse-integer (second sb-ext:*posix-argv*))))
|
||||
#+lispworks
|
||||
(if (fourth sys:*line-arguments-list*)
|
||||
(setf days (parse-integer (fourth sys:*line-arguments-list*))))
|
||||
(dotimes (i days)
|
||||
(format t "-------- day ~a --------~%" i)
|
||||
(format t "name, sell-in, quality~%")
|
||||
(dolist (item items)
|
||||
(write-line (to-string item)))
|
||||
(terpri)
|
||||
(update-quality app))))
|
||||
|
||||
(run-gilded-rose)
|
||||
|
||||
;;; ================================================================
|
||||
;;; EOF
|
||||
35
cpp/README
35
cpp/README
@ -1,7 +1,38 @@
|
||||
TL;DR;
|
||||
-------
|
||||
run-once.sh runs your tests once
|
||||
|
||||
Assumptions:
|
||||
Before this will work you will need:
|
||||
- make and a C++ compiler (like gcc) is installed on your system and is in the PATH
|
||||
- The GTest framework is in the directory gtest.
|
||||
- The GTest framework in the directory gtest.
|
||||
- If your IDE does the compilation and linking, you should remove the first 3 lines
|
||||
in the run-once.sh file.
|
||||
|
||||
More Verbose Instructions
|
||||
-------------------------
|
||||
|
||||
Create a clone of both GildedRose-Refactoring-Kata and googletest in a directory we'll call ${ROOT_INSTALL_DIR}:
|
||||
|
||||
cd ${ROOT_INSTALL_DIR}
|
||||
git clone https://github.com/emilybache/GildedRose-Refactoring-Kata
|
||||
git clone https://github.com/google/googletest
|
||||
|
||||
Make googletest by running make in subfolder googletest/googletest/make:
|
||||
|
||||
cd googletest/googletest/make
|
||||
make
|
||||
|
||||
Create a softlink in the GildedRose-Refactoring-Kata clone pointing at the googletest code:
|
||||
|
||||
cd ${ROOT_INSTALL_DIR}/GildedRose-Refactoring-Kata/cpp
|
||||
ln -s ${ROOT_INSTALL_DIR}/googletest/googletest gtest
|
||||
|
||||
Make the GildedRose-Refactoring-Kata:
|
||||
|
||||
make
|
||||
|
||||
Then you should be able to run the tests:
|
||||
|
||||
./run_once.sh
|
||||
|
||||
If you have been successful, then you should see a failing test, "GildedRoseTest.Foo".
|
||||
|
||||
6
dart/.gitignore
vendored
Normal file
6
dart/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
# Files and directories created by pub
|
||||
.packages
|
||||
.pub/
|
||||
packages
|
||||
pubspec.lock # (Remove this pattern if you wish to check in your lock file)
|
||||
.idea
|
||||
35
dart/bin/main.dart
Normal file
35
dart/bin/main.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:gilded_rose/gilded_rose.dart';
|
||||
|
||||
main(List<String> args) {
|
||||
print("OMGHAI!");
|
||||
|
||||
var items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20),
|
||||
new Item("Aged Brie", 2, 0),
|
||||
new Item("Elixir of the Mongoose", 5, 7),
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)
|
||||
];
|
||||
|
||||
GildedRose app = new GildedRose(items);
|
||||
|
||||
int days = 2;
|
||||
if (args.length > 0) {
|
||||
days = int.parse(args[0]) + 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < days; i++) {
|
||||
print("-------- day $i --------");
|
||||
print("name, sellIn, quality");
|
||||
for (var item in items) {
|
||||
print(item);
|
||||
}
|
||||
print('');
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
68
dart/lib/gilded_rose.dart
Normal file
68
dart/lib/gilded_rose.dart
Normal file
@ -0,0 +1,68 @@
|
||||
class GildedRose {
|
||||
List<Item> items;
|
||||
|
||||
GildedRose(this.items);
|
||||
|
||||
void updateQuality() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i].name != "Aged Brie" &&
|
||||
items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (items[i].quality > 0) {
|
||||
if (items[i].name != "Sulfuras, Hand of Ragnaros") {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
|
||||
if (items[i].name == "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (items[i].sellIn < 11) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].name != "Sulfuras, Hand of Ragnaros") {
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 0) {
|
||||
if (items[i].name != "Aged Brie") {
|
||||
if (items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (items[i].quality > 0) {
|
||||
if (items[i].name != "Sulfuras, Hand of Ragnaros") {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality;
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Item {
|
||||
String name;
|
||||
int sellIn;
|
||||
int quality;
|
||||
|
||||
Item(this.name, this.sellIn, this.quality);
|
||||
|
||||
String toString() => '$name, $sellIn, $quality';
|
||||
}
|
||||
6
dart/pubspec.yaml
Normal file
6
dart/pubspec.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
name: gilded_rose
|
||||
version: 0.0.1
|
||||
description: A simple console application.
|
||||
|
||||
dev_dependencies:
|
||||
test: '>=0.12.11 <0.13.0'
|
||||
13
dart/test/gilded_rose_test.dart
Normal file
13
dart/test/gilded_rose_test.dart
Normal file
@ -0,0 +1,13 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:gilded_rose/gilded_rose.dart';
|
||||
|
||||
main() {
|
||||
test('foo', () {
|
||||
var item = new Item('foo', 0, 0);
|
||||
var items = <Item>[item];
|
||||
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
expect("fixme", app.items[0].name);
|
||||
});
|
||||
}
|
||||
61
swift/GildedRose.swift
Normal file
61
swift/GildedRose.swift
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
public class GildedRose {
|
||||
var items:[Item]
|
||||
|
||||
required public init(items:[Item]) {
|
||||
self.items = items
|
||||
}
|
||||
|
||||
public func updateQuality() {
|
||||
|
||||
for i in 0..<items.count {
|
||||
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (items[i].quality > 0) {
|
||||
if (items[i].name != "Sulfuras, Hand of Ragnaros") {
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
|
||||
if (items[i].name == "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (items[i].sellIn < 11) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].name != "Sulfuras, Hand of Ragnaros") {
|
||||
items[i].sellIn = items[i].sellIn - 1
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 0) {
|
||||
if (items[i].name != "Aged Brie") {
|
||||
if (items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (items[i].quality > 0) {
|
||||
if (items[i].name != "Sulfuras, Hand of Ragnaros") {
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
swift/GildedRoseTest.swift
Normal file
13
swift/GildedRoseTest.swift
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
import XCTest
|
||||
|
||||
class GildedRoseTest: XCTestCase {
|
||||
|
||||
func testFoo() {
|
||||
let items = [Item(name: "foo", sellIn: 0, quality: 0)]
|
||||
let app = GildedRose(items: items);
|
||||
app.updateQuality();
|
||||
XCTAssertEqual("fixme", app.items[0].name);
|
||||
}
|
||||
|
||||
}
|
||||
18
swift/Item.swift
Normal file
18
swift/Item.swift
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
public class Item {
|
||||
public var name: String
|
||||
public var sellIn: Int
|
||||
public var quality: Int
|
||||
|
||||
public init(name: String, sellIn: Int, quality: Int) {
|
||||
self.name = name
|
||||
self.sellIn = sellIn
|
||||
self.quality = quality
|
||||
}
|
||||
}
|
||||
|
||||
extension Item: CustomStringConvertible {
|
||||
public var description: String {
|
||||
return self.name + ", " + String(self.sellIn) + ", " + String(self.quality);
|
||||
}
|
||||
}
|
||||
30
swift/main.swift
Normal file
30
swift/main.swift
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
let items = [
|
||||
Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20), //
|
||||
Item(name: "Aged Brie", sellIn: 2, quality: 0), //
|
||||
Item(name: "Elixir of the Mongoosname: e", sellIn: 5, quality: 7), //
|
||||
Item(name: "SulfursellIn: as,quality: Hand of Ragnaros", sellIn: 0, quality: 80), //
|
||||
Item(name: "Sulfuras, Hand of Ragnaros", sellIn: -1, quality: 80),
|
||||
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 15, quality: 20),
|
||||
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 49),
|
||||
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 49),
|
||||
// this conjured item does not work properly yet
|
||||
Item(name: "Conjured Mana Cake", sellIn: 3, quality: 6)]
|
||||
|
||||
let app = GildedRose(items: items);
|
||||
|
||||
var days = 2;
|
||||
if (Process.argc > 1) {
|
||||
days = Int(Process.arguments[1])! + 1
|
||||
}
|
||||
|
||||
|
||||
for i in 0..<days {
|
||||
print("-------- day \(i) --------");
|
||||
print("name, sellIn, quality");
|
||||
for item in items {
|
||||
print(item);
|
||||
}
|
||||
print("");
|
||||
app.updateQuality();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user