!classDefinition: #PortfolioTest category: #'PortfolioTreePrinter-Ejercicio'! TestCase subclass: #PortfolioTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 18:44'! test01ReceptiveAccountHaveZeroAsBalanceWhenCreated | account | account := ReceptiveAccount new. self assert: 0 = account balance . ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 18:45'! test02DepositIncreasesBalanceOnTransactionValue | account | account := ReceptiveAccount new. Deposit register: 100 on: account. self assert: 100 = account balance . ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/14/2011 05:34'! test03WithdrawDecreasesBalanceOnTransactionValue | account | account := ReceptiveAccount new. Deposit register: 100 on: account. Withdraw register: 50 on: account. self assert: 50 = account balance . ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HAW 9/28/2017 15:22:46'! test03_01WithdrawValueMustBePositive | account withdrawValue | account := ReceptiveAccount new. withdrawValue := 50. self assert: (Withdraw register: withdrawValue on: account) value equals: withdrawValue ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 18:48'! test04PortfolioBalanceIsSumOfManagedAccountsBalance | account1 account2 complexPortfolio | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. Deposit register: 100 on: account1. Deposit register: 200 on: account2. self assert:300 = complexPortfolio balance . ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 18:53'! test05PortfolioCanManagePortfolios | account1 account2 account3 complexPortfolio composedPortfolio | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. Deposit register: 100 on:account1. Deposit register: 200 on: account2. Deposit register: 300 on: account3. self assert: 600 = composedPortfolio balance .! ! !PortfolioTest methodsFor: 'tests' stamp: 'HAW 9/25/2017 20:14:36'! test06ReceptiveAccountKnowsRegisteredTransactions | account deposit withdraw | account := ReceptiveAccount new. deposit := Deposit register: 100 on: account. withdraw := Withdraw register: 50 on: account. self assert: (account registers: deposit). self assert: (account registers: withdraw). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HAW 9/25/2017 20:14:30'! test07ReceptiveAccountDoNotKnowNotRegisteredTransactions | account deposit withdraw | account := ReceptiveAccount new. deposit := Deposit for: 100. withdraw := Withdraw for: 50. self deny: (account registers: deposit). self deny: (account registers:withdraw). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/26/2011 16:51'! test08PortfolioKnowsTransactionsRegisteredByItsManagedAccounts | account1 account2 account3 complexPortfolio composedPortfolio deposit1 deposit2 deposit3 | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. deposit1 := Deposit register: 100 on: account1. deposit2 := Deposit register: 200 on: account2. deposit3 := Deposit register: 300 on: account3. self assert: (composedPortfolio registers: deposit1). self assert: (composedPortfolio registers: deposit2). self assert: (composedPortfolio registers: deposit3).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/12/2011 13:25'! test08PortofolioKnowsTransactionsRegisteredByItsManagedAccounts | account1 account2 account3 complexPortfolio composedPortfolio deposit1 deposit2 deposit3 | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. deposit1 := Deposit register: 100 on: account1. deposit2 := Deposit register: 200 on: account2. deposit3 := Deposit register: 300 on: account3. self assert: (composedPortfolio registers: deposit1). self assert: (composedPortfolio registers: deposit2). self assert: (composedPortfolio registers: deposit3).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 19:00'! test10ReceptiveAccountManageItSelf | account1 | account1 := ReceptiveAccount new. self assert: (account1 manages:account1). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 19:01'! test11ReceptiveAccountDoNotManageOtherAccount | account1 account2 | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. self deny: (account1 manages: account2). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 19:02'! test12PortfolioManagesComposedAccounts | account1 account2 account3 complexPortfolio | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. self assert: (complexPortfolio manages: account1). self assert: (complexPortfolio manages: account2). self deny: (complexPortfolio manages: account3). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 19:03'! test13PortfolioManagesComposedAccountsAndPortfolios | account1 account2 account3 complexPortfolio composedPortfolio | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. self assert: (composedPortfolio manages: account1). self assert: (composedPortfolio manages: account2). self assert: (composedPortfolio manages: account3). self assert: (composedPortfolio manages: complexPortfolio). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/26/2011 16:28'! test14AccountKnowsItsTransactions | account1 deposit1 | account1 := ReceptiveAccount new. deposit1 := Deposit register: 100 on:account1. self assert: 1=account1 transactions size . self assert: (account1 transactions includes: deposit1). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/18/2011 17:15'! test15PortfolioTransactionsIsTheUnionOftsAccountsTransactions | account1 account2 account3 complexPortfolio account composedPortfolio deposit1 deposit2 deposit3 | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. deposit1 := Deposit register: 100 on: account1. deposit2 := Deposit register: 200 on: account2. deposit3 := Deposit register: 300 on: account3. self assert: 3 = composedPortfolio transactions size . self assert: (composedPortfolio transactions includes: deposit1). self assert: (composedPortfolio transactions includes: deposit2). self assert: (composedPortfolio transactions includes: deposit3). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/12/2011 13:23'! test16PortfolioKnowsItsAccountsTransactions | account1 account2 account3 complexPortfolio composedPortfolio deposit1 | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. deposit1 := Deposit register: 100 on: account1. self assert: 1= (composedPortfolio transactionsOf:account1) size . self assert: ((composedPortfolio transactionsOf: account1) includes:deposit1).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/12/2011 13:23'! test17PortfolioKnowsItsPortfoliosTransactions | account1 account2 account3 complexPortfolio composedPortfolio deposit1 deposit2 | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. deposit1 := Deposit register: 100 on: account1. deposit2 := Deposit register: 100 on: account2. Deposit register: 100 on: account3. self assert: 2 = (composedPortfolio transactionsOf:complexPortfolio) size . self assert: ((composedPortfolio transactionsOf:complexPortfolio) includes:deposit1). self assert: ((composedPortfolio transactionsOf:complexPortfolio) includes:deposit2). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/12/2011 13:24'! test18PortfolioCanNotAnswerTransactionsOfNotManagedAccounts | account1 account2 account3 complexPortfolio | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. self should: [ complexPortfolio transactionsOf:account3 ] raise: Error withExceptionDo: [ :accountNotManaged | self assert: Portfolio accountNotManagedMessageDescription = accountNotManaged messageText ] ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 19:28'! test19CanNotCreatePortfoliosWithRepeatedAccount | account1 | account1 := ReceptiveAccount new. self should: [ Portfolio with: account1 with: account1 ] raise: Error withExceptionDo: [ :invalidPortfolio | self assert: Portfolio accountAlreadyManagedErrorMessage = invalidPortfolio messageText ]! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/13/2011 19:15'! test20CanNotCreatePortfoliosWithAccountsManagedByOtherManagedPortfolio | account1 account2 complexPortfolio | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. self should: [ Portfolio with: complexPortfolio with: account1 ] raise: Error withExceptionDo: [ :invalidPortfolio | self assert: Portfolio accountAlreadyManagedErrorMessage = invalidPortfolio messageText ]! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/14/2011 05:27'! test21TransferShouldWithdrawFromFromAccountAndDepositIntoToAccount | fromAccount toAccount | fromAccount := ReceptiveAccount new. toAccount := ReceptiveAccount new. Transfer register: 100 from: fromAccount to: toAccount. self assert: -100 = fromAccount balance. self assert: 100 = toAccount balance.! ! !PortfolioTest methodsFor: 'tests' stamp: 'HAW 9/28/2017 15:30:52'! test21_01TransferIsReachedFromTransacctions | fromAccount toAccount transfer | fromAccount := ReceptiveAccount new. toAccount := ReceptiveAccount new. transfer := Transfer register: 100 from: fromAccount to: toAccount. self assert: 100 = transfer value. self assert: fromAccount transactions first transfer equals: transfer. self assert: toAccount transactions first transfer equals: transfer. ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HAW 9/28/2017 15:27:01'! test22AccountSummaryShouldProvideHumanReadableTransactionsDetail | fromAccount toAccount fromAccountLines toAccountLines| fromAccount := ReceptiveAccount new. toAccount := ReceptiveAccount new. Deposit register: 100 on: fromAccount. Withdraw register: 50 on: fromAccount. Transfer register: 100 from: fromAccount to: toAccount. fromAccountLines := self accountSummaryLinesOf: fromAccount. toAccountLines := self accountSummaryLinesOf: toAccount. self assert: 3 = fromAccountLines size. self assert: 'Deposito por 100' = (fromAccountLines at: 1). self assert: 'Extraccion por 50' = (fromAccountLines at: 2). self assert: 'Transferencia por -100' = (fromAccountLines at: 3). self assert: 1 = toAccountLines size. self assert: 'Transferencia por 100' = (toAccountLines at: 1). ! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/14/2011 06:58'! test23ShouldBeAbleToBeQueryTransferNet | fromAccount toAccount | fromAccount := ReceptiveAccount new. toAccount := ReceptiveAccount new. Deposit register: 100 on: fromAccount. Withdraw register: 50 on: fromAccount. Transfer register: 100 from: fromAccount to: toAccount. Transfer register: 250 from: toAccount to: fromAccount. self assert: 150 = (self accountTransferNetOf: fromAccount). self assert: -150 = (self accountTransferNetOf: toAccount).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/14/2011 06:58'! test24CertificateOfDepositShouldWithdrawInvestmentValue | account toAccount | account := ReceptiveAccount new. toAccount := ReceptiveAccount new. Deposit register: 1000 on: account. Withdraw register: 50 on: account. Transfer register: 100 from: account to: toAccount. CertificateOfDeposit register: 100 during: 30 at: 1/10 on: account. self assert: 100 =(self investmentNetOf:account). self assert: 750 = account balance.! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/14/2011 06:58'! test25ShouldBeAbleToQueryInvestmentEarnings | account investmentEarnings | account := ReceptiveAccount new. CertificateOfDeposit register: 100 during: 30 at: 1/10 on: account. CertificateOfDeposit register: 100 during: 60 at: 15/100 on: account. investmentEarnings := (100*((1/10)/360)*30) + (100*((15/100)/360)*60). self assert: investmentEarnings = (self investmentEarningsOf: account).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HAW 8/13/2017 18:37:21'! test26AccountSummaryShouldWorkWithCertificateOfDeposit | fromAccount toAccount lines | fromAccount := ReceptiveAccount new. toAccount := ReceptiveAccount new. Deposit register: 100 on: fromAccount. Withdraw register: 50 on: fromAccount. Transfer register: 100 from: fromAccount to: toAccount. CertificateOfDeposit register: 1000 during: 30 at: 1/10 on: fromAccount. lines := self accountSummaryLinesOf: fromAccount. self assert: 4 = lines size. self assert: 'Deposito por 100' = (lines at: 1). self assert: 'Extraccion por 50' = (lines at: 2). self assert: 'Transferencia por -100' = (lines at: 3). self assert: 'Plazo fijo por 1000 durante 30 dias a una tna de 10%' = (lines at: 4).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 7/14/2011 06:58'! test27ShouldBeAbleToBeQueryTransferNetWithCertificateOfDeposit | fromAccount toAccount | fromAccount := ReceptiveAccount new. toAccount := ReceptiveAccount new. Deposit register: 100 on: fromAccount. Withdraw register: 50 on: fromAccount. Transfer register: 100 from: fromAccount to: toAccount. Transfer register: 250 from: toAccount to: fromAccount. CertificateOfDeposit register: 1000 during: 30 at: 1/10 on: fromAccount. self assert: 150 = (self accountTransferNetOf: fromAccount). self assert: -150 = (self accountTransferNetOf: toAccount).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/26/2011 16:29'! test28PortfolioTreePrinterPrintsTheCompositeInDepthFirstOrder | account1 account2 account3 complexPortfolio composedPortfolio accountNames lines | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. accountNames := Dictionary new. accountNames at: composedPortfolio put: 'composedPortfolio'. accountNames at: complexPortfolio put: 'complexPortfolio'. accountNames at: account1 put: 'account1'. accountNames at: account2 put: 'account2'. accountNames at: account3 put: 'account3'. lines := self portofolioTreeOf: composedPortfolio namingAccountWith: accountNames. self assert: 5 = lines size. self assert: 'composedPortfolio' = (lines at: 1). self assert: ' complexPortfolio' = (lines at: 2). self assert: ' account1' = (lines at: 3). self assert: ' account2' = (lines at: 4). self assert: ' account3' = (lines at: 5).! ! !PortfolioTest methodsFor: 'tests' stamp: 'HernanWilkinson 9/26/2011 16:30'! test29ReversePortfolioTreePrinterPrintsTheCompositeStartingFromTheLeaves | account1 account2 account3 complexPortfolio composedPortfolio accountNames lines | account1 := ReceptiveAccount new. account2 := ReceptiveAccount new. account3 := ReceptiveAccount new. complexPortfolio := Portfolio with: account1 with: account2. composedPortfolio := Portfolio with: complexPortfolio with: account3. accountNames := Dictionary new. accountNames at: composedPortfolio put: 'composedPortfolio'. accountNames at: complexPortfolio put: 'complexPortfolio'. accountNames at: account1 put: 'account1'. accountNames at: account2 put: 'account2'. accountNames at: account3 put: 'account3'. lines := self reversePortofolioTreeOf: composedPortfolio namingAccountWith: accountNames. self assert: 5 = lines size. self assert: ' account3' = (lines at: 1). self assert: ' account2' = (lines at: 2). self assert: ' account1' = (lines at: 3). self assert: ' complexPortfolio' = (lines at: 4). self assert: 'composedPortfolio' = (lines at: 5). ! ! !PortfolioTest methodsFor: 'test support' stamp: 'HAW 9/25/2017 21:44:47'! accountSummaryLinesOf: aReceptiveAccount ^aReceptiveAccount accountSummary! ! !PortfolioTest methodsFor: 'test support' stamp: 'HernanWilkinson 9/6/2016 19:43'! accountTransferNetOf: aReceptiveAccount self shouldBeImplemented ! ! !PortfolioTest methodsFor: 'test support' stamp: 'HernanWilkinson 9/6/2016 19:43'! investmentEarningsOf: aReceptiveAccount self shouldBeImplemented ! ! !PortfolioTest methodsFor: 'test support' stamp: 'HernanWilkinson 9/6/2016 19:43'! investmentNetOf: aReceptiveAccount self shouldBeImplemented ! ! !PortfolioTest methodsFor: 'test support' stamp: 'HernanWilkinson 9/6/2016 19:43'! portofolioTreeOf: aPortfolio namingAccountWith: aDictionary self shouldBeImplemented ! ! !PortfolioTest methodsFor: 'test support' stamp: 'HernanWilkinson 9/6/2016 19:43'! reversePortofolioTreeOf: aPortfolio namingAccountWith: aDictionary self shouldBeImplemented ! ! !classDefinition: #AccountTransaction category: #'PortfolioTreePrinter-Ejercicio'! Object subclass: #AccountTransaction instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !AccountTransaction methodsFor: 'evaluating' stamp: 'HernanWilkinson 7/14/2011 06:48'! value self subclassResponsibility ! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'AccountTransaction class' category: #'PortfolioTreePrinter-Ejercicio'! AccountTransaction class instanceVariableNames: ''! !AccountTransaction class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 18:38'! register: aValue on: account | withdraw | withdraw := self for: aValue. account register: withdraw. ^ withdraw! ! !classDefinition: #CertificateOfDeposit category: #'PortfolioTreePrinter-Ejercicio'! AccountTransaction subclass: #CertificateOfDeposit instanceVariableNames: 'value tna numberOfDays account' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !classDefinition: #Deposit category: #'PortfolioTreePrinter-Ejercicio'! AccountTransaction subclass: #Deposit instanceVariableNames: 'value' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-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! ! !Deposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 19:56:56'! moneyForBalance ^self value! ! !Deposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 20:13:28'! transactionDescription ^'Deposito por ', self value asString! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'Deposit class' category: #'PortfolioTreePrinter-Ejercicio'! Deposit class instanceVariableNames: ''! !Deposit class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 18:38'! for: aValue ^ self new initializeFor: aValue ! ! !Deposit class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 19:41'! register: aValue on: account | withdraw | withdraw := self for: aValue. account register: withdraw. ^ withdraw! ! !classDefinition: #TransferDeposit category: #'PortfolioTreePrinter-Ejercicio'! AccountTransaction subclass: #TransferDeposit instanceVariableNames: 'value account transfer' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !TransferDeposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 20:36:22'! account ^account! ! !TransferDeposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:18:55'! initializeFor: aValue on: anAccount with: aTransfer value := aValue. account := anAccount. transfer := aTransfer.! ! !TransferDeposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:15:01'! moneyForBalance ^self value! ! !TransferDeposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:56:25'! transactionDescription ^'Transferencia por ', self value asString! ! !TransferDeposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:22:31'! transfer ^transfer.! ! !TransferDeposit methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:14:55'! value ^value! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'TransferDeposit class' category: #'PortfolioTreePrinter-Ejercicio'! TransferDeposit class instanceVariableNames: ''! !TransferDeposit class methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:23:31'! for: aValue on: anAccount with: aTransfer ^self new initializeFor: aValue on: anAccount with: aTransfer! ! !TransferDeposit class methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:24:07'! register: aValue on: account with: aTransfer | transfer | transfer := self for: aValue on: account with: aTransfer. account register: transfer. ^ transfer! ! !classDefinition: #TransferWithdraw category: #'PortfolioTreePrinter-Ejercicio'! AccountTransaction subclass: #TransferWithdraw instanceVariableNames: 'value account transfer' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !TransferWithdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 20:36:56'! account ^account! ! !TransferWithdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:21:42'! initializeFor: aValue on: anAccount with: aTransfer value := aValue. account := anAccount. transfer := aTransfer.! ! !TransferWithdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:15:06'! moneyForBalance ^self value * (-1)! ! !TransferWithdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:56:17'! transactionDescription ^'Transferencia por ', (self value * -1) asString! ! !TransferWithdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:22:35'! transfer ^transfer.! ! !TransferWithdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:14:33'! value ^value! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'TransferWithdraw class' category: #'PortfolioTreePrinter-Ejercicio'! TransferWithdraw class instanceVariableNames: ''! !TransferWithdraw class methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:23:15'! for: aValue on: anAccount with: aTransfer ^self new initializeFor: aValue on: anAccount with: aTransfer! ! !TransferWithdraw class methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:23:54'! register: aValue on: account with: aTransfer | transfer | transfer := self for: aValue on: account with: aTransfer. account register: transfer. ^ transfer! ! !classDefinition: #Withdraw category: #'PortfolioTreePrinter-Ejercicio'! AccountTransaction subclass: #Withdraw instanceVariableNames: 'value' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !Withdraw methodsFor: 'initialization' stamp: 'HernanWilkinson 7/13/2011 18:46'! initializeFor: aValue value := aValue ! ! !Withdraw methodsFor: 'value' stamp: 'HernanWilkinson 7/14/2011 05:54'! value ^ value ! ! !Withdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 19:56:43'! moneyForBalance ^self value * (-1)! ! !Withdraw methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:55:34'! transactionDescription ^'Extraccion por ', (self value * -1) asString! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'Withdraw class' category: #'PortfolioTreePrinter-Ejercicio'! Withdraw class instanceVariableNames: ''! !Withdraw class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 18:33'! for: aValue ^ self new initializeFor: aValue ! ! !Withdraw class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/14/2011 05:32'! register: aValue on: account | withdraw | withdraw := self for: aValue. account register: withdraw. ^ withdraw! ! !classDefinition: #SummarizingAccount category: #'PortfolioTreePrinter-Ejercicio'! Object subclass: #SummarizingAccount instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !SummarizingAccount methodsFor: 'testing' stamp: 'HernanWilkinson 7/13/2011 18:34'! manages: anAccount self subclassResponsibility ! ! !SummarizingAccount methodsFor: 'testing' stamp: 'HernanWilkinson 7/13/2011 18:34'! registers: aTransaction self subclassResponsibility ! ! !SummarizingAccount methodsFor: 'transactions' stamp: 'HernanWilkinson 7/13/2011 18:34'! balance self subclassResponsibility ! ! !SummarizingAccount methodsFor: 'transactions' stamp: 'HernanWilkinson 7/13/2011 18:35'! transactions self subclassResponsibility ! ! !classDefinition: #Portfolio category: #'PortfolioTreePrinter-Ejercicio'! SummarizingAccount subclass: #Portfolio instanceVariableNames: 'accounts' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !Portfolio methodsFor: 'testing' stamp: 'HernanWilkinson 7/13/2011 19:22'! manages: anAccount ^ self = anAccount or: [ accounts anySatisfy: [ :managedAccount | managedAccount manages: anAccount ] ]! ! !Portfolio methodsFor: 'testing' stamp: 'HernanWilkinson 7/13/2011 19:20'! registers: aTransaction ^ accounts anySatisfy: [ :anAccount | anAccount registers: aTransaction ] ! ! !Portfolio methodsFor: 'transactions' stamp: 'HAW 8/13/2017 17:47:44'! balance ^ accounts sum: [ :account | account balance ] ! ! !Portfolio methodsFor: 'transactions' stamp: 'HAW 9/25/2017 19:40:20'! transactions ^ accounts inject: OrderedCollection new into: [ :transactions :account | transactions addAll: account transactions. transactions ] ! ! !Portfolio methodsFor: 'transactions' stamp: 'HernanWilkinson 7/13/2011 19:27'! transactionsOf: anAccount ^ (self manages: anAccount) ifTrue: [ anAccount transactions ] ifFalse: [ self error: self class accountNotManagedMessageDescription] ! ! !Portfolio methodsFor: 'initialization' stamp: 'HernanWilkinson 7/13/2011 19:19'! initializeWithAll: aCollectionOfAccounts accounts := aCollectionOfAccounts ! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'Portfolio class' category: #'PortfolioTreePrinter-Ejercicio'! Portfolio class instanceVariableNames: ''! !Portfolio class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 18:48'! with: anAccount1 with: anAccount2 ^ self withAll: (Array with: anAccount1 with: anAccount2 )! ! !Portfolio class methodsFor: 'instance creation' stamp: 'HernanWilkinson 7/13/2011 19:40'! withAll: aCollectionOfAccounts aCollectionOfAccounts asSet size = aCollectionOfAccounts size ifFalse: [ self error: self accountAlreadyManagedErrorMessage ]. aCollectionOfAccounts do: [ :sourceAccount | aCollectionOfAccounts do: [ :targetAccount | (sourceAccount = targetAccount) not ifTrue: [ (sourceAccount manages: targetAccount) ifTrue: [ self error: self accountAlreadyManagedErrorMessage ]]]]. ^self new initializeWithAll: aCollectionOfAccounts ! ! !Portfolio class methodsFor: 'assertions' stamp: 'HernanWilkinson 9/18/2011 17:22'! check: sourceAccount doesNotManagaAnyOf: aCollectionOfAccounts ^ aCollectionOfAccounts do: [ :targetAccount | (sourceAccount = targetAccount) not ifTrue: [ (sourceAccount manages: targetAccount) ifTrue: [ self error: self accountAlreadyManagedErrorMessage ] ] ]! ! !Portfolio class methodsFor: 'assertions' stamp: 'HernanWilkinson 9/18/2011 17:21'! checkAccountsAreUnique: aCollectionOfAccounts aCollectionOfAccounts asSet size = aCollectionOfAccounts size ifFalse: [ self error: self accountAlreadyManagedErrorMessage ]! ! !Portfolio class methodsFor: 'assertions' stamp: 'HernanWilkinson 9/18/2011 17:21'! checkCreationPreconditions: aCollectionOfAccounts self checkAccountsAreUnique: aCollectionOfAccounts. self checkNoCircularReferencesIn: aCollectionOfAccounts! ! !Portfolio class methodsFor: 'assertions' stamp: 'HernanWilkinson 9/18/2011 17:22'! checkNoCircularReferencesIn: aCollectionOfAccounts aCollectionOfAccounts do: [ :sourceAccount | self check: sourceAccount doesNotManagaAnyOf: aCollectionOfAccounts ]! ! !Portfolio class methodsFor: 'error messages' stamp: 'HernanWilkinson 7/13/2011 19:28'! accountAlreadyManagedErrorMessage ^ 'Account already managed'! ! !Portfolio class methodsFor: 'error messages' stamp: 'HernanWilkinson 7/13/2011 19:27'! accountNotManagedMessageDescription ^ 'Account not managed'! ! !classDefinition: #ReceptiveAccount category: #'PortfolioTreePrinter-Ejercicio'! SummarizingAccount subclass: #ReceptiveAccount instanceVariableNames: 'transactions' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !ReceptiveAccount methodsFor: 'initialization' stamp: 'HernanWilkinson 7/13/2011 18:35'! initialize super initialize. transactions := OrderedCollection new.! ! !ReceptiveAccount methodsFor: 'transactions' stamp: 'ig 5/10/2018 19:57:08'! balance ^ transactions inject: 0 into: [ :balance :transaction | balance + (transaction moneyForBalance) ]! ! !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: 'testing' stamp: 'HernanWilkinson 7/13/2011 18:37'! manages: anAccount ^ self = anAccount ! ! !ReceptiveAccount methodsFor: 'testing' stamp: 'HernanWilkinson 7/13/2011 18:37'! registers: aTtransaction ^ transactions includes: aTtransaction ! ! !ReceptiveAccount methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:53:31'! accountSummary ^ transactions inject: OrderedCollection new into: [ :summary :transaction | summary , transaction transactionDescription. summary ]! ! !classDefinition: #Transfer category: #'PortfolioTreePrinter-Ejercicio'! Object subclass: #Transfer instanceVariableNames: 'value withdraw deposit' classVariableNames: '' poolDictionaries: '' category: 'PortfolioTreePrinter-Ejercicio'! !Transfer methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:36:14'! initializeWith: aValue withWithdraw: aWithdraw andDeposit: aDeposit value := aValue. withdraw := aWithdraw. deposit := aDeposit.! ! !Transfer methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:37:36'! value ^value! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !classDefinition: 'Transfer class' category: #'PortfolioTreePrinter-Ejercicio'! Transfer class instanceVariableNames: 'value withdraw deposit'! !Transfer class methodsFor: 'as yet unclassified' stamp: 'ig 5/10/2018 21:49:09'! register: aValue from: fromAccount to: toAccount | transfer withdraw deposit | transfer := self new. withdraw := TransferWithdraw register: aValue on: fromAccount with: transfer. deposit := TransferDeposit register: aValue on: toAccount with: transfer. transfer := transfer initializeWith: aValue withWithdraw: withdraw andDeposit: deposit. ^transfer! !