-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Elisp version of the kata #572
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(require 'ert) | ||
(require 'gilded-rose) | ||
|
||
(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")))) | ||
|
||
(ert-run-tests-interactively t) |
MGadhvi marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(defun make-item (name sell-in quality) | ||
"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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the lets are already a simplification/improvement of the original code. Is it possible to access the value from the struct each time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. This was the simplest way I could represent the problem with the elisp I know. I'll have a look at getting the value from the struct each time |
||
(sell-in (item-sell-in item))) | ||
(cond | ||
;; Aged Brie | ||
((string= (item-name item) "Aged Brie") | ||
(setf (nth 2 item) (min 50 (1+ quality)))) | ||
|
||
;; Backstage passes | ||
((string= (item-name item) "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") | ||
(setf (nth 2 item) quality)) | ||
|
||
(provide 'gilded-rose) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
* Gilded Rose | ||
Gilded Rose kata in Elisp! | ||
|
||
* Structure | ||
~gilded-rose.el~ contains source code. ~gilded-rose-test.el~ uses [[https://www.gnu.org/software/emacs/manual/html_mono/ert.html][ert]] to run tests | ||
|
||
* Running tests | ||
- 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)~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this test similar to other sample tests, e.g. https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/clojure/test/gilded/core_test.clj
i.e. check that the name of "foo" is not "fixme".