mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Further Amendments
- removed the cond statement and replaced with nested ifs - removed the let statement. Data is now accesses directly - update-quality now takes a list of items
This commit is contained in:
parent
91ebc85a70
commit
e9cf5311fd
@ -1,10 +1,10 @@
|
||||
(require 'ert)
|
||||
(require 'gilded-rose)
|
||||
|
||||
|
||||
(defconst foo (make-item "foo" 20 10))
|
||||
(setq item-list
|
||||
(list (make-item "foo" 5 5)))
|
||||
|
||||
(ert-deftest check-name-of-item ()
|
||||
(should (string= "fixme" (plist-get foo :name))))
|
||||
(should (string= "fixme" (plist-get (car item-list) :name))))
|
||||
|
||||
(ert-run-tests-interactively t)
|
||||
|
||||
@ -2,22 +2,26 @@
|
||||
"Create an item with NAME, SELL-IN, and QUALITY."
|
||||
(list :name name :sell-in sell-in :quality quality))
|
||||
|
||||
(defun update-quality (item)
|
||||
(let* ((quality (plist-get item :quality))
|
||||
(sell-in (plist-get item :sell-in))
|
||||
(name (plist-get item :name)))
|
||||
(cond
|
||||
((string= name "Aged Brie")
|
||||
(setf (nth 2 item) (min 50 (1+ quality))))
|
||||
((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))))
|
||||
((string= name "Sulfuras")
|
||||
(setf (nth 2 item) quality))
|
||||
(t
|
||||
(setf (nth 2 item) (max 0 (1- quality)))))))
|
||||
(defun update-quality (items)
|
||||
(dolist (item items)
|
||||
(if (string= (plist-get item :name) "Aged Brie")
|
||||
(plist-put item :quality (min 50 (1+ (plist-get item :quality))))
|
||||
|
||||
(if (string= (plist-get item :name) "Backstage passes")
|
||||
(if (> (plist-get item :sell-in) 10)
|
||||
(plist-put item :quality (plist-get item :quality))
|
||||
|
||||
(if (and (<= (plist-get item :sell-in) 10) (> (plist-get item :sell-in) 5))
|
||||
(plist-put item :quality (min 50 (+ (plist-get item :quality) 2)))
|
||||
|
||||
(if (and (<= (plist-get item :sell-in) 5) (> (plist-get item :sell-in) 0))
|
||||
(plist-put item :quality (min 50 (+ (plist-get item :quality) 3)))
|
||||
|
||||
(plist-put item :quality 0))))
|
||||
|
||||
(if (string= (plist-get item :name) "Sulfuras")
|
||||
(plist-put item :quality (plist-get item :quality))
|
||||
|
||||
(plist-put item :quality (max 0 (1- (plist-get item :quality)))))))))
|
||||
|
||||
(provide 'gilded-rose)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user