diff --git a/lisp/compound-interest-test.lisp b/lisp/compound-interest-test.lisp index e9f8de7..1031947 100644 --- a/lisp/compound-interest-test.lisp +++ b/lisp/compound-interest-test.lisp @@ -5,43 +5,43 @@ (list (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 () - (eq (compound-interest 100000 10 0) 100000) + (assert= 100000 (compound-interest 100000 10 0)) ) (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 () - (eq (compound-interest 100000 5 2) 110250) + (assert= 110250 (compound-interest 100000 5 2)) ) (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 () - (eq (compound-interest 100000 5 4) 121551) + (assert= 121551 (compound-interest 100000 5 4)) ) (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 () - (eq (compound-interest 100000 (- 5) 2) 90250) + (assert= 90250 (compound-interest 100000 (- 5) 2)) ) (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 () - (eq (compound-interest 100000 (- 5) 4) 81450) + (assert= 81450 (compound-interest 100000 (- 5) 4)) ) ) diff --git a/lisp/compound-interest.lisp b/lisp/compound-interest.lisp index 61ca082..0817706 100644 --- a/lisp/compound-interest.lisp +++ b/lisp/compound-interest.lisp @@ -3,14 +3,14 @@ (defun percent (n percent) (cond ((> percent 0) (/ (+ (* n percent) 50) 100)) - (t (/ (- (* n percent) 50) 100)) + (T (/ (- (* n percent) 50) 100)) ) ) (defun compound-interest (principal rate years) (cond ((= years 0) principal) - (t (compound-interest (+ principal (percent principal rate)) + (T (compound-interest (+ principal (percent principal rate)) rate (decrement years) ) diff --git a/lisp/compound-test.lisp b/lisp/compound-test.lisp deleted file mode 100644 index 8179405..0000000 --- a/lisp/compound-test.lisp +++ /dev/null @@ -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) - ) - - ) -) - diff --git a/lisp/compound.lisp b/lisp/compound.lisp deleted file mode 100644 index 0f46729..0000000 --- a/lisp/compound.lisp +++ /dev/null @@ -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) - ) - ) - ) - ) -) diff --git a/lisp/unit-test.lisp b/lisp/unit-test.lisp index 31d2642..896257b 100644 --- a/lisp/unit-test.lisp +++ b/lisp/unit-test.lisp @@ -12,5 +12,12 @@ ) (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) + ) )