transcendental-lisp/lisp/finance/interest-compounder-test.lisp

81 lines
3.4 KiB
Common Lisp

(load "../unit/unit-test.lisp")
(load "interest-compounder.lisp")
(unit
(let ((compounder))
(list
(defun principal-initialized ()
(setf compounder (interest-compounder 1000 0))
(assert= 1000 (funcall compounder :get-principal)))
(defun interest-rate-initialized ()
(setf compounder (interest-compounder 0 10))
(assert= 10 (funcall compounder :get-interest-rate)))
(defun many-years-with-no-interest-rate ()
(setf compounder (interest-compounder 1000 0))
(funcall compounder :move-forward-years 83)
(assert= 1000 (funcall compounder :get-principal)))
(defun no-years-with-positive-interest-rate ()
(setf compounder (interest-compounder 1000 10))
(assert= 1000 (funcall compounder :get-principal)))
(defun one-year-with-positive-interest-rate ()
(setf compounder (interest-compounder 100000 5))
(funcall compounder :move-forward-one-year)
(assert= 105000 (funcall compounder :get-principal)))
(defun two-years-with-positive-interest-rate ()
(setf compounder (interest-compounder 100000 5))
(funcall compounder :move-forward-one-year)
(funcall compounder :move-forward-one-year)
(assert= 110250 (funcall compounder :get-principal)))
(defun three-years-with-positive-interest-rate ()
(setf compounder (interest-compounder 100000 5))
(funcall compounder :move-forward-years 3)
(assert= 115763 (funcall compounder :get-principal)))
(defun four-years-with-positive-interest-rate ()
(setf compounder (interest-compounder 100000 5))
(funcall compounder :move-forward-years 4)
(assert= 121551 (funcall compounder :get-principal)))
(defun one-year-with-negative-interest-rate ()
(setf compounder (interest-compounder 100000 -5))
(funcall compounder :move-forward-years 1)
(assert= 95000 (funcall compounder :get-principal)))
(defun two-years-with-negative-interest-rate ()
(setf compounder (interest-compounder 100000 -5))
(funcall compounder :move-forward-years 2)
(assert= 90250 (funcall compounder :get-principal)))
(defun three-years-with-negative-interest-rate ()
(setf compounder (interest-compounder 100000 -5))
(funcall compounder :move-forward-years 3)
(assert= 85737 (funcall compounder :get-principal)))
(defun four-years-with-negative-interest-rate ()
(setf compounder (interest-compounder 100000 -5))
(funcall compounder :move-forward-years 4)
(assert= 81450 (funcall compounder :get-principal)))
(defun negative-number-of-years-does-nothing ()
(setf compounder (interest-compounder 100000 5))
(funcall compounder :move-forward-years -4)
(assert= 100000 (funcall compounder :get-principal))
(funcall compounder :move-forward-years 1)
(funcall compounder :move-forward-years -4)
(assert= 105000 (funcall compounder :get-principal)))
(defun zero-number-of-years-does-nothing ()
(setf compounder (interest-compounder 100000 5))
(funcall compounder :move-forward-years 0)
(assert= 100000 (funcall compounder :get-principal))
(funcall compounder :move-forward-years 1)
(funcall compounder :move-forward-years 0)
(assert= 105000 (funcall compounder :get-principal))))))