Sha256: 85e2fc7fea43c1e99064dbeb18f5fc417bf039d9598f7ea3a088c053d1e0682f

Contents?: true

Size: 1.58 KB

Versions: 395

Compression:

Stored size: 1.58 KB

Contents

(ns bank-account-test
  (:require
    [clojure.test :refer [deftest testing is use-fixtures]]
    [bank-account]))

(defn shutdown-agents-fixture [f]
  (f)
  (shutdown-agents))

(use-fixtures :once shutdown-agents-fixture)

(deftest initial-account-state
  (testing "Accounts are opened with a balance of 0"
    (is (= 0 (-> (bank-account/open-account)
                 (bank-account/get-balance))))))

(deftest increment-and-get-balance
  (testing "Adding money to the account works"
    (let [account (bank-account/open-account)]
      (is (= 0 (bank-account/get-balance account)))
      (bank-account/update-balance account 10)
      (is (= 10 (bank-account/get-balance account))))))

(deftest increment-decrement-and-get-balance
  (testing "Taking money out of the account works"
    (let [account (bank-account/open-account)]
      (is (= 0 (bank-account/get-balance account)))
      (bank-account/update-balance account 10)
      (is (= 10 (bank-account/get-balance account)))
      (bank-account/update-balance account -10)
      (is (= 0 (bank-account/get-balance account))))))

(deftest closed-accounts-are-nil
  (testing "Closing an account makes it nil"
    (let [account (bank-account/open-account)]
      (bank-account/close-account account)
      (is (nil? (bank-account/get-balance account))))))

(deftest check-concurrent-access
  (testing "The account can handle parallel access"
    (let [account (bank-account/open-account)
          add-10 #(bank-account/update-balance account 10)]
      (doall (pcalls add-10 add-10 add-10 add-10 add-10))
      (is (= 50 (bank-account/get-balance account))))))

Version data entries

395 entries across 395 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.179 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.178 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.177 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.176 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.175 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.174 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.173 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.172 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.171 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.170 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.169 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.167 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.166 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.165 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.164 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.163 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.162 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.161 tracks/clojure/exercises/bank-account/test/bank_account_test.clj
trackler-2.2.1.160 tracks/clojure/exercises/bank-account/test/bank_account_test.clj