Last active
March 5, 2020 10:16
-
-
Save iGEL/1d64bb96b638bb140647e27a9167c57d to your computer and use it in GitHub Desktop.
Clojure version of the tests for Kata 09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This is an adapted version of the tests from http://codekata.com/kata/kata09-back-to-the-checkout/ for Clojure | |
;; Original version by Dave Thomas | |
;; Run it like this: | |
;; lein exec check_out.clj | |
;; # or with Docker: | |
;; docker run -v `pwd`:`pwd` -w `pwd` clojure:alpine lein exec check_out.clj | |
(ns check-out.core | |
(:require [clojure.test :refer [is are deftest testing run-tests]] | |
clojure.string)) | |
(defn new-bill! [pricing-rules] | |
) | |
(defn scan [item] | |
) | |
(defn total [] | |
0) | |
(deftest scan-test | |
;; Item Unit Special | |
;; Price Price | |
;; -------------------------- | |
;; A 50 3 for 130 | |
;; B 30 2 for 45 | |
;; C 20 | |
;; D 15 | |
(let [pricing-rules (throw (RuntimeException. "Implement me"))] | |
(testing "incremential scanning one bill" | |
(new-bill! pricing-rules) | |
(is (= 0 (total))) | |
(scan "A") | |
(is (= 50 (total))) | |
(scan "B") | |
(is (= 80 (total))) | |
(scan "A") | |
(is (= 130 (total))) | |
(scan "A") | |
(is (= 160 (total))) | |
(scan "B") | |
(is (= 175 (total)))) | |
(testing "totals" | |
(let [total-of (fn [items] | |
(new-bill! pricing-rules) | |
(doseq [item (clojure.string/split items #"")] | |
(scan item)) | |
(total))] | |
(is (= 50 (total-of "A"))) | |
(is (= 80 (total-of "AB"))) | |
;; The following lines are tests like above, just written more compactly. | |
;; Each line has the expected amount and a string of items, which is split into a list. | |
(are [expected given-items] (= expected (total-of given-items)) | |
130 "ABA" | |
160 "ABAA" | |
175 "ABAAB" | |
115 "CDBA" | |
100 "AA" | |
130 "AAA" | |
180 "AAAA" | |
230 "AAAAA" | |
260 "AAAAAA" | |
160 "AAAB" | |
175 "AAABB" | |
190 "AAABBD" | |
190 "DABABA"))))) | |
(run-tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject check-out "0.1.0-SNAPSHOT" | |
:dependencies [[org.clojure/clojure "1.10.0"]] | |
:plugins [[lein-exec "0.3.7"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment