-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.bak
More file actions
194 lines (183 loc) · 6.38 KB
/
tests.bak
File metadata and controls
194 lines (183 loc) · 6.38 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
#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")
;; Reset the transaction-counter for tests
(define (reset-transaction-counter)
(transaction-counter (make-parameter 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"))
(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"))
(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"))
(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"))
(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"))
(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"))))))
;; Run the tests
(run-tests account-formatting)
(run-tests transaction-formatting)
(run-tests data-calculation))