-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.rkt
More file actions
282 lines (264 loc) · 9.35 KB
/
tests.rkt
File metadata and controls
282 lines (264 loc) · 9.35 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#lang racket
;; Require your program module with renaming to avoid conflicts
(require rackunit
rackunit/text-ui
(rename-in "preprocessing.rkt" [check payment-check])
"processing.rkt"
"output.rkt")
;; Reset the transaction-counter for tests
(define (reset-transaction-counter) 10001)
(module+ test
(define account-formatting
;; Define all your unit tests here
(test-suite
"Data Formatting"
#:before (λ () (reset-transaction-counter))
(test-case
"Account Formatting"
;; Tests Account data formatting & assignment
(check-equal? (reading-accounts-data
'("123456789012" "John Doe" "500.00"))
(user 123456789012 "John Doe" 500.00)
"Account Data is not being processed appropriately"))))
(define transaction-formatting
(test-suite
"Transaction Formatting"
;; Tests the Purchase Formatting & Assignment
(test-case
"Purchase Transaction Formatting"
(begin
(reset-transaction-counter)
(check-equal?
(reading-transaction-data
'("Purchase"
"123456789012"
"20200101"
"Store"
"100.00") 1)
(purchase 10001
'purchase
123456789012
20200101
"Store"
100.00)
"Purchase transaction data does not process correctly")))
(test-case
"Cash Payment Formatting"
;; Tests the Payment Payment Formatting & Assignment
(begin
(reset-transaction-counter)
(check-equal?
(reading-transaction-data
'("Payment"
"123456789012"
"1234567"
"Cash"
"100.00") 1)
(cash 10001
'payment
123456789012
1234567
'cash
100.00)
"Check Payment transaction data does not process correctly")))
;; Test Check payment transaction formatting & Assignment
(test-case
"Check Payment Formatting"
(begin
(reset-transaction-counter)
(check-equal?
(reading-transaction-data
'("Payment"
"123456789012"
"20200101"
"Check"
"11101"
"100.00") 1)
(payment-check 10001
'payment
123456789012
20200101
'check
11101
100.00)
"Check Payment transaction data does not process correctly")))
;; Test Credit payment transaction Formatting & Assignment
(test-case
"Credit Payment Formatting"
(begin
(reset-transaction-counter)
(check-equal?
(reading-transaction-data
'("Payment"
"123456789012"
"20200101"
"Credit"
"550055005500"
"100.00") 1)
(card 10001
'payment
123456789012
20200101
'credit
550055005500
100.00)
"Credit Payment transaction data does not process correctly")))
(test-case
"Debit Payment Formatting"
(begin
(reset-transaction-counter)
(check-equal?
(reading-transaction-data
'("Payment"
"123456789012"
"20200101"
"Debit"
"550055005500"
"100.00") 1)
(card 10001
'payment
123456789012
20200101
'debit
550055005500
100.00)
"Debit Payment transaction data does not process correctly")))))
(define data-calculation
(test-suite
"Data Calculation"
(test-case
"Total Payment Calculator"
;; Test the calculation of payments with accuracy up to 1 cent
(begin
(reset-transaction-counter)
(let* ([test-transactions (list
(cash 10001
'payment
123456789012
20200101
'cash
150.00)
(payment-check 10002
'payment
123456789012
20200102
'check
11101
200.00)
(card 10003
'payment
123456789012
20200103
'credit
5500550055005500
250.00))]
;; Filter transactions by account number 123456789012
[filtered-transactions (filter-by-account
test-transactions 123456789012)])
(check-= (sum-payments filtered-transactions) 600.00 0.01
"Payments are not calculated correctly"))))
(test-case
"Total Purchase Calculator"
;; Test the calculation of purchases with accuracy up to 1 cent
(begin
(reset-transaction-counter)
(let ([transactions (list
(purchase 10001
'purchase
123456789012
20200101
"Store"
100.00)
(purchase 10002
'purchase
123456789012
20200102
"Online"
200.00))])
(check-= (sum-purchases transactions) 300.00 0.01
"Purchases are not calculated correctly"))))
(test-case
"Balance Calculation"
(begin
(reset-transaction-counter)
(let* ([total-purchases 900.00]
[total-payments 500.00]
[starting-balance 50.00])
(check-= (calculate-ending-balance starting-balance
total-payments
total-purchases)
450.00 0.01
"Balance Calculation is not functioning as expected")
)))))
(define output-verification
(test-suite
"Output Formatting"
(test-case
"Output Testing"
(begin
(let*
([sample-accounts
(list
(user 123456789012 "John Doe" 1000.00)
(user 234567890123 "Jane Smith" 1500.00))]
[sample-transactions
(list
(purchase 10001
'purchase
123456789012
20200101
"Long Merchant Name That Exceeds Forty Characters"
200.00)
(cash 10002
'payment
123456789012
20200102
'cash
300.00)
(payment-check 10003
'payment
234567890123
20200103
'check
5001
400.00)
(card 10004
'payment
234567890123
20200104
'credit
550055005500
500.00))]
[out-port (open-output-string)]
;; Call the function with the string port
[actual-output
(with-output-to-string
(lambda ()
(create-output-file sample-accounts
sample-transactions)))]
[expected-output
"STATEMENT OF ACCOUNT
123456789012 John Doe Starting Balance: 1000.00
20200101 Purchase Long Merchant Name That Exceeds Forty 200.00
20200102 Payment Cash 300.00
Total Purchases: 200.00
Total Payments: 300.00
Ending Balance: 1100.00
*********************************************************
STATEMENT OF ACCOUNT
234567890123 Jane Smith Starting Balance: 1500.00
20200103 Payment Check 400.00
20200104 Payment Credit 500.00
Total Purchases: 0.00
Total Payments: 900.00
Ending Balance: 2400.00
*********************************************************
"])
;; Compare actual output with expected output
(check-equal? actual-output expected-output
"Output does not match expected result"))))))
;; Run the tests
(run-tests account-formatting)
(run-tests transaction-formatting)
(run-tests data-calculation)
(run-tests output-verification))