Skip to content

Commit

Permalink
Codigo de clase
Browse files Browse the repository at this point in the history
  • Loading branch information
facu777 committed Oct 3, 2024
1 parent 4e23452 commit bd4f887
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
30 changes: 28 additions & 2 deletions laPorota.wlk
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
object x {
object laPorota {
var stock = 100
var precio = 2
method stock()= stock
method vender(cantidadDePorotos, comprador){
comprador.pagar(precio*cantidadDePorotos)
stock = stock - cantidadDePorotos
}
}
class Comprador{
var medioDePago
method pagar(montoAPagar){
medioDePago.pagar(montoAPagar)
}
}
class TarjetaDeDebito{
var saldoDisponible
method pagar(monto){
if(saldoDisponible < monto) throw new DomainException(message="No hay saldo")
saldoDisponible = saldoDisponible - monto
}
}
class TarjetaDeCredito{
var deuda = 0
method pagar(monto){
deuda = deuda + monto
}
}

}
36 changes: 33 additions & 3 deletions tesLaPorota.wtest
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
import laPorota.*

describe "Tests de la porota" {

test "Test" {
assert.equals(1,1)
const debitoDeFacu = new TarjetaDeDebito(saldoDisponible = 0)
const facu = new Comprador(medioDePago = debitoDeFacu)
test "Cuando vendo bajo el stock" {
const creditoDePepe = new TarjetaDeCredito()
const pepe = new Comprador(medioDePago = creditoDePepe)
laPorota.vender(10, pepe)
assert.equals(90, laPorota.stock())
}

test "Cuando vendo se usa el medio de pago" {
assert.equals(1, 2)
}

test "Cuando no puedo vender, me entero de la razón" {
assert.throwsExceptionWithMessage("No hay saldo", { laPorota.vender(1, facu) })
}

test "Cuando no hay fondos, no se descuente el stock" {
assert.throwsException({ laPorota.vender(1, facu) })
assert.equals(100, laPorota.stock())
}

test "Cuando no puedo vender, el cliente no debe pagar" {
assert.equals(1, 2)
}
}

describe "Tests de Medios de pago" {
test "Cuando se paga con credito aumenta la deuda " {
assert.equals(1, 2)
}

test "Cuando se paga con debti reduce el saldo " {
assert.equals(1, 2)
}
}

0 comments on commit bd4f887

Please sign in to comment.