1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Package: rsm.finance.test -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name: finance-test.lisp
;;;; Purpose: Regression testing for financial loan utilities.
;;;; Author: R. Scott McIntire
;;;; Date Started: Aug 2003
;;;;
;;;; $Id: finance-test.lisp,v 1.2 2003/09/10 22:19:24 rscottmcintire Exp $
;;;; *************************************************************************
(in-package #:cl-user)
(defpackage rsm.finance.test
(:use #:cl rsm.finance #:ptester)
(:documentation
"Provides a test harness for financial loan utilities.")
)
(in-package rsm.finance.test)
;;;; INFRASTRUCTURE FUNCTIONS AND VARIABLES.
(defvar *tolerance* 1.0d-5
"The tolerance used to decide floating point equality.")
(defun float-equal (x y)
"Equal if relative of x and y is less than +tolerance+.
When +tolerance+ is 1.0d-4, then equality means that <x> and <y>
are equal with a relative error of a hundredth of a percent."
(if (and (= 0.0d0 x) (= 0.0d0 y))
t
(let ((max (max (abs x) (abs y))))
(< (/ (abs (- x y)) max) *tolerance*))))
;;;; RUN THE TESTS.
(defun run-finance-tests ()
(with-tests (:name "LOAN FINANCE TESTS")
;; Group 1
(test 1330.60d0
(calc-monthly-payment 200000.0 30 7.0)
:test #'float-equal
:fail-info "Test 1")
(test 200000.0d0
(calc-initial-debt 30 7.0 1330.60)
:test #'float-equal
:fail-info "Test 2")
(test 7.0d0
(calc-interest-rate 200000.0 1330.60 30)
:test #'float-equal
:fail-info "Test 3")
(test '(361 30 1 479022.11787691835d0 6.117876918363281d0)
(calc-num-payments 200000.0 7.0 1330.60)
:test #'float-equal
:multiple-values t
:fail-info "Test 4")
;; Group 2
(test 716.43d0
(calc-monthly-payment 100000.0 20 6.0)
:test #'float-equal
:fail-info "Test 5")
(test 100000.0d0
(calc-initial-debt 20 6.0 716.43)
:test #'float-equal
:fail-info "Test 6")
(test 6.0d0
(calc-interest-rate 100000.0 716.43 20)
:test #'float-equal
:fail-info "Test 7")
(test '(241 20 1 171943.69556928397d0 0.4924442839637882d0)
(calc-num-payments 100000.0 6.0 716.43)
:test #'float-equal
:multiple-values t
:fail-info "Test 8")
;; Group 3
(test 278.49d0
(calc-monthly-payment 15000.0 5 4.33d0)
:test #'float-equal
:fail-info "Test 9")
(test 15000.0d0
(calc-initial-debt 5 4.33 278.49)
:test #'float-equal
:fail-info "Test 10")
(let ((*tolerance* 1.0d-4))
(test 4.33d0
(calc-interest-rate 15000.0 278.49 5)
:test #'float-equal
:fail-info "Test 11")
(test '(60 5 0 16708.217007688505d0 277.30685143850604d0)
(calc-num-payments 15000.0 4.33 278.49)
:test #'float-equal
:multiple-values t
:fail-info "Test 12")
;; Group 4
(test 0.0054549d0
(calc-interest-rate 200000.0 556.00 30)
:test #'float-equal
:fail-info "Test 13")
(test 556.0d0
(calc-monthly-payment 200000.0 30 0.0054549)
:test #'float-equal
:fail-info "Test 14")
(test 200000.0d0
(calc-initial-debt 30 0.0054549 556.00)
:test #'float-equal
:fail-info "Test 15")
(test '(361 30 1 200164.14959972943d0 4.149599729439264d0)
(calc-num-payments 200000.0 0.0054549 556.00)
:test #'float-equal
:multiple-values t
:fail-info "Test 16")
)
;; Group 5
(test nil
(calc-interest-rate 200000.0 555.00 30)
:fail-info "Test 17")
;; Group 6
(test-error
(calc-interest-rate 200000.0 555.00 -30)
:fail-info "Test 18")
(test-error
(calc-interest-rate 200000.0 -555.00 30)
:fail-info "Test 19")
(test-error
(calc-interest-rate -200000.0 555.00 30)
:fail-info "Test 20")
(test-error
(calc-interest-rate -200000.0 555.00 -30)
:fail-info "Test 21")
(test-error
(calc-interest-rate -200000.0 -555.00 30)
:fail-info "Test 22")
(test-error
(calc-interest-rate -200000.0 -555.00 -30)
:fail-info "Test 23")
;; Group 7
(test-error
(calc-num-payments -15000.0 4.33 278.49)
:fail-info "Test 24")
(test-error
(calc-num-payments 15000.0 -4.33 278.49)
:fail-info "Test 25")
(test-error
(calc-num-payments 15000.0 4.33 -278.49)
:fail-info "Test 26")
(test-error
(calc-num-payments -15000.0 -4.33 278.49)
:fail-info "Test 27")
(test-error
(calc-num-payments -15000.0 -4.33 -278.49)
:fail-info "Test 28")
;; Group 8
(test-error
(calc-monthly-payment -15000.0 5 4.33d0)
:fail-info "Test 29")
(test-error
(calc-monthly-payment 15000.0 -5 4.33d0)
:fail-info "Test 30")
(test-error
(calc-monthly-payment 15000.0 5 -4.33d0)
:fail-info "Test 31")
(test-error
(calc-monthly-payment -15000.0 -5 4.33d0)
:fail-info "Test 32")
(test-error
(calc-monthly-payment -15000.0 5 -4.33d0)
:fail-info "Test 33")
(test-error
(calc-monthly-payment -15000.0 -5 -4.33d0)
:fail-info "Test 34")
;; Group 9
(test-error
(calc-initial-debt -30 7.0 1330.60)
:fail-info "Test 35")
(test-error
(calc-initial-debt 30 -7.0 1330.60)
:fail-info "Test 36")
(test-error
(calc-initial-debt 30 7.0 -1330.60)
:fail-info "Test 37")
(test-error
(calc-initial-debt -30 7.0 -1330.60)
:fail-info "Test 38")
(test-error
(calc-initial-debt -30 -7.0 1330.60)
:fail-info "Test 39")
(test-error
(calc-initial-debt 30 -7.0 -1330.60)
:fail-info "Test 40")
(test-error
(calc-initial-debt -30 -7.0 -1330.60)
:fail-info "Test 41")
)
t
)
|