Merge pull request #144 from Naomi-Dennis/elm

Add elm version of Gilded Rose
This commit is contained in:
Emily Bache 2020-01-23 13:07:56 +01:00 committed by GitHub
commit 6bd9e8e389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 118 additions and 0 deletions

5
elm/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
elm-stuff
# elm-repl generated files
repl-temp-*
*.src
src/index.html

7
elm/README.md Normal file
View File

@ -0,0 +1,7 @@
# Gilded Rose (elm)
To run tests, enter `elm-test`
### Installing `elm-test`
https://github.com/elm-explorations/test

28
elm/elm.json Normal file
View File

@ -0,0 +1,28 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.4",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.2.2"
},
"indirect": {
"elm/random": "1.0.0"
}
}
}

53
elm/src/GildedRose.elm Normal file
View File

@ -0,0 +1,53 @@
module GildedRose exposing (Item, update_quality)
type alias Item =
{ name : String
, sell_by : Int
, quality : Int
}
update_quality : List Item -> List Item
update_quality items =
List.map
(\item ->
if item.name == "Aged Brie" || item.name == "Backstage passes to a TAFKAL80ETC concert" then
if item.quality < 50 then
if item.name == "Backstage passes to a TAFKAL80ETC concert" then
if item.sell_by < 0 then
{ item | sell_by = item.sell_by - 1, quality = 0 }
else if item.sell_by < 6 then
{ item | sell_by = item.sell_by - 1, quality = item.quality + 3 }
else if item.sell_by < 11 then
{ item | sell_by = item.sell_by - 1, quality = item.quality + 2 }
else
{ item | sell_by = item.sell_by - 1, quality = item.quality + 1 }
else
{ item | sell_by = item.sell_by - 1, quality = item.quality + 1 }
else
{ item | sell_by = item.sell_by }
else if item.name /= "Aged Brie" && item.name /= "Sulfuras, Hand of Ragnaros" then
if item.sell_by < 0 && item.quality > 0 then
if item.quality >= 2 then
{ item | sell_by = item.sell_by - 1, quality = item.quality - 2 }
else
{ item | sell_by = item.sell_by - 1, quality = 0 }
else if item.quality >= 1 then
{ item | sell_by = item.sell_by - 1, quality = item.quality - 1 }
else
{ item | sell_by = item.sell_by - 1, quality = 0 }
else
item
)
items

7
elm/src/Main.elm Normal file
View File

@ -0,0 +1,7 @@
module Main exposing (main)
import Html exposing (..)
main =
text "Gilded Rose"

View File

@ -0,0 +1,18 @@
module GildedRoseTest exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import GildedRose exposing (..)
import Test exposing (..)
suite : Test
suite =
test "example test"
(\_ ->
let
foo =
Item "foo" 10 30
in
Expect.equal foo.name "fixme"
)