diff --git a/lisp/compound-test.lisp b/lisp/compound-test.lisp new file mode 100644 index 0000000..8179405 --- /dev/null +++ b/lisp/compound-test.lisp @@ -0,0 +1,33 @@ +(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 new file mode 100644 index 0000000..0f46729 --- /dev/null +++ b/lisp/compound.lisp @@ -0,0 +1,14 @@ +(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 15f297a..31d2642 100644 --- a/lisp/unit-test.lisp +++ b/lisp/unit-test.lisp @@ -1,7 +1,7 @@ (defun run-unit-test (unit-test) (cond - ((funcall unit-test) (print (cons (symbol-function unit-test) T)) T) - (T (print (cons (symbol-function unit-test) 'F)) NIL) + ((funcall unit-test) (print (cons T unit-test)) T) + (T (print (cons 'F unit-test)) NIL) ) )