Created
April 21, 2013 23:54
-
-
Save delucas/5431620 to your computer and use it in GitHub Desktop.
UNTreF - Ejemplo de Pruebas: Clase CajaDeAhorros
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
package ar.edu.untref.pruebas; | |
public class CajaDeAhorros { | |
private String titular; | |
private double saldo = 0.0; | |
public CajaDeAhorros(String titular) { | |
this.titular = titular; | |
} | |
public String getTitular() { | |
return titular; | |
} | |
public void depositar(double monto) { | |
if (monto < 0.0) { | |
throw new Error("No puede depositarse un monto negativo"); | |
} | |
this.saldo = this.saldo + monto; | |
} | |
public void extraer(double monto) { | |
if (monto > this.saldo) { | |
throw new Error("Saldo insuficiente"); | |
} | |
if (monto < 0.0) { | |
throw new Error("No puede extraerse un monto negativo"); | |
} | |
this.saldo = this.saldo - monto; | |
} | |
public double getSaldo() { | |
return this.saldo; | |
} | |
} |
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
package ar.edu.untref.pruebas; | |
import junit.framework.Assert; | |
import org.junit.Test; | |
public class CajaDeAhorrosTests { | |
@Test | |
public void testQuePuedoDepositar() { | |
CajaDeAhorros caja = new CajaDeAhorros("yo"); | |
caja.depositar(100.0); | |
Assert.assertEquals(100.0, caja.getSaldo()); | |
} | |
@Test(expected=Error.class) | |
public void testQueNoPuedoDepositarNegativos() { | |
CajaDeAhorros caja = new CajaDeAhorros("yo"); | |
caja.depositar(-100.0); | |
} | |
@Test | |
public void testQuePuedoExtraer() { | |
CajaDeAhorros caja = new CajaDeAhorros("yo"); | |
caja.depositar(100.0); | |
caja.extraer(10.0); | |
Assert.assertEquals(90.0, caja.getSaldo()); | |
} | |
@Test(expected=Error.class) | |
public void testQueNoPuedoExtraer() { | |
CajaDeAhorros caja = new CajaDeAhorros("yo"); | |
caja.extraer(10.0); | |
} | |
@Test(expected=Error.class) | |
public void testQueNoPuedoExtraerCantidadNegativa() { | |
CajaDeAhorros caja = new CajaDeAhorros("yo"); | |
caja.depositar(100.0); | |
caja.extraer(-10.0); | |
} | |
@Test(expected=Error.class) | |
public void testQueNoPuedoExtraerCantidadNegativaSinTenerNada() { | |
CajaDeAhorros caja = new CajaDeAhorros("yo"); | |
caja.extraer(-10.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment