mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
Merge pull request #8 from codecop/master
minor Update of IDEA configuration of Java project and port of GildedRose to R language
This commit is contained in:
commit
be902c4640
@ -1,5 +1,3 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="">
|
||||
<module2copyright />
|
||||
</settings>
|
||||
<settings default="" />
|
||||
</component>
|
||||
@ -17,6 +17,17 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="JUnit4">
|
||||
<CLASSES>
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
18
R/.project
Normal file
18
R/.project
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>GildedRose.R</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>de.walware.statet.r.builders.RSupport</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>de.walware.statet.base.StatetNature</nature>
|
||||
<nature>de.walware.statet.r.RNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
56
R/gilded_rose.R
Normal file
56
R/gilded_rose.R
Normal file
@ -0,0 +1,56 @@
|
||||
source('item.R')
|
||||
|
||||
update_quality <- function(items) {
|
||||
lapply(items,
|
||||
function(item) {
|
||||
|
||||
if (item$name != "Aged Brie" && item$name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (item$quality > 0) {
|
||||
if (item$name != "Sulfuras, Hand of Ragnaros") {
|
||||
item$quality <- item$quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (item$quality < 50) {
|
||||
item$quality <- item$quality + 1
|
||||
if (item$name == "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (item$sell_in < 11) {
|
||||
if (item$quality < 50) {
|
||||
item$quality = item$quality + 1
|
||||
}
|
||||
}
|
||||
if (item$sell_in < 6) {
|
||||
if (item$quality < 50) {
|
||||
item$quality = item$quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item$name != "Sulfuras, Hand of Ragnaros") {
|
||||
item$sell_in <- item$sell_in - 1
|
||||
}
|
||||
|
||||
if (item$sell_in < 0) {
|
||||
if (item$name != "Aged Brie") {
|
||||
if (item$name != "Backstage passes to a TAFKAL80ETC concert") {
|
||||
if (item$quality > 0) {
|
||||
if (item$name != "Sulfuras, Hand of Ragnaros") {
|
||||
item$quality <- item$quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item$quality <- item$quality - item$quality
|
||||
}
|
||||
} else {
|
||||
if (item$quality < 50) {
|
||||
item$quality <- item$quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item
|
||||
}
|
||||
)
|
||||
}
|
||||
13
R/item.R
Normal file
13
R/item.R
Normal file
@ -0,0 +1,13 @@
|
||||
item <- function(name, sell_in, quality) {
|
||||
newItem <- list(name=name, sell_in=sell_in, quality=quality)
|
||||
class(newItem) <- 'item'
|
||||
newItem
|
||||
}
|
||||
|
||||
as.character.item <- function(item) {
|
||||
paste(item$name, ", ", item$sell_in, ", ", item$quality, sep='')
|
||||
}
|
||||
|
||||
print.item <- function(item) {
|
||||
print.default(as.character(item))
|
||||
}
|
||||
7
R/runit_gilded_rose.R
Normal file
7
R/runit_gilded_rose.R
Normal file
@ -0,0 +1,7 @@
|
||||
source('gilded_rose.R')
|
||||
|
||||
test.foo <- function() {
|
||||
items <- list( item('foo', 0, 0) )
|
||||
items <- update_quality(items)
|
||||
checkEquals('fixme', items[[1]]$name);
|
||||
}
|
||||
7
R/test_setup.R
Normal file
7
R/test_setup.R
Normal file
@ -0,0 +1,7 @@
|
||||
# A little helper script to get the testing infrastructure started
|
||||
|
||||
# install.packages("RUnit")
|
||||
require(RUnit)
|
||||
|
||||
# execute single test file
|
||||
runTestFile("runit_gilded_rose.R")
|
||||
33
R/texttest_fixture.R
Normal file
33
R/texttest_fixture.R
Normal file
@ -0,0 +1,33 @@
|
||||
rm(list=ls())
|
||||
|
||||
source('gilded_rose.R')
|
||||
|
||||
writeLines('OMGHAI!')
|
||||
|
||||
items <- list(
|
||||
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),
|
||||
# This Conjured item does not work properly yet
|
||||
item('Conjured Mana Cake', 3, 6)
|
||||
)
|
||||
|
||||
days <- 2
|
||||
for (day in 0:days) {
|
||||
writeLines(paste('-------- day ', day, ' --------', sep=''))
|
||||
writeLines('name, sellIn, quality')
|
||||
lapply(items,
|
||||
function(item) {
|
||||
writeLines(as.character(item))
|
||||
}
|
||||
)
|
||||
writeLines('')
|
||||
items <- update_quality(items)
|
||||
}
|
||||
|
||||
rm('day', 'days', 'items')
|
||||
Loading…
Reference in New Issue
Block a user