mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 20:32:15 +00:00
* Amendments
- Initial test modified to be similar to Clojure version - update-quality modified to read from make-item directly. Helper methods removed
This commit is contained in:
parent
3615cfb8ab
commit
91ebc85a70
@ -1,9 +1,10 @@
|
||||
(require 'ert)
|
||||
(require 'gilded-rose)
|
||||
|
||||
|
||||
(defconst foo (make-item "foo" 20 10))
|
||||
|
||||
(ert-deftest check-name-of-item ()
|
||||
"Test that item is called sweets. This test should fail!"
|
||||
(let ((sweets (make-item "sweets" 5 5)))
|
||||
(should (string= (item-name sweets) "You should change this"))))
|
||||
(should (string= "fixme" (plist-get foo :name))))
|
||||
|
||||
(ert-run-tests-interactively t)
|
||||
|
||||
@ -2,37 +2,22 @@
|
||||
"Create an item with NAME, SELL-IN, and QUALITY."
|
||||
(list :name name :sell-in sell-in :quality quality))
|
||||
|
||||
(defun item-name (item)
|
||||
"Return the name of ITEM."
|
||||
(plist-get item :name))
|
||||
|
||||
(defun item-sell-in (item)
|
||||
"Return the sell-in value of ITEM."
|
||||
(plist-get item :sell-in))
|
||||
|
||||
(defun item-quality (item)
|
||||
"Return the quality of ITEM."
|
||||
(plist-get item :quality))
|
||||
|
||||
(defun update-quality (item)
|
||||
"Update the quality of the ITEM according to the Gilded Rose rules."
|
||||
(let ((quality (item-quality item))
|
||||
(sell-in (item-sell-in item)))
|
||||
(let* ((quality (plist-get item :quality))
|
||||
(sell-in (plist-get item :sell-in))
|
||||
(name (plist-get item :name)))
|
||||
(cond
|
||||
;; Aged Brie
|
||||
((string= (item-name item) "Aged Brie")
|
||||
((string= name "Aged Brie")
|
||||
(setf (nth 2 item) (min 50 (1+ quality))))
|
||||
|
||||
;; Backstage passes
|
||||
((string= (item-name item) "Backstage passes")
|
||||
((string= name "Backstage passes")
|
||||
(cond
|
||||
((> sell-in 10) (setf (nth 2 item) quality))
|
||||
((and (<= sell-in 10) (> sell-in 5)) (setf (nth 2 item) (min 50 (+ quality 2))))
|
||||
((and (<= sell-in 5) (> sell-in 0)) (setf (nth 2 item) (min 50 (+ quality 3))))
|
||||
(t (setf (nth 2 item) 0))))
|
||||
|
||||
;; Sulfuras
|
||||
((string= (item-name item) "Sulfuras")
|
||||
((string= name "Sulfuras")
|
||||
(setf (nth 2 item) quality))
|
||||
(t
|
||||
(setf (nth 2 item) (max 0 (1- quality)))))))
|
||||
|
||||
(provide 'gilded-rose)
|
||||
|
||||
@ -8,3 +8,6 @@ Gilded Rose kata in Elisp!
|
||||
- Use the command ~eval-buffer~ on ~gilded-rose.el~
|
||||
- Use the command ~eval-buffer~ on ~gilded-rose-test.el~
|
||||
- Test can be run interactively using the command ~ert~ or with ~(ert-run-tests-interactively t)~
|
||||
|
||||
* Todo
|
||||
- Add TestText fixture
|
||||
|
||||
Loading…
Reference in New Issue
Block a user