-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from maiste/port-for-ocaml
Gilded Rose port for OCaml
- Loading branch information
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
profile = default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Gilded Rose Kata for OCaml | ||
|
||
### Requirements | ||
|
||
To run the project, the following package must be available on your computer: | ||
- `opam` `>= 2.0` | ||
|
||
### Installation | ||
|
||
At the root of the _ocaml_ directory, execute: | ||
```sh | ||
opam switch create . --deps-only | ||
eval $(opam env) | ||
``` | ||
|
||
It will install all the required dependencies for the project to run. | ||
|
||
### Running | ||
|
||
This project relies on `dune`. To build it, run this command in your terminal: | ||
```sh | ||
dune exec gilded_rose | ||
``` | ||
|
||
### Testing | ||
|
||
The test suite is built with `Alcostest`. To launch the tests, just type: | ||
```sh | ||
dune runtest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(lang dune 3.11) | ||
(generate_opam_files true) | ||
|
||
(name gilded_rose) | ||
(source | ||
(github emilybache/GildedRose-Refactoring-Kata)) | ||
(authors "Maiste <[email protected]>") | ||
(maintainers "Maiste <[email protected]>") | ||
(license MIT) | ||
(documentation https://github.com/emilybache/GildedRose-Refactoring-Kata) | ||
|
||
(package | ||
(name gilded_rose) | ||
(synopsis "Gilded Rose Refactoring Kata") | ||
(description "The Gilded Rose Refactoring Kata in OCaml") | ||
(depends | ||
(ocaml (>= 4.08)) | ||
dune | ||
ppx_deriving | ||
(alcotest (>= 1.7.0)))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
synopsis: "Gilded Rose Refactoring Kata" | ||
description: "The Gilded Rose Refactoring Kata in OCaml" | ||
maintainer: ["Maiste <[email protected]>"] | ||
authors: ["Maiste <[email protected]>"] | ||
license: "MIT" | ||
homepage: "https://github.com/emilybache/GildedRose-Refactoring-Kata" | ||
doc: "https://github.com/emilybache/GildedRose-Refactoring-Kata" | ||
bug-reports: | ||
"https://github.com/emilybache/GildedRose-Refactoring-Kata/issues" | ||
depends: [ | ||
"ocaml" {>= "4.08"} | ||
"dune" {>= "3.11"} | ||
"ppx_deriving" | ||
"alcotest" {>= "1.7.0"} | ||
"odoc" {with-doc} | ||
] | ||
build: [ | ||
["dune" "subst"] {dev} | ||
[ | ||
"dune" | ||
"build" | ||
"-p" | ||
name | ||
"-j" | ||
jobs | ||
"@install" | ||
"@runtest" {with-test} | ||
"@doc" {with-doc} | ||
] | ||
] | ||
dev-repo: "git+https://github.com/emilybache/GildedRose-Refactoring-Kata.git" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(library | ||
(preprocess (pps ppx_deriving.show)) | ||
(name gilded_rose)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(test | ||
(name gilded_rose) | ||
(libraries gilded_rose alcotest)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open Gilded_rose | ||
|
||
let test () = | ||
let items = Items.v ~items:[ Item.v "Foo" 10 20 ] () in | ||
Alcotest.(check string) | ||
"Broken test" "Fixme" | ||
(List.hd items |> fun item -> item.name) | ||
|
||
let () = | ||
let open Alcotest in | ||
run "Gilded Rose" [ ("Our first test", [ test_case "fixme" `Quick test ]) ] |