-
Notifications
You must be signed in to change notification settings - Fork 0
/
[Ori]Portfolio-Ejercicio.st
216 lines (140 loc) · 5.45 KB
/
[Ori]Portfolio-Ejercicio.st
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
!classDefinition: #ReceptiveAccountTest category: 'Portfolio-Ejercicio'!
TestCase subclass: #ReceptiveAccountTest
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Portfolio-Ejercicio'!
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'NR 11/2/2020 17:13:44'!
test01ReceptiveAccountHaveZeroAsBalanceWhenCreated
| account |
account := ReceptiveAccount new.
self assert: 0 equals: account balance.
! !
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'NR 11/2/2020 17:13:48'!
test02DepositIncreasesBalanceOnTransactionValue
| account |
account := ReceptiveAccount new.
Deposit register: 100 on: account.
self assert: 100 equals: account balance.
! !
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'NR 11/2/2020 17:13:52'!
test03WithdrawDecreasesBalanceOnTransactionValue
| account |
account := ReceptiveAccount new.
Deposit register: 100 on: account.
Withdraw register: 50 on: account.
self assert: 50 equals: account balance.
! !
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'HAW 5/23/2019 15:20:32'!
test04WithdrawValueMustBePositive
| account withdrawValue |
account := ReceptiveAccount new.
withdrawValue := 50.
self assert: withdrawValue equals: (Withdraw register: withdrawValue on: account) value
! !
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'HAW 5/23/2019 15:20:46'!
test05ReceptiveAccountKnowsRegisteredTransactions
| account deposit withdraw |
account := ReceptiveAccount new.
deposit := Deposit register: 100 on: account.
withdraw := Withdraw register: 50 on: account.
self assert: (account hasRegistered: deposit).
self assert: (account hasRegistered: withdraw).
! !
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'NR 5/17/2021 17:29:53'!
test06ReceptiveAccountDoNotKnowNotRegisteredTransactions
| deposit withdraw account |
account := ReceptiveAccount new.
deposit := Deposit for: 200.
withdraw := Withdraw for: 50.
self deny: (account hasRegistered: deposit).
self deny: (account hasRegistered:withdraw).
! !
!ReceptiveAccountTest methodsFor: 'tests' stamp: 'NR 11/2/2020 17:14:01'!
test07AccountKnowsItsTransactions
| account1 deposit1 |
account1 := ReceptiveAccount new.
deposit1 := Deposit register: 50 on: account1.
self assert: 1 equals: account1 transactions size.
self assert: (account1 transactions includes: deposit1).
! !
!classDefinition: #AccountTransaction category: 'Portfolio-Ejercicio'!
Object subclass: #AccountTransaction
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Portfolio-Ejercicio'!
!AccountTransaction methodsFor: 'value' stamp: 'HernanWilkinson 9/12/2011 12:25'!
value
self subclassResponsibility ! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'AccountTransaction class' category: 'Portfolio-Ejercicio'!
AccountTransaction class
instanceVariableNames: ''!
!AccountTransaction class methodsFor: 'instance creation' stamp: 'NR 10/17/2019 03:22:00'!
register: aValue on: account
| transaction |
transaction := self for: aValue.
account register: transaction.
^ transaction! !
!classDefinition: #Deposit category: 'Portfolio-Ejercicio'!
AccountTransaction subclass: #Deposit
instanceVariableNames: 'value'
classVariableNames: ''
poolDictionaries: ''
category: 'Portfolio-Ejercicio'!
!Deposit methodsFor: 'initialization' stamp: 'HernanWilkinson 7/13/2011 18:45'!
initializeFor: aValue
value := aValue ! !
!Deposit methodsFor: 'value' stamp: 'HernanWilkinson 7/13/2011 18:38'!
value
^ value! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'Deposit class' category: 'Portfolio-Ejercicio'!
Deposit class
instanceVariableNames: ''!
!Deposit class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 18:38'!
for: aValue
^ self new initializeFor: aValue ! !
!classDefinition: #Withdraw category: 'Portfolio-Ejercicio'!
AccountTransaction subclass: #Withdraw
instanceVariableNames: 'value'
classVariableNames: ''
poolDictionaries: ''
category: 'Portfolio-Ejercicio'!
!Withdraw methodsFor: 'initialization' stamp: 'HernanWilkinson 7/13/2011 18:46'!
initializeFor: aValue
value := aValue ! !
!Withdraw methodsFor: 'value' stamp: 'HernanWilkinson 7/13/2011 18:33'!
value
^ value! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'Withdraw class' category: 'Portfolio-Ejercicio'!
Withdraw class
instanceVariableNames: ''!
!Withdraw class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 18:33'!
for: aValue
^ self new initializeFor: aValue ! !
!classDefinition: #ReceptiveAccount category: 'Portfolio-Ejercicio'!
Object subclass: #ReceptiveAccount
instanceVariableNames: 'transactions'
classVariableNames: ''
poolDictionaries: ''
category: 'Portfolio-Ejercicio'!
!ReceptiveAccount methodsFor: 'initialization' stamp: 'NR 10/17/2019 15:06:56'!
initialize
transactions := OrderedCollection new.! !
!ReceptiveAccount methodsFor: 'transactions' stamp: 'HernanWilkinson 7/13/2011 18:37'!
register: aTransaction
transactions add: aTransaction
! !
!ReceptiveAccount methodsFor: 'transactions' stamp: 'HernanWilkinson 7/13/2011 18:37'!
transactions
^ transactions copy! !
!ReceptiveAccount methodsFor: 'balance' stamp: 'HAW 5/23/2019 15:19:32'!
balance
^transactions sum: [ :aTransaction | aTransaction value ] ifEmpty: [ 0 ]! !
!ReceptiveAccount methodsFor: 'testing' stamp: 'NR 10/17/2019 03:28:43'!
hasRegistered: aTransaction
^ transactions includes: aTransaction
! !