Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Dario Ocles
ing1-2018-1c
Commits
914318a8
Commit
914318a8
authored
6 years ago
by
ivan guralnik
Browse files
Options
Download
Email Patches
Plain Diff
cashier implementado
parent
4c628f75
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
355 additions
and
0 deletions
+355
-0
09-TusLibros.com/TusLibros-Entrega2.st
09-TusLibros.com/TusLibros-Entrega2.st
+355
-0
No files found.
09-TusLibros.com/TusLibros-Entrega2.st
0 → 100644
View file @
914318a8
!
classDefinition:
#CartTest
category:
#TusLibros
!
TestCase
subclass:
#CartTest
instanceVariableNames:
''
classVariableNames:
''
poolDictionaries:
''
category:
'TusLibros'
!
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:08'
!
test01NewCartsAreCreatedEmpty
self
assert:
self
createCart
isEmpty
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:45'
!
test02CanNotAddItemsThatDoNotBelongToStore
|
cart
|
cart
:=
self
createCart
.
self
should:
[
cart
add:
self
itemNotSellByTheStore
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
self
assert:
anError
messageText
=
cart
invalidItemErrorMessage
.
self
assert:
cart
isEmpty
]
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:43'
!
test03AfterAddingAnItemTheCartIsNotEmptyAnymore
|
cart
|
cart
:=
self
createCart
.
cart
add:
self
itemSellByTheStore
.
self
deny:
cart
isEmpty
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:43'
!
test04CanNotAddNonPositiveNumberOfItems
|
cart
|
cart
:=
self
createCart
.
self
should:
[
cart
add:
0
of:
self
itemSellByTheStore
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
self
assert:
anError
messageText
=
cart
invalidQuantityErrorMessage
.
self
assert:
cart
isEmpty
]
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:45'
!
test05CanNotAddMoreThanOneItemNotSellByTheStore
|
cart
|
cart
:=
self
createCart
.
self
should:
[
cart
add:
2
of:
self
itemNotSellByTheStore
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
self
assert:
anError
messageText
=
cart
invalidItemErrorMessage
.
self
assert:
cart
isEmpty
]
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:43'
!
test06CartRemembersAddedItems
|
cart
|
cart
:=
self
createCart
.
cart
add:
self
itemSellByTheStore
.
self
assert:
(
cart
includes:
self
itemSellByTheStore
)
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:43'
!
test07CartDoesNotHoldNotAddedItems
|
cart
|
cart
:=
self
createCart
.
self
deny:
(
cart
includes:
self
itemSellByTheStore
)
! !
!
CartTest
methodsFor:
'tests'
stamp:
'HernanWilkinson 6/17/2013 17:45'
!
test08CartRemembersTheNumberOfAddedItems
|
cart
|
cart
:=
self
createCart
.
cart
add:
2
of:
self
itemSellByTheStore
.
self
assert:
(
cart
occurrencesOf:
self
itemSellByTheStore
)
=
2
! !
!
CartTest
methodsFor:
'support'
stamp:
'HernanWilkinson 6/17/2013 17:48'
!
createCart
^
Cart
acceptingItemsOf:
self
defaultCatalog
! !
!
CartTest
methodsFor:
'support'
stamp:
'HernanWilkinson 6/17/2013 17:43'
!
defaultCatalog
^
Array
with:
self
itemSellByTheStore
! !
!
CartTest
methodsFor:
'support'
stamp:
'HernanWilkinson 6/17/2013 17:44'
!
itemNotSellByTheStore
^
'invalidBook'
! !
!
CartTest
methodsFor:
'support'
stamp:
'HernanWilkinson 6/17/2013 17:43'
!
itemSellByTheStore
^
'validBook'
! !
!
classDefinition:
#CashierTest
category:
#TusLibros
!
TestCase
subclass:
#CashierTest
instanceVariableNames:
''
classVariableNames:
''
poolDictionaries:
''
category:
'TusLibros'
!
!
CashierTest
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:15:36'
!
test01CashierCanNotCheckoutEmptyCart
|
catalog cart cashier creditCard
|
catalog
:=
Bag
new
.
cart
:=
Cart
acceptingItemsOf:
catalog
.
cashier
:=
Cashier
acceptingItemsOf:
catalog
onTheDateOf:
Date
today
.
creditCard
:=
CreditCard
withId:
'123123123'
andExpirationDate:
Date
tomorrow
.
self
should:
[
cashier
checkout:
cart
payingWith:
creditCard
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
self
assert:
anError
messageText
=
Cashier
canNotCheckoutEmptyCart
.
].
! !
!
CashierTest
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:15:57'
!
test02CashierCountsMoneyOnCheckout
|
catalog cart cashier product1 product2 creditCard totalPrice
|
product1
:=
Object
new
.
product2
:=
Object
new
.
catalog
:=
Dictionary
new
.
catalog
add:
product1
->
3
.
catalog
add:
product2
->
7.3
.
cart
:=
Cart
acceptingItemsOf:
catalog
.
cart
add:
product1
.
cart
add:
product2
.
cashier
:=
Cashier
acceptingItemsOf:
catalog
onTheDateOf:
Date
today
.
creditCard
:=
CreditCard
withId:
'123123123'
andExpirationDate:
Date
tomorrow
.
totalPrice
:=
cashier
checkout:
cart
payingWith:
creditCard
.
self
assert:
totalPrice
=
10.3
.
! !
!
CashierTest
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:19:08'
!
test03CashierFialsWhileValidatingExpiredCreditCard
|
catalog cart cashier product1 product2 creditCard
|
product1
:=
Object
new
.
product2
:=
Object
new
.
catalog
:=
Dictionary
new
.
catalog
add:
product1
->
3
.
catalog
add:
product2
->
7.3
.
cart
:=
Cart
acceptingItemsOf:
catalog
.
cart
add:
product1
.
cart
add:
product2
.
cashier
:=
Cashier
acceptingItemsOf:
catalog
onTheDateOf:
Date
today
.
creditCard
:=
CreditCard
withId:
'123123123'
andExpirationDate:
Date
yesterday
.
self
should:
[
cashier
checkout:
cart
payingWith:
creditCard
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
self
assert:
anError
messageText
=
Cashier
canNotCheckoutWithExpiredCreditCard
.
]
! !
!
classDefinition:
#Cart
category:
#TusLibros
!
Object
subclass:
#Cart
instanceVariableNames:
'catalog items'
classVariableNames:
''
poolDictionaries:
''
category:
'TusLibros'
!
!
Cart
methodsFor:
'error messages'
stamp:
'HernanWilkinson 6/17/2013 17:45'
!
invalidItemErrorMessage
^
'Item is not in catalog'
! !
!
Cart
methodsFor:
'error messages'
stamp:
'HernanWilkinson 6/17/2013 17:45'
!
invalidQuantityErrorMessage
^
'Invalid number of items'
! !
!
Cart
methodsFor:
'assertions'
stamp:
'ig 6/7/2018 19:31:34'
!
assertIsValidItem:
anItem
(
catalog
keys
includes:
anItem
)
ifFalse:
[
self
error:
self
invalidItemErrorMessage
]
! !
!
Cart
methodsFor:
'assertions'
stamp:
'HernanWilkinson 6/17/2013 17:51'
!
assertIsValidQuantity:
aQuantity
aQuantity
strictlyPositive
ifFalse:
[
self
error:
self
invalidQuantityErrorMessage
]
! !
!
Cart
methodsFor:
'initialization'
stamp:
'HernanWilkinson 6/17/2013 17:48'
!
initializeAcceptingItemsOf:
aCatalog
catalog
:=
aCatalog
.
items
:=
OrderedCollection
new
.
! !
!
Cart
methodsFor:
'queries'
stamp:
'HernanWilkinson 6/17/2013 17:45'
!
occurrencesOf:
anItem
^
items
occurrencesOf:
anItem
! !
!
Cart
methodsFor:
'queries'
stamp:
'ig 6/7/2018 19:23:56'
!
products
^
items
copy
! !
!
Cart
methodsFor:
'testing'
stamp:
'HernanWilkinson 6/17/2013 17:44'
!
includes:
anItem
^
items
includes:
anItem
! !
!
Cart
methodsFor:
'testing'
stamp:
'HernanWilkinson 6/17/2013 17:44'
!
isEmpty
^
items
isEmpty
! !
!
Cart
methodsFor:
'adding'
stamp:
'HernanWilkinson 6/17/2013 17:44'
!
add:
anItem
^
self
add:
1
of:
anItem
! !
!
Cart
methodsFor:
'adding'
stamp:
'ig 6/7/2018 18:42:49'
!
add:
aQuantity
of:
anItem
self
assertIsValidQuantity:
aQuantity
.
self
assertIsValidItem:
anItem
.
aQuantity
timesRepeat:
[
items
add:
anItem
]
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "
!
!
classDefinition:
'Cart class'
category:
#TusLibros
!
Cart
class
instanceVariableNames:
''
!
!
Cart
class
methodsFor:
'instance creation'
stamp:
'HernanWilkinson 6/17/2013 17:48'
!
acceptingItemsOf:
aCatalog
^
self
new
initializeAcceptingItemsOf:
aCatalog
! !
!
classDefinition:
#Cashier
category:
#TusLibros
!
Object
subclass:
#Cashier
instanceVariableNames:
'catalog date'
classVariableNames:
''
poolDictionaries:
''
category:
'TusLibros'
!
!
Cashier
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:25:19'
!
cashinWithRest
! !
!
Cashier
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:25:12'
!
checkout:
aCart
payingWith:
aCreditCard
|
totalPrice
|
(
aCart
isEmpty
)
ifTrue:
[
self
error:
self
class
canNotCheckoutEmptyCart
].
(
aCreditCard
isExpiredFrom:
date
)
ifTrue:
[
^
self
error:
self
class
canNotCheckoutWithExpiredCreditCard
].
totalPrice
:=
0
.
(
aCart
products
)
do:
[
:
product
|
totalPrice
:=
totalPrice
+
catalog
at:
product
].
self
cashinWithRest
.
^
totalPrice
! !
!
Cashier
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:02:21'
!
initializeAcceptingItemsOf:
aCatalog
withDate:
aDate
catalog
:=
aCatalog
.
date
:=
aDate
.
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "
!
!
classDefinition:
'Cashier class'
category:
#TusLibros
!
Cashier
class
instanceVariableNames:
''
!
!
Cashier
class
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:02:02'
!
acceptingItemsOf:
aCatalog
onTheDateOf:
aDate
^
self
new
initializeAcceptingItemsOf:
aCatalog
withDate:
aDate
.
! !
!
Cashier
class
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 19:15:21'
!
canNotCheckoutEmptyCart
^
'No se puede hacer checkout de un carrito vacio'
! !
!
Cashier
class
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:08:15'
!
canNotCheckoutWithExpiredCreditCard
^
'La tarjeta de credito esta expirada'
! !
!
classDefinition:
#CreditCard
category:
#TusLibros
!
Object
subclass:
#CreditCard
instanceVariableNames:
'id expirationDate'
classVariableNames:
''
poolDictionaries:
''
category:
'TusLibros'
!
!
CreditCard
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 19:56:08'
!
initializeWithId:
anId
andExpirationDate:
anExpirationDate
id
:=
anId
.
expirationDate
:=
anExpirationDate
.
! !
!
CreditCard
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 20:09:12'
!
isExpiredFrom:
aDate
^
expirationDate
<
aDate
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "
!
!
classDefinition:
'CreditCard class'
category:
#TusLibros
!
CreditCard
class
instanceVariableNames:
''
!
!
CreditCard
class
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 19:55:16'
!
initliazeWithId:
anId
andExpirationDate:
anExpirationDate
! !
!
CreditCard
class
methodsFor:
'as yet unclassified'
stamp:
'ig 6/7/2018 19:55:42'
!
withId:
anId
andExpirationDate:
anExpirationDate
^
self
new
initializeWithId:
anId
andExpirationDate:
anExpirationDate
! !
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment