From 207e4eabddc4c87a529b60fcd0dab86f408ca3e0 Mon Sep 17 00:00:00 2001 From: Javier Calvo <javiercalvoporro@gmail.com> Date: Sun, 10 Nov 2024 19:34:07 +0100 Subject: [PATCH] Contenedor y Contenedor Test hechos --- src/es/markse/Contenedor.java | 14 ++-- src/es/markse/Puerto.java | 2 +- uses/es/markse/ContenedorTest.java | 110 ++++++++++++++++++++++++----- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/src/es/markse/Contenedor.java b/src/es/markse/Contenedor.java index e0275ce..1c24410 100644 --- a/src/es/markse/Contenedor.java +++ b/src/es/markse/Contenedor.java @@ -243,7 +243,7 @@ public class Contenedor { public boolean estadoApilado() { return this.apilado; } - + /** * Metodo que sirve para anyadir un trayecto al contenedor * @param t El trayecto que se añade al contenedor @@ -253,16 +253,18 @@ public class Contenedor { */ public void anyadirTrayecto(Trayecto t) { if (t == null) throw new IllegalArgumentException("El trayecto no puede ser nulo"); - if (this.trayectos == null) this.trayectos.add(t); + if (this.trayectos.size() == 0) this.trayectos.add(t); else { Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1); + //Si la fecha fin es mayor a la de inicio del nuevo if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch()) throw new IllegalArgumentException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente"); - if (!(ultimoT.getPuertoDestino().paisDelPuerto().equals(t.getPuertoOrigen().paisDelPuerto()) && - ultimoT.getPuertoDestino().ciudadDelPuerto().equals(t.getPuertoOrigen().ciudadDelPuerto()))) + //Si el puerto destino no es el origen del nuevo + if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto())) throw new IllegalArgumentException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto"); - if(!ultimoT.getMuelleDestino().equals(t.getMuelleOrigen())) - throw new IllegalArgumentException("El Muelle de origen es distinto al muelle de destino del ultimo trayecto"); + //Si el muelle de destino no es el de origen del nuevo + if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador())) + throw new IllegalArgumentException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto"); this.trayectos.add(t); } } diff --git a/src/es/markse/Puerto.java b/src/es/markse/Puerto.java index 369be27..319742c 100644 --- a/src/es/markse/Puerto.java +++ b/src/es/markse/Puerto.java @@ -76,7 +76,7 @@ public class Puerto { * @param m obtejo Muelle * @return true si esta, y false si no se encuentra en el puerto */ - private boolean comprobarMuelleEnPuerto(Muelle m) { + public boolean comprobarMuelleEnPuerto(Muelle m) { String id = m.getIdentificador(); GPSCoordinate cord = m.getGPSCoordinate(); for (Muelle muelle : this.muelles) { diff --git a/uses/es/markse/ContenedorTest.java b/uses/es/markse/ContenedorTest.java index f99fe6a..d49196d 100644 --- a/uses/es/markse/ContenedorTest.java +++ b/uses/es/markse/ContenedorTest.java @@ -150,24 +150,98 @@ public class ContenedorTest { @Test public void testAnyadirTrayecto() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - Puerto pOrig = new Puerto("ES" , "BAR"); - Puerto pDestino = new Puerto("IT" , "NAP"); - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(10d,10d); - Muelle m1 = new Muelle("01", c1, true, 1, 1); - Muelle m2 = new Muelle("01", c2, true, 1, 1); - pOrig.anyadirMuelle(m1); - pDestino.anyadirMuelle(m2); + Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); Fecha fInicio = new Fecha (25,11,2024); Fecha fFin = new Fecha(30,11,2024); - Trayecto t = new Trayecto(m1,pOrig,fInicio,m2,pDestino,fFin); - c.anyadirTrayecto(t); - - Puerto pDestino2 = new Puerto("IT" , "NAP"); - GPSCoordinate c3 = new GPSCoordinate(11d,11d); - Muelle m3 = new Muelle("02", c3, true, 1, 1); - pDestino2.anyadirMuelle(m3); - + Muelle m1 = new Muelle("01", new GPSCoordinate(5d,5d), true, 1, 1); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), true, 1, 1); + Puerto origen = new Puerto("ES" , "BAR"); + Puerto destino = new Puerto("IT" , "NAP"); + origen.anyadirMuelle(m1); + destino.anyadirMuelle(m2); + assertTrue(origen.comprobarMuelleEnPuerto(m1)); + assertTrue(destino.comprobarMuelleEnPuerto(m2)); + Trayecto t1 = new Trayecto(m1,origen,fInicio,m2,destino,fFin); + c.anyadirTrayecto(t1); + Muelle m3= new Muelle("02", new GPSCoordinate(10d,10d), true, 1, 1); + destino.anyadirMuelle(m3); + Fecha fFinal = new Fecha(1,12,2024); + Trayecto t2 = new Trayecto(m2,destino,fFin,m3,destino,fFinal); + c.anyadirTrayecto(t2); + } + + @Test(expected = IllegalArgumentException.class) + public void testAnyadirTrayectoNulo() { + Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); + c.anyadirTrayecto(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testAnyadirTrayectoFechaOrigenAntesQueFinalDeUltimoTrayecto() { + Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); + Muelle m1 = new Muelle("01", new GPSCoordinate(5d,5d), true, 1, 1); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), true, 1, 1); + Puerto origen = new Puerto("ES" , "BAR"); + Puerto destino = new Puerto("IT" , "NAP"); + origen.anyadirMuelle(m1); + destino.anyadirMuelle(m2); + assertTrue(origen.comprobarMuelleEnPuerto(m1)); + assertTrue(destino.comprobarMuelleEnPuerto(m2)); + Trayecto t1 = new Trayecto(m1,origen,fInicio,m2,destino,fFin); + c.anyadirTrayecto(t1); + Muelle m3= new Muelle("02", new GPSCoordinate(10d,10d), true, 1, 1); + destino.anyadirMuelle(m3); + Fecha fOrigen = new Fecha(29,11,2024); + Fecha fFinal = new Fecha(1,12,2024); + Trayecto t2 = new Trayecto(m2,destino,fOrigen,m3,destino,fFinal); + c.anyadirTrayecto(t2); + } + + @Test(expected = IllegalArgumentException.class) + public void testAnyadirTrayectoPuertoOrigenDistintoAlPuertoDestinoAnteriro() { + Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); + Muelle m1 = new Muelle("01", new GPSCoordinate(5d,5d), true, 1, 1); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), true, 1, 1); + Puerto origen = new Puerto("ES" , "BAR"); + Puerto destino = new Puerto("IT" , "NAP"); + origen.anyadirMuelle(m1); + destino.anyadirMuelle(m2); + assertTrue(origen.comprobarMuelleEnPuerto(m1)); + assertTrue(destino.comprobarMuelleEnPuerto(m2)); + Trayecto t1 = new Trayecto(m1,origen,fInicio,m2,destino,fFin); + c.anyadirTrayecto(t1); + Muelle m3= new Muelle("02", new GPSCoordinate(10d,10d), true, 1, 1); + destino.anyadirMuelle(m3); + Fecha fFin2 = new Fecha(4,12,2024); + Trayecto t2 = new Trayecto(m2,origen,fFin,m3,destino,fFin2); + c.anyadirTrayecto(t2); } -} + + @Test(expected = IllegalArgumentException.class) + public void testAnyadirTrayectoMuelleOrigenDistintoAlMuelleDestinoAnteriro() { + Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); + Muelle m1 = new Muelle("01", new GPSCoordinate(5d,5d), true, 1, 1); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), true, 1, 1); + Puerto origen = new Puerto("ES" , "BAR"); + Puerto destino = new Puerto("IT" , "NAP"); + origen.anyadirMuelle(m1); + destino.anyadirMuelle(m2); + assertTrue(origen.comprobarMuelleEnPuerto(m1)); + assertTrue(destino.comprobarMuelleEnPuerto(m2)); + Trayecto t1 = new Trayecto(m1,origen,fInicio,m2,destino,fFin); + c.anyadirTrayecto(t1); + Muelle m3= new Muelle("02", new GPSCoordinate(11d,11d), true, 1, 1); + destino.anyadirMuelle(m3); + Muelle mNuevo= new Muelle("03", new GPSCoordinate(12d,12d), true, 1, 1); + destino.anyadirMuelle(mNuevo); + Fecha fFin2 = new Fecha(4,12,2024); + Trayecto t2 = new Trayecto(m3,destino,fFin,mNuevo,destino,fFin2); + c.anyadirTrayecto(t2); + } +} \ No newline at end of file -- GitLab