From 8e6838fed5904b2a10f90c31ce8518c3fe003ccd Mon Sep 17 00:00:00 2001 From: Javier Calvo <javiercalvoporro@gmail.com> Date: Sun, 10 Nov 2024 13:54:38 +0100 Subject: [PATCH] Todo modificado. Quedan Cosas del trayecto --- src/es/markse/Contenedor.java | 1 - src/es/markse/Fecha.java | 2 - src/es/markse/Muelle.java | 3 +- src/es/markse/Puerto.java | 2 +- src/es/markse/Trayecto.java | 47 ++++++++++++-- uses/es/markse/ContenedorTest.java | 1 - uses/es/markse/MuelleTest.java | 1 + uses/es/markse/PuertoTest.java | 1 + uses/es/markse/TrayectoTest.java | 100 ++++++++++++++++++++++++----- 9 files changed, 129 insertions(+), 29 deletions(-) diff --git a/src/es/markse/Contenedor.java b/src/es/markse/Contenedor.java index 2ec7eb8..de63754 100644 --- a/src/es/markse/Contenedor.java +++ b/src/es/markse/Contenedor.java @@ -251,6 +251,5 @@ public class Contenedor { public void anyadirTrayecto(Trayecto t) { //COMPROBAR SI LA FECHA FIN DEL ANTERIOR ES ANTES QUE FECHA INICIO DEL SIGUIENTE //LO MISMO CON EL MUELLE DESTINO Y MUELLE ORIGEN - //LO MISMO PUERTO DESTINO Y PUERTO ORIGEN } } \ No newline at end of file diff --git a/src/es/markse/Fecha.java b/src/es/markse/Fecha.java index de0a953..232c7b0 100644 --- a/src/es/markse/Fecha.java +++ b/src/es/markse/Fecha.java @@ -4,10 +4,8 @@ package es.markse; * Implementación de la fecha del calendario gregoriano. * Ejercicio de Programación Orientada a Objetos * Implementación basada en tres atributos - * * @author felix * @author marga - * */ public class Fecha { diff --git a/src/es/markse/Muelle.java b/src/es/markse/Muelle.java index 5d88b4e..5c07ba8 100644 --- a/src/es/markse/Muelle.java +++ b/src/es/markse/Muelle.java @@ -456,6 +456,5 @@ public class Muelle { plazasLlenas++; } } - } - + } } \ No newline at end of file diff --git a/src/es/markse/Puerto.java b/src/es/markse/Puerto.java index 8338379..24ac1a7 100644 --- a/src/es/markse/Puerto.java +++ b/src/es/markse/Puerto.java @@ -170,4 +170,4 @@ public class Puerto { public String ciudadDelPuerto() { return this.ciudad; } -} +} \ No newline at end of file diff --git a/src/es/markse/Trayecto.java b/src/es/markse/Trayecto.java index 77047b6..b93de1e 100644 --- a/src/es/markse/Trayecto.java +++ b/src/es/markse/Trayecto.java @@ -3,7 +3,6 @@ */ package es.markse; - /** * Implementacion de la clase Trayecto * @author vicmtorm @@ -19,7 +18,7 @@ public class Trayecto { private Fecha fechaFinTrayecto; /** * Constructor del objeto Trayecto. - * @param muelleOrigen Muelle desde el que se empieza el Trayecto + * @param muelleOrigen Muelle desde el que se e mpieza el Trayecto * @param puertoOrigen Puerto desde el que se empieza el Trayecto * @param fechaInicioTrayecto Fecha en la que comienza el Trayecto * @param muelleDestino Muelle en el que finaliza un Trayecto @@ -27,15 +26,18 @@ public class Trayecto { * @param fechaFinTrayecto Fecha en la que finaliza un Trayecto */ public Trayecto (Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) { + comprobacionMuellesDistintos(muelleOrigen, muelleDestino); + comprobacionPuertosDistintos(puertoOrigen, puertoDestino); + comprobacionFecha(fechaInicioTrayecto); + comprobacionFecha(fechaFinTrayecto); + comprobacionOrdenFechas(fechaInicioTrayecto,fechaFinTrayecto); this.muelleOrigen=muelleOrigen; this.puertoOrigen=puertoOrigen; this.fechaInicioTrayecto=fechaInicioTrayecto; this.muelleDestino = muelleDestino; this.puertoDestino = puertoDestino; this.fechaFinTrayecto = fechaFinTrayecto; - comprobacionFecha(fechaInicioTrayecto); - comprobacionFecha(fechaFinTrayecto); - comprobacionOrdenFechas(); + } public Muelle getMuelleOrigen() { @@ -57,9 +59,38 @@ public class Trayecto { return this.fechaFinTrayecto; } + + /** + * Método que Comprueba si los Muelles Introducidos son Distintos o no + * @param muelleOrigen Muelle desde el que comienza el Trayecto + * @param muelleDestino Muelle en el que finaliza el Trayecto + * @throws IllegalArgumentException Si el Muelle de Origen y el Muelle de Destino son el Mismo + */ + + + private void comprobacionMuellesDistintos(Muelle muelleOrigen, Muelle muelleDestino) { + if (muelleOrigen.getIdentificador()==muelleDestino.getIdentificador()) { + throw new IllegalArgumentException ("¡El Muelle de Origen no puede ser igual al Muelle de Destino!"); + } + } + + /** + * Método que Comprueba si los Puertos Introducidos son Distintos o no, fijándonos en la Localidad + * @param puertoOrigen Puerto desde el que comienza el Trayecto + * @param puertoDestino Puerto en el que finaliza el Trayecto + * @throws IllegalArgumentException Si el Puerto de Origen y el Puerto de Destino son el Mismo + */ + + private void comprobacionPuertosDistintos(Puerto puertoOrigen, Puerto puertoDestino) { + if (puertoOrigen.ciudadDelPuerto()==puertoDestino.ciudadDelPuerto()) { + throw new IllegalArgumentException ("¡El Puerto de Origen no puede ser igual al Puerto de Destino!"); + } + } + /** * Método que Comprueba si la Fecha Introducida al Declarar un nuevo Trayecto es válida o no * @param fechaDada Fecha Introducida por el Usuario + * @throws IllegalArgumentException Si la Fecha a Comprobar es Nula, o no es una fecha válida */ private void comprobacionFecha(Fecha fechaDada) { @@ -77,11 +108,12 @@ public class Trayecto { /** * Método que Comprueba si el Orden de las Fechas de Inicio y del Final del Trayecto es el adecuado. + * @throws IllegalArgumentException Si la Fecha del Inicio del Trayecto es Posterior a la Fecha del Fin del Trayecto, lo cual es Imposible. */ - private void comprobacionOrdenFechas() { - if (this.fechaInicioTrayecto.getDiasDesdeEpoch()>this.fechaFinTrayecto.getDiasDesdeEpoch()){ + private void comprobacionOrdenFechas(Fecha fechaInicioTrayecto, Fecha fechaFinTrayecto) { + if (fechaInicioTrayecto.getDiasDesdeEpoch()>fechaFinTrayecto.getDiasDesdeEpoch()){ throw new IllegalArgumentException ("La Fecha del Inicio del Trayecto no puede ser posterior a la fecha del Fin del Trayecto"); } } @@ -152,3 +184,4 @@ public class Trayecto { "\nINFORMACION SOBRE EL DESTINO: \nCiudad Destino: "+ciudadDest+"\nPais Destino: "+paisDest+"\nFecha del Fin: "+FechaFin; } } + diff --git a/uses/es/markse/ContenedorTest.java b/uses/es/markse/ContenedorTest.java index 2dd26f7..000a1fb 100644 --- a/uses/es/markse/ContenedorTest.java +++ b/uses/es/markse/ContenedorTest.java @@ -5,7 +5,6 @@ package es.markse; import static org.junit.Assert.*; import org.junit.Test; - import es.uva.inf.poo.maps.GPSCoordinate; /** diff --git a/uses/es/markse/MuelleTest.java b/uses/es/markse/MuelleTest.java index 700c2ad..c37fb10 100644 --- a/uses/es/markse/MuelleTest.java +++ b/uses/es/markse/MuelleTest.java @@ -1,6 +1,7 @@ /** * Copyrigth Universidad de Valladolid 2024/2025 */ + package es.markse; import static org.junit.Assert.*; import org.junit.Test; diff --git a/uses/es/markse/PuertoTest.java b/uses/es/markse/PuertoTest.java index f2f0c48..79bdd4d 100644 --- a/uses/es/markse/PuertoTest.java +++ b/uses/es/markse/PuertoTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import es.uva.inf.poo.maps.GPSCoordinate; + /** * Test realizados para la clase Puerto * @author javcalv diff --git a/uses/es/markse/TrayectoTest.java b/uses/es/markse/TrayectoTest.java index 9d9305a..da35005 100644 --- a/uses/es/markse/TrayectoTest.java +++ b/uses/es/markse/TrayectoTest.java @@ -13,7 +13,7 @@ public class TrayectoTest { Muelle m1 = new Muelle ("01",c1,true,2,2); Muelle m2 = new Muelle ("02",c2,true,2,2); Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("ES","BAR"); + Puerto p2 = new Puerto ("AR","BUE"); Fecha f1 = new Fecha (9,11,2024); Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); @@ -107,25 +107,95 @@ public class TrayectoTest { Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); assertEquals(f2,t.getFechaFinTrayecto()); + } + + @Test(expected = IllegalArgumentException.class) + public void testcomprobacionMuellesDistintos() { + GPSCoordinate c1 = new GPSCoordinate(5d,5d); + GPSCoordinate c2 = new GPSCoordinate(10d,10d); + Muelle m1 = new Muelle ("01",c1,true,2,2); + Muelle m2 = new Muelle ("01",c2,false,4,1); + Puerto p1 = new Puerto ("ES","PAL"); + Puerto p2 = new Puerto ("AR","BUE"); + Fecha f1 = new Fecha (9,11,2024); + Fecha f2 = new Fecha(11,11,2024); + Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); + } - - @Test - public void comprobacionFecha() { + @Test(expected = IllegalArgumentException.class) + public void testcomprobacionPuertosDistintos() { + GPSCoordinate c1 = new GPSCoordinate(5d,5d); + GPSCoordinate c2 = new GPSCoordinate(10d,10d); + Muelle m1 = new Muelle ("01",c1,true,2,2); + Muelle m2 = new Muelle ("02",c2,false,2,2); + Puerto p1 = new Puerto ("ES","PAL"); + Puerto p2 = new Puerto ("ES","PAL"); + Fecha f1 = new Fecha (9,11,2024); + Fecha f2 = new Fecha(11,11,2024); + Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); + } - @Test - public void testPrecioTrayectoEnEuros() { - fail("Not yet implemented"); - } + @Test(expected = IllegalArgumentException.class) + public void testcomprobacionFecha() { + GPSCoordinate c1 = new GPSCoordinate(5d,5d); + GPSCoordinate c2 = new GPSCoordinate(10d,10d); + Muelle m1 = new Muelle ("01",c1,true,2,2); + Muelle m2 = new Muelle ("02",c2,false,2,2); + Puerto p1 = new Puerto ("ES","PAL"); + Puerto p2 = new Puerto ("ES","VAL"); + Fecha f1 = new Fecha (9,11,2024); + Fecha f2 = new Fecha(5,11,2024); + Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); +} + + + @Test(expected = IllegalArgumentException.class) + public void testcomprobacionFechaNula() { + GPSCoordinate c1 = new GPSCoordinate(5d,5d); + GPSCoordinate c2 = new GPSCoordinate(10d,10d); + Muelle m1 = new Muelle ("01",c1,true,2,2); + Muelle m2 = new Muelle ("02",c2,false,2,2); + Puerto p1 = new Puerto ("ES","PAL"); + Puerto p2 = new Puerto ("ES","VAL"); + Fecha f1 = new Fecha (9,11,2024); + Fecha f2 = null; + Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - @Test - public void testDistanciaMillasMarinas() { - fail("Not yet implemented"); } + + @Test(expected = IllegalArgumentException.class) + public void testcomprobacionFechaImposible() { + GPSCoordinate c1 = new GPSCoordinate(5d,5d); + GPSCoordinate c2 = new GPSCoordinate(10d,10d); + Muelle m1 = new Muelle ("01",c1,true,2,2); + Muelle m2 = new Muelle ("02",c2,false,2,2); + Puerto p1 = new Puerto ("ES","PAL"); + Puerto p2 = new Puerto ("ES","VAL"); + Fecha f1 = new Fecha (0,11,1999); + Fecha f2 = new Fecha (30,12,2000); + Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - @Test - public void testInforTrayecto() { - fail("Not yet implemented"); } -} \ No newline at end of file +} + //@Test + //public void comprobacionFecha() { + //} + + //@Test + //public void testPrecioTrayectoEnEuros() { + //fail("Not yet implemented"); + //} + + //@Test + //public void testDistanciaMillasMarinas() { + //fail("Not yet implemented"); + //} + + //@Test + //public void testInforTrayecto() { + //fail("Not yet implemented"); + //} + +//} -- GitLab