2017-03-09 11:19:15 -05:00
|
|
|
(load "../unit/unit-tester.lisp")
|
2017-03-06 16:52:06 -05:00
|
|
|
(load "interest-compounder.lisp")
|
|
|
|
|
2017-03-09 11:19:15 -05:00
|
|
|
(setq assertions (unit-tester-assertions))
|
|
|
|
|
|
|
|
(setq tests
|
2017-03-06 16:52:06 -05:00
|
|
|
(let ((compounder))
|
|
|
|
(list
|
|
|
|
|
|
|
|
(defun principal-initialized ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 1000 0))
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 1000 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun interest-rate-initialized ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 0 10))
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 10 (call compounder :get-interest-rate)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun many-years-with-no-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 1000 0))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 83)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 1000 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun no-years-with-positive-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 1000 10))
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 1000 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun one-year-with-positive-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 1)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 105000 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun two-years-with-positive-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 2)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 110250 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun three-years-with-positive-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 3)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 115763 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun four-years-with-positive-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 4)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 121551 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun one-year-with-negative-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 -5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 1)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 95000 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun two-years-with-negative-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 -5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 2)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 90250 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun three-years-with-negative-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 -5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 3)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 85737 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun four-years-with-negative-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 -5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 4)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 81450 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun negative-number-of-years-does-nothing ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years -4)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 100000 (call compounder :get-principal))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 1)
|
|
|
|
(call compounder :move-forward-years -4)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 105000 (call compounder :get-principal)))
|
2017-03-06 16:52:06 -05:00
|
|
|
|
|
|
|
(defun zero-number-of-years-does-nothing ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 0)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 100000 (call compounder :get-principal))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 1)
|
|
|
|
(call compounder :move-forward-years 0)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 105000 (call compounder :get-principal)))
|
2017-03-07 11:37:27 -05:00
|
|
|
|
|
|
|
(defun variable-interest-rate ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 2)
|
|
|
|
(call compounder :set-interest-rate 10)
|
|
|
|
(call compounder :move-forward-years 2)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 133403 (call compounder :get-principal)))
|
2017-03-07 11:37:27 -05:00
|
|
|
|
|
|
|
(defun years-are-updated ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 27)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 27 (call compounder :get-years-passed)))
|
2017-03-07 11:37:27 -05:00
|
|
|
|
|
|
|
(defun negative-number-of-years-does-not-update-years ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 27)
|
|
|
|
(call compounder :move-forward-years -2)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 27 (call compounder :get-years-passed)))
|
2017-03-07 11:37:27 -05:00
|
|
|
|
|
|
|
(defun zero-number-of-years-does-not-update-years ()
|
2017-03-07 13:15:40 -05:00
|
|
|
(setq compounder (interest-compounder 100000 5))
|
2017-03-07 11:37:27 -05:00
|
|
|
(call compounder :move-forward-years 27)
|
|
|
|
(call compounder :move-forward-years 0)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 27 (call compounder :get-years-passed)))
|
2017-03-08 11:14:44 -05:00
|
|
|
|
|
|
|
(defun make-contribution ()
|
|
|
|
(setq compounder (interest-compounder 100000 5))
|
|
|
|
(call compounder :make-contribution 2000)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 102000 (call compounder :get-principal)))
|
2017-03-08 11:14:44 -05:00
|
|
|
|
|
|
|
(defun make-several-contributions ()
|
|
|
|
(setq compounder (interest-compounder 100000 5))
|
|
|
|
(call compounder :make-contribution 2000)
|
|
|
|
(call compounder :make-contribution 2000)
|
|
|
|
(call compounder :make-contribution 1000)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 105000 (call compounder :get-principal)))
|
2017-03-08 11:14:44 -05:00
|
|
|
|
|
|
|
(defun make-several-contributions-and-earn-interest ()
|
|
|
|
(setq compounder (interest-compounder 100000 5))
|
|
|
|
(call compounder :make-contribution 2000)
|
|
|
|
(call compounder :move-forward-years 2)
|
|
|
|
(call compounder :make-contribution 2000)
|
|
|
|
(call compounder :move-forward-years 2)
|
2017-03-09 11:19:15 -05:00
|
|
|
(call assertions :assert= 126187 (call compounder :get-principal))))))
|
|
|
|
|
|
|
|
|
|
|
|
(setq tester (unit-tester tests))
|
|
|
|
(call tester :run)
|