-
-
Save ericnormand/e2a506c9f5cc168ed818791498804167 to your computer and use it in GitHub Desktop.
| # Coffee shop scenario | |
| Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.* | |
| Operation set: | |
| (defn create-order []) ;;=> Order | |
| (defn add-coffee [order coffee]) ;;=> Order | |
| (defn order-price [order]) ;;=> Price | |
| (defn remove-coffee [order coffee-index]) ;;=> Order | |
| (defn update-coffee [order coffee-index f & args]) ;;=> Order | |
| (defn submit-order [order]) ;;=> OrderID | |
| (defn create-coffee []) ;;=> Coffee | |
| (defn set-size [coffee size]) ;;=> Coffee | |
| (defn set-roast [coffee roast]) ;;=> Coffee | |
| (defn add-add-in [coffee add-in]) ;;=> Coffee | |
| (defn remove-add-in [coffee add-in]) ;;=> Coffee | |
| ;; Order | |
| ;; Price - maybe a number of cents? | |
| ;; Coffee-Index - ordinal number | |
| ;; OrderID - UUID?? | |
| ;; Coffee | |
| ;; Size - small | |
| ;; Roast - dark, medium | |
| ;; Add-In - almond-syrup, soy-milk | |
| Jill starts to order some coffee at the touchscreen. | |
| She adds a small, dark roast. | |
| Then she adds a large medium roast with double almond syrup. | |
| She adds a medium medium roast with two soy milk shots (the second one by | |
| accident). | |
| She reads the price and it's too expensive. | |
| So she removes the second coffee (the one with the almond syrup). | |
| Then she realizes the third coffee has two milk soy shots and she removes one. | |
| The price looks good, so she submits the order. |
Coffee shop scenario
Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
Jill starts to order some coffee at the touchscreen.
She adds a small, dark roast.
Then she adds a large medium roast with double almond syrup.
She adds a medium medium roast with two soy milk shots (the second one by
accident).
She reads the price and it's too expensive.
So she removes the second coffee (the one with the almond syrup).
Then she realizes the third coffee has two milk soy shots and she removes one.
The price looks good, so she submits the order.
;; assuming pure functions
(let [order (create-order)
order (add-coffee order (create-coffee))
order (update-coffee order 0 set-size :small)
order (update-coffee order 0 set-roast :dark)
order (add-coffee order (create-coffee))
order (update-coffee order 1 set-size :large)
order (update-coffee order 1 set-roast :medium)
order (update-coffee order 1 add-add-in :almond-syrup)
order (update-coffee order 1 add-add-in :almond-syrup)
order (add-coffee order (create-coffee))
order (update-coffee order 2 set-size :medium)
order (update-coffee order 2 set-roast :medium)
order (update-coffee order 2 add-add-in :soy-milk)
order (update-coffee order 2 add-add-in :soy-milk)
price (order-price order)
order (remove-coffee order 1)
order (update-coffee order 1 remove-add-in :soy-milk)
price (order-price order)
order-id (submit-order order)
])
;; Jill starts to order some coffee at the touchscreen.
(-> (create-order)
;; She adds a small, dark roast.
(add-coffee (-> (create-coffee)
(set-size :small)
(set-roast :dark)))
;; Then she adds a large medium roast with double almond syrup.
(add-coffee (-> (create-coffee)
(set-size :large)
(set-roast :medium)))
;; She adds a medium medium roast with two soy milk shots (the second one by
;; accident).
(add-coffee (-> (create-coffee)
(set-size :medium)
(set-roast :medium)
(add-add-in :soy-milk-shot)
(add-add-in :soy-milk-shot)))
;; She reads the price and it's too expensive.
(#((assert (> (order-price %) <big-num>))
%))
;; So she removes the second coffee (the one with the almond syrup).
(remove-coffee 1)
;; Then she realizes the third coffee has two milk soy shots and she removes one.
(update-coffee 2 remove-add-in <coffee-3> :soy-milk-shot)
;; The price looks good, so she submits the order.
(#((assert (= (order-price %) <good-num>))
%))
submit-order)
;;# Coffee shop scenario
;;Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
;; Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
;;Jill starts to order some coffee at the touchscreen.
(def order (create-order))
;;She adds a small, dark roast.
(def coffee (create-coffee))
(def coffee (set-size coffee :small))
(def coffee (set-roast coffee :dark))
(def order (add-item-to-order coffee)) ;; ;; will give added item an id and will set coffee to base coffee
;;Then she adds a large medium roast with double almond syrup.
(def coffee (set-size coffee :large))
(def coffee (set-roast coffee :medium))
(def coffee (add-add-in coffee :almond-syrup))
(def coffee (add-add-in coffee :almond-syrup))
(def order (add-coffee order coffee))
;;She adds a medium medium roast with two soy milk shots (the second one by
;;accident).
(def coffee (set-size coffee :medium))
(def coffee (set-roast coffee :medium))
(def coffee (add-add-in coffee :soy-milk))
(def coffee (add-add-in coffee :soy-milk))
(def order (add-coffee order coffee))
;;She reads the price and it's too expensive.
;;So she removes the second coffee (the one with the almond syrup).
(def order (remove-coffee order item-id))
;;Then she realizes the third coffee has two milk soy shots and she removes one.
(def order (update-coffee order item-id remove-add-in :soy-milk))
;;The price looks good, so she submits the order.
;;TODO
Coffee shop scenario
Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.
Operation set:
(defn create-order []) ;;=> Order
(defn add-coffee [order coffee]) ;;=> Order
(defn order-price [order]) ;;=> Price
(defn remove-coffee [order coffee-index]) ;;=> Order
(defn update-coffee [order coffee-index f & args]) ;;=> Order
(defn submit-order [order]) ;;=> OrderID
(defn create-coffee []) ;;=> Coffee
(defn set-size [coffee size]) ;;=> Coffee
(defn set-roast [coffee roast]) ;;=> Coffee
(defn add-add-in [coffee add-in]) ;;=> Coffee
(defn remove-add-in [coffee add-in]) ;;=> Coffee
;; Order
;; Price - maybe a number of cents?
;; Coffee-Index - ordinal number
;; OrderID - UUID??
;; Coffee
;; Size - small
;; Roast - dark, medium
;; Add-In - almond-syrup, soy-milk
Jill starts to order some coffee at the touchscreen.
(def order (create-order))
She adds a small, dark roast.
(def coffee (-> (create-coffee)
(set-size :small)
(set-roast :dark)))
(add-coffee order coffee)
Then she adds a large medium roast with double almond syrup.
(def coffee (-> (create-coffee)
(set-size :large)
(set-roast :medium)
(add-add-in :almond-syrup)
(add-add-in :almond-syrup))
(add-coffee order coffee)
She adds a medium medium roast with two soy milk shots (the second one by
accident).
(def coffee (-> (create-coffee)
(set-size :medium)
(set-roast :medium)
(add-add-in :soy-milk)
(add-add-in :soy-milk))
(add-coffee order coffee)
She reads the price and it's too expensive.
So she removes the second coffee (the one with the almond syrup).
(def order (remove-coffee order 1))
Then she realizes the third coffee has two milk soy shots and she removes one.
The price looks good, so she submits the order.