mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Add Gilded Rose exercise
This commit is contained in:
parent
a204601429
commit
c7bdcb974c
@ -1,2 +1,3 @@
|
|||||||
(library
|
(library
|
||||||
|
(preprocess (pps ppx_deriving.show))
|
||||||
(name gilded_rose))
|
(name gilded_rose))
|
||||||
|
|||||||
54
ocaml/lib/gilded_rose.ml
Normal file
54
ocaml/lib/gilded_rose.ml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
module Item = struct
|
||||||
|
type t = { name : string; sell_in : int; quality : int } [@@deriving show]
|
||||||
|
|
||||||
|
let v name sell_in quality = { name; sell_in; quality }
|
||||||
|
end
|
||||||
|
|
||||||
|
module Items = struct
|
||||||
|
type items = Item.t list [@@deriving show]
|
||||||
|
|
||||||
|
let v ?(items = []) () = items
|
||||||
|
let show items : string = show_items items
|
||||||
|
|
||||||
|
let update_quality items =
|
||||||
|
let update_quality_items ({ name; sell_in; quality } as item : Item.t) =
|
||||||
|
let quality' =
|
||||||
|
if
|
||||||
|
name <> "Aged Brie"
|
||||||
|
&& name <> "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
then
|
||||||
|
if quality > 0 then
|
||||||
|
if name <> "Sulfuras, Hand of Ragnaros" then quality - 1
|
||||||
|
else quality
|
||||||
|
else quality
|
||||||
|
else if quality < 50 then
|
||||||
|
quality + 1
|
||||||
|
+
|
||||||
|
if name = "Backstage passes to a TAFKAL80ETC concert" then
|
||||||
|
if sell_in < 11 then
|
||||||
|
if quality < 49 then
|
||||||
|
1 + if sell_in < 6 then if quality < 48 then 1 else 0 else 0
|
||||||
|
else 0
|
||||||
|
else 0
|
||||||
|
else 0
|
||||||
|
else quality
|
||||||
|
in
|
||||||
|
let sell_in' =
|
||||||
|
if name <> "Sulfuras, Hand of Ragnaros" then sell_in - 1 else sell_in
|
||||||
|
in
|
||||||
|
if sell_in' < 0 then
|
||||||
|
if name <> "Aged Brie" then
|
||||||
|
if name <> "Backstage passes to a TAFKAL80ETC concert" then
|
||||||
|
if quality' > 0 then
|
||||||
|
if name <> "Sulfuras, Hand of Ragnaros" then
|
||||||
|
{ item with sell_in = sell_in'; quality = quality' - 1 }
|
||||||
|
else { item with sell_in = sell_in'; quality = quality' }
|
||||||
|
else { item with sell_in = sell_in'; quality = quality' }
|
||||||
|
else { item with sell_in = sell_in'; quality = quality' - quality' }
|
||||||
|
else if quality' < 50 then
|
||||||
|
{ item with sell_in = sell_in'; quality = quality' + 1 }
|
||||||
|
else { item with sell_in = sell_in'; quality = quality' }
|
||||||
|
else { item with sell_in = sell_in'; quality = quality' }
|
||||||
|
in
|
||||||
|
List.map update_quality_items items
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user