diff --git a/elisp/gilded-rose-test.el b/elisp/gilded-rose-test.el new file mode 100644 index 0000000000..3d982f7a19 --- /dev/null +++ b/elisp/gilded-rose-test.el @@ -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) diff --git a/elisp/gilded-rose.el b/elisp/gilded-rose.el new file mode 100644 index 0000000000..c56e128073 --- /dev/null +++ b/elisp/gilded-rose.el @@ -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) diff --git a/elisp/readme.org b/elisp/readme.org new file mode 100644 index 0000000000..19187d8aad --- /dev/null +++ b/elisp/readme.org @@ -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