diff --git a/elm/.gitignore b/elm/.gitignore new file mode 100644 index 00000000..d9100021 --- /dev/null +++ b/elm/.gitignore @@ -0,0 +1,5 @@ +elm-stuff +# elm-repl generated files +repl-temp-* +*.src +src/index.html diff --git a/elm/README.md b/elm/README.md new file mode 100644 index 00000000..30aa4660 --- /dev/null +++ b/elm/README.md @@ -0,0 +1,7 @@ +# Gilded Rose (elm) + +To run tests, enter `elm-test` + +### Installing `elm-test` + +https://github.com/elm-explorations/test diff --git a/elm/elm.json b/elm/elm.json new file mode 100644 index 00000000..5c475c39 --- /dev/null +++ b/elm/elm.json @@ -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" + } + } +} diff --git a/elm/src/GildedRose.elm b/elm/src/GildedRose.elm new file mode 100644 index 00000000..bf97c94a --- /dev/null +++ b/elm/src/GildedRose.elm @@ -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 diff --git a/elm/src/Main.elm b/elm/src/Main.elm new file mode 100644 index 00000000..bb225f23 --- /dev/null +++ b/elm/src/Main.elm @@ -0,0 +1,7 @@ +module Main exposing (main) + +import Html exposing (..) + + +main = + text "Gilded Rose" diff --git a/elm/tests/GildedRoseTest.elm b/elm/tests/GildedRoseTest.elm new file mode 100644 index 00000000..2a2cff01 --- /dev/null +++ b/elm/tests/GildedRoseTest.elm @@ -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" + )