Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 729f593251
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 30 lines (22 sloc) 0.91 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
(ns iterate-clojure-workshop12.task14-java-interop
  (:require [clojure.test :refer :all]))

;; ### TASK A ###
;; Help Uncle Scrooge (Skrue) to keep a list of his debtors.
;; Create a Java HashMap and two functions, add-debtor [name amount]
;; and check-debt [name]. Add the initial debtor Donald Duck owing
;; $1814 to make the Uncle happy.
;; (Notice that the Uncle doesn't require any remove function in the
;; first iteration as its business value has been deemed diminutive.)

(def debtors (new java.util.HashMap))

(defn add-debtor [name amount]
  (.put debtors name amount))

(defn check-debt [name]
  (.get debtors name))

(add-debtor "Donald Duck" 1814)

;; Tests
(deftest check-debtor-test
  (is (= 1814 (check-debt "Donald Duck")))
  (is (nil? (check-debt "Uncle Srooge"))))


(deftest add-debtor-test
  (do (add-debtor "Launchpad McQuack" 9999))
  (is (= 9999 (check-debt "Launchpad McQuack"))))
Something went wrong with that request. Please try again.