-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |