mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
updated tests and added README, based on review feedback.
This commit is contained in:
parent
42d6bce336
commit
4f43ddb78f
8
janet/.gitignore
vendored
8
janet/.gitignore
vendored
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!project.janet
|
!project.janet
|
||||||
!gilded-rose/
|
!README.md
|
||||||
!gilded-rose/main.janet
|
|
||||||
|
!src/
|
||||||
|
!src/main.janet
|
||||||
!test/
|
!test/
|
||||||
!test/*.janet
|
!test/*.janet
|
||||||
|
|||||||
39
janet/README.md
Normal file
39
janet/README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# Gilded Rose
|
||||||
|
|
||||||
|
This is the Gilded Rose kata in [janet](https://janet-lang.org).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
We'll need to install [janet and jpm](https://janet-lang.org/docs/index.html).
|
||||||
|
|
||||||
|
## Running texttest
|
||||||
|
|
||||||
|
To produce output suitable for texttest, we can run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
janet test/texttest.janet
|
||||||
|
```
|
||||||
|
|
||||||
|
We can specify the number of days as an argument:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
janet test/texttest.janet 30
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running tests
|
||||||
|
|
||||||
|
First, we install the test library dependency using `jpm -l deps`. Then we can run all the tests using:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jpm -l test
|
||||||
|
```
|
||||||
|
|
||||||
|
The testing library being used is [judge](https://github.com/ianthehenry/judge), that enables the writing of inline snapshot tests.
|
||||||
|
Specifically, Judge has the ability to capture a snapshot of stdout, which gives us a similar experience to that offered by texttest, but natively in the janet tests.
|
||||||
|
|
||||||
|
Having run `jpm -l deps`, we now have a (repository-local) installed executable of judge, which we can run directly using:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./jpm_tree/bin/judge
|
||||||
|
```
|
||||||
|
(pass `-h` for usage).
|
||||||
@ -3,10 +3,4 @@
|
|||||||
:description "A program for updating inventory at the Gilded Rose"
|
:description "A program for updating inventory at the Gilded Rose"
|
||||||
:dependencies ["https://github.com/ianthehenry/judge.git"])
|
:dependencies ["https://github.com/ianthehenry/judge.git"])
|
||||||
|
|
||||||
|
(task "test" [] (shell "jpm_tree/bin/judge"))
|
||||||
(declare-executable
|
|
||||||
:name "gilded-rose"
|
|
||||||
:entry "gilded-rose/main.janet"
|
|
||||||
:install true)
|
|
||||||
|
|
||||||
(task "test" [] (shell "jpm_tree/bin/judge"))
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
(defn item [name quality sell-in] @{:name name :quality quality :sell-in sell-in})
|
||||||
|
|
||||||
(defn update-quality [items]
|
(defn update-quality [items]
|
||||||
(for i 0 (length items)
|
(for i 0 (length items)
|
||||||
(if (and
|
(if (and
|
||||||
@ -29,23 +31,12 @@
|
|||||||
(if (> 50 ((get items i) :quality))
|
(if (> 50 ((get items i) :quality))
|
||||||
(put (get items i) :quality (+ ((get items i) :quality) 1)))))))
|
(put (get items i) :quality (+ ((get items i) :quality) 1)))))))
|
||||||
|
|
||||||
(defn item-to-str [x]
|
(defn- item-to-str [x]
|
||||||
(string (get x :name) ", " (get x :sell-in) ", " (get x :quality)))
|
(string (get x :name) ", " (get x :sell-in) ", " (get x :quality)))
|
||||||
|
|
||||||
(defn main [& args]
|
(defn run [days items]
|
||||||
(def num-days (scan-number (or (get args 1) "2")))
|
|
||||||
(print "OMGHAI!")
|
(print "OMGHAI!")
|
||||||
(def items
|
(for i 0 (+ 1 days)
|
||||||
[@{ :name "+5 Dexterity Vest" :quality 20 :sell-in 10}
|
|
||||||
@{ :name "Aged Brie" :quality 0 :sell-in 2}
|
|
||||||
@{ :name "Elixir of the Mongoose" :quality 7 :sell-in 5}
|
|
||||||
@{ :name "Sulfuras, Hand of Ragnaros" :quality 80 :sell-in 0}
|
|
||||||
@{ :name "Sulfuras, Hand of Ragnaros" :quality 80 :sell-in -1}
|
|
||||||
@{ :name "Backstage passes to a TAFKAL80ETC concert" :quality 20 :sell-in 15}
|
|
||||||
@{ :name "Backstage passes to a TAFKAL80ETC concert" :quality 49 :sell-in 10}
|
|
||||||
@{ :name "Backstage passes to a TAFKAL80ETC concert" :quality 49 :sell-in 5}
|
|
||||||
@{ :name "Conjured Mana Cake" :quality 6 :sell-in 3}])
|
|
||||||
(for i 0 num-days
|
|
||||||
(do
|
(do
|
||||||
(print (string "-------- day " i " --------"))
|
(print (string "-------- day " i " --------"))
|
||||||
(print "name, sellIn, quality")
|
(print "name, sellIn, quality")
|
||||||
@ -1,10 +1,7 @@
|
|||||||
(import ../gilded-rose/main)
|
(import ../src/main :as shop)
|
||||||
(use judge)
|
(use judge)
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(def items
|
(def items [(shop/item "foo" 0 0)])
|
||||||
[@{ :name "foo" :quality 3 :sell-in 5}
|
(shop/update-quality items)
|
||||||
@{ :name "bar" :quality 6 :sell-in 6}])
|
(test ((first items) :name) "fixme"))
|
||||||
(main/update-quality items)
|
|
||||||
(def found (find |(= ($ :quality) 2) items))
|
|
||||||
(test (found :name) "fixme"))
|
|
||||||
|
|||||||
22
janet/test/texttest.janet
Normal file
22
janet/test/texttest.janet
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
(import ../src/main :as shop)
|
||||||
|
|
||||||
|
(defn get-items []
|
||||||
|
[ (shop/item "+5 Dexterity Vest" 20 10)
|
||||||
|
(shop/item "Aged Brie" 0 2)
|
||||||
|
(shop/item "Elixir of the Mongoose" 7 5)
|
||||||
|
(shop/item "Sulfuras, Hand of Ragnaros" 80 0)
|
||||||
|
(shop/item "Sulfuras, Hand of Ragnaros" 80 -1)
|
||||||
|
(shop/item "Backstage passes to a TAFKAL80ETC concert" 20 15)
|
||||||
|
(shop/item "Backstage passes to a TAFKAL80ETC concert" 49 10)
|
||||||
|
(shop/item "Backstage passes to a TAFKAL80ETC concert" 49 5)
|
||||||
|
(shop/item "Conjured Mana Cake" 6 3)])
|
||||||
|
|
||||||
|
# judge allows for snapshot testing of stdout, much like the texttest tool.
|
||||||
|
# So something like the following would create a janet-native test of the output of shop/run:
|
||||||
|
#
|
||||||
|
# (test-stdout (shop/run 30 (get-items)))
|
||||||
|
|
||||||
|
(defn main [& args]
|
||||||
|
(def num-days (scan-number (or (get args 1) "-1")))
|
||||||
|
(def items (get-items))
|
||||||
|
(shop/run num-days items))
|
||||||
Loading…
Reference in New Issue
Block a user