Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions elisp/gilded-rose-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(require 'ert)
(require 'gilded-rose)


(defconst foo (make-item "foo" 20 10))

(ert-deftest check-name-of-item ()
(should (string= "fixme" (plist-get foo :name))))

(ert-run-tests-interactively t)
23 changes: 23 additions & 0 deletions elisp/gilded-rose.el
MGadhvi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(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 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)))))))

(provide 'gilded-rose)
13 changes: 13 additions & 0 deletions elisp/readme.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* 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)~

* Todo
- Add TestText fixture