mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
add janet version
This commit is contained in:
parent
d0d6fdb93c
commit
42d6bce336
8
janet/.gitignore
vendored
Normal file
8
janet/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
*
|
||||
|
||||
!.gitignore
|
||||
!project.janet
|
||||
!gilded-rose/
|
||||
!gilded-rose/main.janet
|
||||
!test/
|
||||
!test/*.janet
|
||||
55
janet/gilded-rose/main.janet
Normal file
55
janet/gilded-rose/main.janet
Normal file
@ -0,0 +1,55 @@
|
||||
(defn update-quality [items]
|
||||
(for i 0 (length items)
|
||||
(if (and
|
||||
(not (= "Aged Brie" ((get items i) :name)))
|
||||
(not (= "Backstage passes to a TAFKAL80ETC concert" ((get items i) :name))))
|
||||
(if (< 0 ((get items i) :quality))
|
||||
(if (not (= "Sulfuras, Hand of Ragnaros" ((get items i) :name)))
|
||||
(put (get items i) :quality (- ((get items i) :quality) 1))))
|
||||
(if (> 50 ((get items i) :quality))
|
||||
(do
|
||||
(put (get items i) :quality (+ ((get items i) :quality) 1))
|
||||
(if (= "Backstage passes to a TAFKAL80ETC concert" ((get items i) :name))
|
||||
(do
|
||||
(if (> 11 ((get items i) :sell-in))
|
||||
(if (> 50 ((get items i) :quality))
|
||||
(put (get items i) :quality (+ ((get items i) :quality) 1))))
|
||||
(if (> 6 ((get items i) :sell-in))
|
||||
(if (> 50 ((get items i) :quality))
|
||||
(put (get items i) :quality (+ ((get items i) :quality) 1)))))))))
|
||||
(if (not (= "Sulfuras, Hand of Ragnaros" ((get items i) :name)))
|
||||
(put (get items i) :sell-in (- ((get items i) :sell-in) 1)))
|
||||
(if (> 0 ((get items i) :sell-in))
|
||||
(if (not (= "Aged Brie" ((get items i) :name)))
|
||||
(if (not (= "Backstage passes to a TAFKAL80ETC concert" ((get items i) :name)))
|
||||
(if (< 0 ((get items i) :quality))
|
||||
(if (not (= "Sulfuras, Hand of Ragnaros" ((get items i) :name)))
|
||||
(put (get items i) :quality (- ((get items i) :quality) 1))))
|
||||
(put (get items i) :quality (- ((get items i) :quality) ((get items i) :quality))))
|
||||
(if (> 50 ((get items i) :quality))
|
||||
(put (get items i) :quality (+ ((get items i) :quality) 1)))))))
|
||||
|
||||
(defn item-to-str [x]
|
||||
(string (get x :name) ", " (get x :sell-in) ", " (get x :quality)))
|
||||
|
||||
(defn main [& args]
|
||||
(def num-days (scan-number (or (get args 1) "2")))
|
||||
(print "OMGHAI!")
|
||||
(def items
|
||||
[@{ :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
|
||||
(print (string "-------- day " i " --------"))
|
||||
(print "name, sellIn, quality")
|
||||
(for j 0 (length items)
|
||||
(print (item-to-str (get items j))))
|
||||
(print "")
|
||||
(update-quality items))))
|
||||
12
janet/project.janet
Normal file
12
janet/project.janet
Normal file
@ -0,0 +1,12 @@
|
||||
(declare-project
|
||||
:name "gilded-rose"
|
||||
:description "A program for updating inventory at the Gilded Rose"
|
||||
:dependencies ["https://github.com/ianthehenry/judge.git"])
|
||||
|
||||
|
||||
(declare-executable
|
||||
:name "gilded-rose"
|
||||
:entry "gilded-rose/main.janet"
|
||||
:install true)
|
||||
|
||||
(task "test" [] (shell "jpm_tree/bin/judge"))
|
||||
10
janet/test/gilded-rose.janet
Normal file
10
janet/test/gilded-rose.janet
Normal file
@ -0,0 +1,10 @@
|
||||
(import ../gilded-rose/main)
|
||||
(use judge)
|
||||
|
||||
(do
|
||||
(def items
|
||||
[@{ :name "foo" :quality 3 :sell-in 5}
|
||||
@{ :name "bar" :quality 6 :sell-in 6}])
|
||||
(main/update-quality items)
|
||||
(def found (find |(= ($ :quality) 2) items))
|
||||
(test (found :name) "fixme"))
|
||||
Loading…
Reference in New Issue
Block a user