Commit 02361a36 authored by istng's avatar istng
Browse files

tuslibros con carrito andando

parent 9151f7f8
......@@ -5,79 +5,168 @@ TestCase subclass: #CartTest
poolDictionaries: ''
category: 'TusLibros'!
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:28:06'!
test01CreatedNewCartIsEmpty
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 17:01:40'!
test01NewCreatedCartIsEmpty
| cart |
| cart market catalog |
cart := Cart new.
catalog := Catalog new.
market := Market with: catalog.
cart := Cart with: market.
self assert: cart isEmpty.! !
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:45:32'!
test02AddingABookToACart
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 17:02:14'!
test02AddingOneProductToACart
| cart isbn quantity cosa |
| cart market catalog product |
cart := Cart new.
isbn := '123123'.
quantity := '2'.
product := Object new.
catalog := Catalog new.
catalog add: product.
market := Market with: catalog.
cart := Cart with: market.
cart add: quantity of: isbn.
cart add: product.
cosa := (Pair with: isbn with: quantity).
self deny: cart isEmpty.
self assert: ((cart books) at: 1) = cosa.! !
self assert: ((cart products) includesKey: product).! !
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:42:29'!
test03ListingCartListsAddedBooks
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 17:02:38'!
test03AddingMoreOfTheSameProductToACart
| cart isbn quantity |
| cart market catalog product |
cart := Cart new.
isbn := '123123'.
quantity := '2'.
product := Object new.
catalog := Catalog new.
catalog add: product.
market := Market with: catalog.
cart := Cart with: market.
cart add: product quantity: 4.
cart add: quantity of: isbn.
self deny: cart isEmpty.
self assert: ((cart products) includesKey: product).
self assert: (((cart products) at: product) = 4)! !
!CartTest methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 17:03:12'!
test04CheckingProductIsInCatalog
| cart market catalog product |
self assert: cart list = '0|123123|2'
product := Object new.
catalog := Catalog new.
market := Market with: catalog.
cart := Cart with: market.
! !
self
should: [cart add: product]
raise: Error - MessageNotUnderstood
withExceptionDo: [ :anError |
self assert: Cart canNotAddProductOustideTheCatalog equals: anError messageText.
].! !
!classDefinition: #Cart category: #TusLibros!
Object subclass: #Cart
instanceVariableNames: 'books'
instanceVariableNames: 'products market'
classVariableNames: ''
poolDictionaries: ''
category: 'TusLibros'!
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:35:47'!
add: aQuantity of: anIsbn
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:58:59'!
add: aProduct
books add: (Pair with: anIsbn with: aQuantity).! !
(market has: aProduct) ifFalse: [self error: (self class canNotAddProductOustideTheCatalog)].
products add: aProduct->1.! !
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:20:07'!
books
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:59:03'!
add: aProduct quantity: aQuantity
^books! !
(market has: aProduct) ifFalse: [self error: (self class canNotAddProductOustideTheCatalog)].
products add: aProduct->aQuantity.
! !
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:19:06'!
initialize
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 17:00:23'!
initializeWith: aMarket
books := OrderedCollection new.! !
products := Dictionary new.
market := aMarket.! !
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:19:13'!
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 15:50:01'!
isEmpty
^books isEmpty! !
^(products hasContentsInExplorer) not! !
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 15:53:59'!
products
^products copy! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'Cart class' category: #TusLibros!
Cart class
instanceVariableNames: ''!
!Cart class methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:07:26'!
canNotAddProductOustideTheCatalog
^'No se puede agregar un producto que no pertenece al catalogo'! !
!Cart class methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 17:00:35'!
with: aMarket
^self new initializeWith: aMarket! !
!classDefinition: #Catalog category: #TusLibros!
Object subclass: #Catalog
instanceVariableNames: 'products'
classVariableNames: ''
poolDictionaries: ''
category: 'TusLibros'!
!Catalog methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:36:23'!
add: aProduct
!Cart methodsFor: 'as yet unclassified' stamp: 'ig 6/4/2018 21:42:06'!
list
products add: aProduct.! !
!Catalog methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:46:05'!
has: aProduct
^products includes: aProduct! !
| list |
!Catalog methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:36:09'!
initialize
products := Set new.! !
!classDefinition: #Market category: #TusLibros!
Object subclass: #Market
instanceVariableNames: 'catalog'
classVariableNames: ''
poolDictionaries: ''
category: 'TusLibros'!
list := '0'.
books do: [:book | list , '|' , (book first asString) , '|' , (book second asString)].
!Market methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:59:18'!
has: aProduct
^list! !
^catalog has: aProduct! !
!Market methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:59:39'!
initializeWith: aCatalog
catalog := aCatalog ! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'Market class' category: #TusLibros!
Market class
instanceVariableNames: ''!
!Market class methodsFor: 'as yet unclassified' stamp: 'ig 6/6/2018 16:59:58'!
with: aCatalog
^self new initializeWith: aCatalog ! !
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment