Updates to the unit test framework
This commit is contained in:
parent
fa45434228
commit
35550c46ac
|
@ -5,43 +5,43 @@
|
||||||
(list
|
(list
|
||||||
|
|
||||||
(defun many-years-with-no-interest-rate ()
|
(defun many-years-with-no-interest-rate ()
|
||||||
(eq (compound-interest 100000 0 10) 100000)
|
(assert= 100000 (compound-interest 100000 0 10))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun no-years-with-positive-interest-rate ()
|
(defun no-years-with-positive-interest-rate ()
|
||||||
(eq (compound-interest 100000 10 0) 100000)
|
(assert= 100000 (compound-interest 100000 10 0))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun one-year-with-positive-interest-rate ()
|
(defun one-year-with-positive-interest-rate ()
|
||||||
(eq (compound-interest 100000 5 1) 105000)
|
(assert= 105000 (compound-interest 100000 5 1))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun two-years-with-positive-interest-rate ()
|
(defun two-years-with-positive-interest-rate ()
|
||||||
(eq (compound-interest 100000 5 2) 110250)
|
(assert= 110250 (compound-interest 100000 5 2))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun three-years-with-positive-interest-rate ()
|
(defun three-years-with-positive-interest-rate ()
|
||||||
(eq (compound-interest 100000 5 3) 115763)
|
(assert= 115763 (compound-interest 100000 5 3))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun four-years-with-positive-interest-rate ()
|
(defun four-years-with-positive-interest-rate ()
|
||||||
(eq (compound-interest 100000 5 4) 121551)
|
(assert= 121551 (compound-interest 100000 5 4))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun one-year-with-negative-interest-rate ()
|
(defun one-year-with-negative-interest-rate ()
|
||||||
(eq (compound-interest 100000 (- 5) 1) 95000)
|
(assert= 95000 (compound-interest 100000 (- 5) 1))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun two-years-with-negative-interest-rate ()
|
(defun two-years-with-negative-interest-rate ()
|
||||||
(eq (compound-interest 100000 (- 5) 2) 90250)
|
(assert= 90250 (compound-interest 100000 (- 5) 2))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun three-years-with-negative-interest-rate ()
|
(defun three-years-with-negative-interest-rate ()
|
||||||
(eq (compound-interest 100000 (- 5) 3) 85737)
|
(assert= 85737 (compound-interest 100000 (- 5) 3))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun four-years-with-negative-interest-rate ()
|
(defun four-years-with-negative-interest-rate ()
|
||||||
(eq (compound-interest 100000 (- 5) 4) 81450)
|
(assert= 81450 (compound-interest 100000 (- 5) 4))
|
||||||
)
|
)
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
(defun percent (n percent)
|
(defun percent (n percent)
|
||||||
(cond
|
(cond
|
||||||
((> percent 0) (/ (+ (* n percent) 50) 100))
|
((> percent 0) (/ (+ (* n percent) 50) 100))
|
||||||
(t (/ (- (* n percent) 50) 100))
|
(T (/ (- (* n percent) 50) 100))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun compound-interest (principal rate years)
|
(defun compound-interest (principal rate years)
|
||||||
(cond
|
(cond
|
||||||
((= years 0) principal)
|
((= years 0) principal)
|
||||||
(t (compound-interest (+ principal (percent principal rate))
|
(T (compound-interest (+ principal (percent principal rate))
|
||||||
rate
|
rate
|
||||||
(decrement years)
|
(decrement years)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
(load "unit-test.lisp")
|
|
||||||
(load "compound.lisp")
|
|
||||||
|
|
||||||
(unit
|
|
||||||
(list
|
|
||||||
|
|
||||||
(defun many-years-with-no-interest-rate ()
|
|
||||||
(eq (compound 100000 0 10) 100000)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun no-years-with-positive-interest-rate ()
|
|
||||||
(eq (compound 100000 10 0) 100000)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun one-year-with-positive-interest-rate ()
|
|
||||||
(eq (compound 100000 5 1) 105000)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun two-years-with-positive-interest-rate ()
|
|
||||||
(eq (compound 100000 5 2) 110250)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun three-years-with-positive-interest-rate ()
|
|
||||||
(eq (compound 100000 5 3) 115763)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun four-years-with-positive-interest-rate ()
|
|
||||||
(eq (compound 100000 5 4) 121551)
|
|
||||||
)
|
|
||||||
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
(defun compound (principal interest-rate years)
|
|
||||||
(cond
|
|
||||||
((= years 0) principal)
|
|
||||||
(t (let ( (previous-principal (compound principal interest-rate (- years 1))) )
|
|
||||||
(+ previous-principal
|
|
||||||
(/ (+ (* previous-principal
|
|
||||||
interest-rate)
|
|
||||||
50)
|
|
||||||
100)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
|
@ -12,5 +12,12 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun unit (test-suite)
|
(defun unit (test-suite)
|
||||||
(apply 'and (run-test-suite test-suite))
|
(eval (cons 'and (run-test-suite test-suite)))
|
||||||
|
)
|
||||||
|
|
||||||
|
(defun assert= (expected actual)
|
||||||
|
(cond
|
||||||
|
((= expected actual) T)
|
||||||
|
(T (print (list expected 'is 'not actual)) nil)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue