diff --git a/.classpath b/.classpath index 7a1eac0324133f37a8af55b6d35ab52afbd8dfce..cf449d5e424e039ea6447c90d0aa329946df3d0f 100644 --- a/.classpath +++ b/.classpath @@ -10,4 +10,4 @@ </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="output" path="bin"/> -</classpath> +</classpath> \ No newline at end of file diff --git a/src/es/markse/Contenedor.java b/src/es/markse/Contenedor.java index 44673c845d8a3fbdaf0356681a1f0a0c147f13a6..653e62e26ad2d0d92f845eb48aa4768a306b850c 100644 --- a/src/es/markse/Contenedor.java +++ b/src/es/markse/Contenedor.java @@ -2,7 +2,6 @@ * Copyright UVa 2024/2025 */ package es.markse; - import java.util.ArrayList; import java.util.List; @@ -12,163 +11,65 @@ import java.util.List; * @author victorm */ public class Contenedor { - private String codigo; + private final List<Trayecto> trayectos = new ArrayList<>(); + + private ISO6346 codigo; private float pesoTara; private float maximaCargaUtil; private float volumen; private boolean techo; - private List<Trayecto> trayectos = new ArrayList<>(); - private boolean recogida; - private boolean transito; - private boolean apilado = false; + //Seleccion del estado y de las medidas + public enum estados{ REGOGIDA, TRANSITO } + public enum pesos{ KILOS, LIBRAS} + public enum volumenes{ METROS, PIES } + private estados estadoActual; + private final pesos pesoSeleccionado; + private final volumenes volumenSeleccionado; + + //Parametros para el paso de unas medidas a otras + private final float KILOS_A_LIBRAS = 2.20462f; + private final float LIBRAS_A_KILOS = 0.453592f; + private final float METROS_A_PIES = 35.3147f; + private final float PIES_A_METROS= 0.0283168f; + /** * Constructor del Objeto Contenedor - * @param codigoDueno codigo de 3 letras mayusculas del dueño - * @param equipamiento Una letra U, J o Z que indica el equipamiento - * @param numeroSerie El Numero de serie de 6 digitos - * @param pesoContenedor El peso del contenedor en kilogramos + * @param pesoTara El peso del contenedor en kilogramos * @param maximaCargaUtil La carga util del contenedor dada en kilogramos * @param volumen El volumen dado en metros cúbicos - * @param transito Indica si esta en transito (true) o en recogida (false) + * @param estadoActual estado del contenedor + * @param pesoSeleccionado en que medidas se dan los pesos de la tara y la carga + * @param volumenSeleccionado en que medida se da el volumen * @param techo indica si tiene techo (true) o no (false) */ - public Contenedor(String codigoDueno, char equipamiento, String numeroSerie, float pesoTara, float maximaCargaUtil, float volumen, boolean transito, boolean techo) { - validarCodigoDueno(codigoDueno); - validarEquipamiento(equipamiento); - comprobarPesos(pesoTara, maximaCargaUtil, volumen); - validarNumeroSerie(numeroSerie); + public Contenedor(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual, pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { + if (pesoTara<=0 || maximaCargaUtil <=0 || volumen<=0) + throw new IllegalArgumentException("Los pesos no puedne ser menores a 0"); + this.codigo = codigo; + this.pesoTara = pesoTara; this.maximaCargaUtil = maximaCargaUtil; this.volumen = volumen; - this.transito = transito; - this.recogida = !transito; + + this.estadoActual = estadoActual; + this.pesoSeleccionado = pesoSeleccionado; + this.volumenSeleccionado = volumenSeleccionado; this.techo = techo; - String digitoControl = String.valueOf(calcularDigitoControl(codigoDueno, equipamiento, numeroSerie)); - this.codigo = codigoDueno.toUpperCase() + equipamiento + numeroSerie + digitoControl; - } - - /** - * Metodo que compara e codigo del dueño para ver si es correcto - * @param codigoDueno Cadena de 3 letras mayusculas - * @throws IllegalArgumentException Si el codigoDueno no coincide con el patron correcto - */ - private void validarCodigoDueno(String codigoDueno) { - if (codigoDueno == null) throw new IllegalArgumentException("El código del dueño debe tener 3 letras mayúsculas."); - if (codigoDueno.length() != 3 || !codigoDueno.matches("[A-Za-z]{3}")) - throw new IllegalArgumentException("El código del dueño debe tener 3 letras mayúsculas."); - } - - /** - * Metodo que sirve para comparar si el equipamiento es uno de los correctos - * @param equipamiento Es un caracter que indica el equipamiento - * @throws IllegalArgumentException si el equipamiento no es correcto (no es ni U ni J ni Z) - */ - private void validarEquipamiento(char equipamiento) { - if (equipamiento != 'U' && equipamiento != 'J' && equipamiento != 'Z') { - throw new IllegalArgumentException("Equipamiento debe ser 'U', 'J' o 'Z'."); - } - } - - /** - * metodo para comparar si el numero de serie es correcto - * @param numeroSerie el numero de serie del contenedor - * @throws Si el numeroSerie no es correcto (no son 6 numeros) o si es nulo - * - */ - private void validarNumeroSerie(String numeroSerie) { - if (numeroSerie == null) throw new IllegalArgumentException("El numero de serie no puede ser nulo"); - if (numeroSerie.length() != 6 || !numeroSerie.matches("\\d{6}")) { - throw new IllegalArgumentException("El número de serie debe tener 6 dÃgitos."); - } - } - - /** - * Metodo qe comprueba los pesos de los contenedores - * @param pesoTara Peso del contenedor - * @param maximaCargaUtil Maxima carga util del contenedor - * @param volumen Volumen del contenedor - * @throws IllegalArgumentException si alguno de los pesos es menor que 1 - */ - private void comprobarPesos(float pesoTara, float maximaCargaUtil, float volumen) { - if (pesoTara < 1 || maximaCargaUtil <1 || volumen < 1) { - throw new IllegalArgumentException("Los pesos deben ser igual o mayores a 1"); - } - } - - /** - * Metodo que sirve para calcular el diito de control mediante el codigo del dueño, el equipamiento y el - * numero de serie - * @return devuelve el digito de control - */ - private int calcularDigitoControl(String codigoDueno, char equipamiento, String numeroSerie) { - String codigoCompleto = codigoDueno + equipamiento + numeroSerie; - int[] valores = {10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38}; - int suma = 0; - for (int i = 0; i < codigoCompleto.length(); i++) { - char c = codigoCompleto.charAt(i); - int valor; - if (Character.isLetter(c))valor = valores[c - 'A']; - else valor = Character.getNumericValue(c); - suma += valor*(int) Math.pow(2, i); - } - int resto = suma % 11; - return (resto == 10) ? 0 : resto; - } - - /** - * Metodo que sirve para devolver el codigo del contenedor - * @return el codigo del contenedor (compelto) - */ - public String getCodigo() { - return this.codigo; - } - - /** - * Metodo que devuelve si un contenedor tiene techo - * @return si tiene techo (true) o si no lo tiene (false) - */ - public boolean tieneTecho() { - return this.techo; } /** * 1.1.13 Metodo que sirve para cambiar el estado a recogida de un contenedor - * Si esta apilado no puede estar en recogida - * @throws IllegalArgumentException si el contenedor esta apilado */ public void cambiarEstadoARecogida() { - if(this.estadoApilado()) throw new IllegalArgumentException("No puedes cambiar el estado a un contenedor apilado"); - this.recogida = true; - this.transito = false; + this.estadoActual = estados.REGOGIDA; } /** - * 1.1.14 metodo que sirve para cambiar un contenedor a estado de transito - * Si esta apilado no puede estar en transito - * @throws IllegalArgumentException si el contenedor esta apilado + * 1.1.14 Metodo que sirve para cambiar un contenedor a estado de transito */ public void cambiarEstadoATransito() { - if(this.estadoApilado()) throw new IllegalArgumentException("No puedes cambiar el estado a un contenedor apilado"); - this.recogida = false; - this.transito = true; - } - - /** - * Metodo para cambiar estado a apilado - */ - public void cambiarEstadoApilado() { - this.apilado = true; - this.transito = false; - this.recogida = false; - } - - /** - * Metodo para cmabiar el estado de apilado --> recogida - */ - public void cambiarEstadoDesapilado() { - this.apilado = false; - this.recogida = true; + this.estadoActual = estados.TRANSITO; } /** @@ -182,89 +83,126 @@ public class Contenedor { * 1.1.16 Metodo que devuelve el volumen del contenedor en metros cubicos * @return volumen en metros cubicos */ - public float volumenEnMetrosCubicos() { - return this.volumen; + public double volumenEnMetrosCubicos() { + return (volumenSeleccionado == volumenes.METROS) ? this.volumen : this.volumen*this.PIES_A_METROS; } /** * 1.1.17 metodo que devuelve el volumen del contenedor en pies cubicos * @return volumen en pies cubicos */ - public float volumenEnPiesCubicos() { - return this.volumen*35.3147f; - + public double volumenEnPiesCubicos() { + return (volumenSeleccionado == volumenes.PIES) ? this.volumen : this.volumen*this.METROS_A_PIES; } /** * 1.1.18 Metodo que devuelve el peso del contenedor en Kilogramos * @return peso del contenedor en kilogramos */ - public float obtenerPesoKilos() { - return this.pesoTara; + public double obtenerPesoKilos() { + return (this.pesoSeleccionado == pesos.KILOS ) ? this.pesoTara : this.pesoTara *this.LIBRAS_A_KILOS; } /** * 1.1.19 Metodo que devuelve el peso del contenedor en Libras * @return peso del contenedor en Libras */ - public float obtenerPesoLibras() { - return this.pesoTara*2.20462f; + public double obtenerPesoLibras() { + return (this.pesoSeleccionado == pesos.LIBRAS ) ? this.pesoTara : this.pesoTara *this.KILOS_A_LIBRAS; } /** - * Metodo que devuelve la maxima carga util de un contenedor - * @return La maxima carga util de un contenedor + * Metodo que calcula el costo total de los trayectos de un contenedor + * @param costeDiarioTrayecto El coste diario de un dia de trayecto + * @param costePorMilla El coste por milla recorrida en un trayecto + * @return el precio total del transporte del contenedor */ - public float cargaUtilContenedor() { - return this.maximaCargaUtil; + public double precioTransporteTotalContenedor(double costeDiarioTrayecto, double costePorMilla) { + if (this.trayectos.isEmpty()) + return 0.0; + double precioTotal = 0.0; + for (Trayecto t : this.trayectos) { + precioTotal += t.precioTrayectoEnEuros(costeDiarioTrayecto, costePorMilla); + } + return precioTotal; } - /** - * Metodo que devuelve el estado de recogida de un contenedor - * @return estado de recogida de un contenedor - */ - public boolean estadoRecogida() { - return this.recogida; - } + /****************************** + * EMPLEACION DE OTROS METODOS* + ******************************/ - /** - * Metodo que devuelve el estado de transito de un contenedor - * @return estado de transito de un contenedor - */ - public boolean estadoTransito() { - return this.transito; - } - - /** - * Metodo que devuelve el estado de apilamiento de un contenedor - * @return estado de apilamiento de un 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 - * @throws IllegalArgumentException si es trayecto es nulo, si la fecha fin del ultimo trayecto es superior - * a la de inicio del nuevo trayecto, o si el puerto/muelle destinos del ultimo trayecto no son los de origen - * del nuevo. + * @throws IllegalArgumentException si es trayecto es nulo, + * @throws IllegalStateException si la fecha fin del ultimo trayecto es superior a la de inicio del nuevo trayecto + * @throws IllegalStateException si el puerto/muelle destinos del ultimo trayecto no son los de origen del nuevo. */ public void anyadirTrayecto(Trayecto t) { - if (t == null) throw new IllegalArgumentException("El trayecto no puede ser nulo"); - if (this.trayectos.size() == 0) this.trayectos.add(t); + if (t == null) + throw new IllegalArgumentException("El trayecto no puede ser nulo"); + if (this.trayectos.isEmpty()) + 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"); + throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente"); //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"); + throw new IllegalStateException("El puerto de origen debe ser el mismo que el 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"); + throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto"); this.trayectos.add(t); } } + + /** + * Metodo que devuelve si un contenedor tiene techo + * @return si tiene techo (true) o si no lo tiene (false) + */ + public boolean tieneTecho() { + return this.techo; + } + + /** + * Metodo que devuelve la maxima carga util de un contenedor + * @return La maxima carga util de un contenedor + */ + public float cargaUtilContenedorKilos() { + return (this.pesoSeleccionado == pesos.KILOS ) ? this.maximaCargaUtil : this.maximaCargaUtil *this.LIBRAS_A_KILOS; + } + + /** + * Metodo que devuelve la maxima carga util de un contenedor + * @return La maxima carga util de un contenedor + */ + public float cargaUtilContenedorLibras() { + return (this.pesoSeleccionado == pesos.LIBRAS ) ? this.maximaCargaUtil : this.maximaCargaUtil *this.KILOS_A_LIBRAS; + } + + /** + * Metodo que sirve para devolver el codigo del contenedor + * @return el codigo del contenedor (compelto) + */ + public String getCodigo() { + return this.codigo.codigoContenedor(); + } + + /** + * Metodo que sirve para devolver si el contenedor esta en transito + * @return true si esta en transito o false si no lo esta + */ + public boolean contenedorEnTransito() { + return (estadoActual == estados.TRANSITO) ? true : false; + } + + /** + * Metodo que sirve para devolver si el contenedor esta en recogida + * @return true si esta en recogida o false si no lo esta + */ + public boolean contenedorEnRecogida() { + return (estadoActual == estados.REGOGIDA) ? true : false; + } } \ No newline at end of file diff --git a/src/es/markse/ISO6346.java b/src/es/markse/ISO6346.java new file mode 100644 index 0000000000000000000000000000000000000000..1cc22caa230cf4e69250546960021b32493c5f5c --- /dev/null +++ b/src/es/markse/ISO6346.java @@ -0,0 +1,127 @@ +/** + * Copyright UVa 2024/2025 + */ +package es.markse; +import java.util.regex.Pattern; +/** + * Implementacion de la clase ISO6346 para el codigo del contenedor + * @author javcalv + * @authro victorm + */ +public class ISO6346 { + + private final String codigoDuenyo; + private char equipamiento; + private final int numeroSerie; + private int digitoControl; + private final Pattern CODIGO_DUENO = Pattern.compile("[A-Za-z]{3}"); + + /** + * Implementacion de la clase ISO6346 + * @param codigoDuenyo Codigo del dueño de 3 letras (Mayusculas) + * @param equipamiento Equipamiento del contenedor --> U, J o Z + * @param numeroSerie Numero de serie del contenedor. De 0-999999 + * @throws IllegalArgumentException si el codigo del dueño es nulo + * @throws IllegalArgumentException si el codigo del dueño no tiene el patron correcto + * @throws IllegalArgumentException si el equipamiento no es correcto + * @throws IllegalArgumentException si el numero de serie es incorrecto + */ + public ISO6346(String codigoDuenyo, char equipamiento, int numeroSerie) { + if(codigoDuenyo == null) + throw new IllegalArgumentException("El codigo del dueño no puede ser nulo"); + if (!validarCodigoDueño(codigoDuenyo)) + throw new IllegalArgumentException("El codigo del dueño no tiene el patron correcto (3 letras)"); + if (!comprobarEquipamiento(equipamiento)) + throw new IllegalArgumentException("Equipamiento debe ser 'U', 'J' o 'Z'"); + if (numeroSerie<0 || numeroSerie>999999) + throw new IllegalArgumentException("El numero de serie debe ser entre 0-999999"); + + this.codigoDuenyo = codigoDuenyo.toUpperCase(); + this.equipamiento = equipamiento; + this.numeroSerie = numeroSerie; + this.digitoControl = calcularDigitoControl(codigoDuenyo, equipamiento, numeroSerie); + } + + + /** + * Metodo que sirve para validar si el codigo del dueño tiene el patron correcto + * @param codigoDuenyo Codigo del dueño que se debe validar + * @return true si es correcto o falso si no lo es + */ + private boolean validarCodigoDueño(String codigoDuenyo) { + return (this.CODIGO_DUENO.matcher(codigoDuenyo).matches()) ? true : false; + } + + /** + * Metodo que comprueba el equipamiento es correcto + * @param equipamiento Equipamiento que se comprobara + * @return true si es correcto o false si no lo es + */ + private boolean comprobarEquipamiento(char equipamiento) { + return (equipamiento == 'U' || equipamiento == 'J' || equipamiento == 'Z')? true: false; + } + + /** + * Metodo que sirve para calcular el diito de control mediante el codigo del dueño, el equipamiento y el + * numero de serie + * @param codigoDuenyo Codigo del dueño + * @param equipamiento = equipamiento del contenedor + * @param numeroSerie numero de serie del contenedor + * @return devuelve el digito de control + */ + private int calcularDigitoControl(String codigoDueno, char equipamiento, int numeroSerie) { + String codigoCompleto = codigoDueno + equipamiento + numeroSerieString(numeroSerie); + int[] valores = {10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38}; + int suma = 0; + for (int i = 0; i < codigoCompleto.length(); i++) { + char c = codigoCompleto.charAt(i); + int valor; + if (Character.isLetter(c))valor = valores[c - 'A']; + else valor = Character.getNumericValue(c); + suma += valor*(int) Math.pow(2, i); + } + int resto = suma % 11; + return (resto == 10) ? 0 : resto; + } + + /** + * Metodo que pasa el numero de Serie a un String (con los 6 caracteres) + * @param numeroSerie Numero de serie a transformar + * @return numero de Serie transformado en String + */ + private String numeroSerieString(int numeroSerie) { + return String.format("%06d", numeroSerie); + } + + /** + * Metodo que devuelve el codigo del dueño + * @return codigo del dueño + */ + public String codigoDuenyo() { + return this.codigoDuenyo; + } + + /** + * Metodo que devuelve el equipamiento del codigo + * @return equipamiento + */ + public char equipamiento() { + return this.equipamiento; + } + + /** + * Metodo que devuelve el numero de Serie del contenedor + * @return numero de Serie del contenedor + */ + public int numeroSerie() { + return this.numeroSerie; + } + + /** + * Metodo que devuelve el codigo del Contenedor completo + * @return codigo del contenedor + */ + public String codigoContenedor() { + return (this.codigoDuenyo + this.equipamiento + numeroSerieString(numeroSerie) + this.digitoControl); + } +} \ No newline at end of file diff --git a/src/es/markse/Muelle.java b/src/es/markse/Muelle.java index 91cf18b9809118edb7f7fed29d100beff9542598..eb4a0ebd25d029b7f01aca1c2e780c9980c20fea 100644 --- a/src/es/markse/Muelle.java +++ b/src/es/markse/Muelle.java @@ -4,6 +4,7 @@ package es.markse; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import es.uva.inf.poo.maps.GPSCoordinate; @@ -13,17 +14,19 @@ import es.uva.inf.poo.maps.GPSCoordinate; * @author victorm */ public class Muelle { - private Plaza[] plazas; - private String identificador; - private boolean operativo; - private GPSCoordinate cord; - private int plazasVacias; - private int plazasLlenas = 0; - private int plazasSemillenas = 0; + private final Plaza[] plazas; + private final String identificador; + public enum estado{ + OPERATIVO, FUERA_DE_SERVICIO + } + private estado estadoActual; + private final GPSCoordinate cord; + private final Pattern IDENTIFICADOR_REGUEX = Pattern.compile("^\\d{2}$"); + private final Pattern CODIGO_CONTENEDOR = Pattern.compile("[A-Z]{4}\\d{7}"); private static class Plaza { private int altura; - private List<Contenedor> contenedores = new ArrayList<>(); + private final List<Contenedor> contenedores = new ArrayList<>(); /** * Constructor del objeto Plaza @@ -34,20 +37,31 @@ public class Muelle { } /** - * Metodo que indica si un contenedor se encuentra en la plaza o no - * @param codigo Codigo del contenedor que queremos buscar - * @return true si contiene ese contenedor en la Plaza o false si no lo tiene + * 1.1.8 Metodo que devuelve si una plaza esta vacia o no + * @return true si esta vacia o false si no lo esta */ - public boolean contieneContenedor(String codigo) { - return this.contenedores.stream().anyMatch(c -> c.getCodigo().equals(codigo)); - } + public boolean plazaVacia() { + return this.contenedores.isEmpty(); + } /** - * Metodo que indica el nivel que tiene un contenedor, dado un codigo. + * 1.1.8 Metodo que devuelve si una plaza esta llena o no + * @return true si la plaza esta llena o si no lo esta + */ + public boolean plazaLlena() { + return (this.contenedores.size() == this.altura + || (!this.contenedores.isEmpty() && !this.ultimoContenedor().tieneTecho())) ? true : false; + } + + /** + * 1.1.10 Metodo que indica el nivel que tiene un contenedor, dado un codigo. * @param codigo Codigo del contenedo que queremos ver su plaza * @return la altura en la que se encuentra (del 1 que es la baja ahasta n, que es el máximo de contenedores apilabres) + * @throws IllegalArgumentException si el codigo es nulo */ public int nivelContenedor(String codigo) { + if (codigo == null) + throw new IllegalArgumentException("El codigo no puede ser nulo"); for (int i = 0; i < this.contenedores.size(); i++) { if (this.contenedores.get(i).getCodigo().equals(codigo)) { return i + 1; @@ -56,50 +70,42 @@ public class Muelle { return -1; } - /** - *Metodo que sirve para colar el contenedor en una plaza (apilarlo si esppsible) + * 1.1.11 Metodo que sirve para colar el contenedor en una plaza (apilarlo si es posible) * @param codigo: Codigo del contenedor - * @return true si se ha colodado, o false si no, ya que la plaza esta llena o el ultimo contenedor de esa plaza - * no tiene techo + * @return true si se ha colodado, o false si no + * @throws IllegalArgumentException si el contenedor es nulo */ - public boolean colocarContenedor(Contenedor contenedor) { - if (this.contenedores.size() >= this.altura) { - return false; - } - if (this.contenedores.isEmpty() || this.ultimoContenedor().tieneTecho()) { - return this.contenedores.add(contenedor); - } - return false; + public void colocarContenedor(Contenedor contenedor) { + //Encapsulamos errores para evitarlos en un futuro (si hay cambios) + if (contenedor == null) + throw new IllegalArgumentException("El contenedor no puede ser nulo"); + + if (contenedor.contenedorEnTransito()) + throw new IllegalStateException("El Contenedor esta en transito, no se puede colocar"); + + if(this.contenedores.size() == this.altura) + throw new IllegalStateException("La plaza está llena"); + + if(!this.contenedores.isEmpty() && !this.contenedores.get(this.contenedores.size()-1).tieneTecho()) + throw new IllegalStateException("El ultimo contenedor no tiene techo"); + + if (this.contenedores.isEmpty() || (this.ultimoContenedor().tieneTecho() && this.contenedores.size() < this.altura)) { + this.contenedores.add(contenedor); + } } /** - * Metodo que devuelve true o false si el contenedor que introducimos se encuentra en el nivel mas alto actual de la plaza, es decir, que - * es el ultimo contenedor apilado en esa plaza (sin necesidad que sea el maximo) - * @param codigoContenedor Codigo del contenedor que se comprueba si es el ultimo - * @return true si es el ultimo o false si no lo es. - */ - public boolean estaEnUltimoNivel(String codigoContenedor) { - return this.ultimoContenedor().getCodigo().equals(codigoContenedor); - } - - /** - * Metodo que desapila el contendor + * 1.1.12 Metodo que desapila el ultimo contendor */ public void desapilarContenedor() { - this.contenedores.remove(contenedores.size() - 1); + if(!this.contenedores.isEmpty()) + this.contenedores.remove(contenedores.size() - 1); } - /** - * Metod que devuelve el ultimo contenedor de la Plaza - * @return ultimo contenedor de la plaza o null si esta vacio - */ - public Contenedor ultimoContenedor() { - if (contenedores.isEmpty()) { - return null; - } - return contenedores.get(contenedores.size() -1); - } + /********************************************* + * OTROS METODOS DE LA PLAZA PARA SU GESTION * + *********************************************/ /** * Metodo que devuelve el numero decontenedores @@ -116,91 +122,77 @@ public class Muelle { public int altura() { return this.altura; } + + /** + * Metodo que devuelve true o false si el contenedor que introducimos se encuentra en el nivel mas alto actual de la plaza, es decir, que + * es el ultimo contenedor apilado en esa plaza (sin necesidad que sea el maximo) + * @param codigoContenedor Codigo del contenedor que se comprueba si es el ultimo + * @return true si es el ultimo o false si no lo es. + */ + public boolean estaEnUltimoNivel(String codigoContenedor) { + Contenedor c = this.ultimoContenedor(); + return (c == null) ? false : c.getCodigo().equals(codigoContenedor); + } + + /** + * Metodo que indica si un contenedor se encuentra en la plaza o no + * @param codigo Codigo del contenedor que queremos buscar + * @return true si contiene ese contenedor en la Plaza o false si no lo tiene + */ + public boolean contieneContenedor(String codigo) { + return (this.nivelContenedor(codigo)!=-1) ? true : false; + } + + /** + * Metod que devuelve el ultimo contenedor de la Plaza + * @return ultimo contenedor de la plaza o null si esta vacio + */ + public Contenedor ultimoContenedor() { + if (contenedores.isEmpty()) { + return null; + } + return contenedores.get(contenedores.size() -1); + } } /** * Constructor del objeto Muelle * @param identificador Identificador de 2 digitos (numeros) * @param cord Punto GPS que lo localiza. Clase GPSCoordinate. - * @param operativo Estado del muelle. + * @param estadoActual Estado del muelle. * @param plazas Numero de plazas totales que tiene el Muelle * @param altura numero maximo de contenedores que se pueden apilar encima de otro */ - public Muelle (String identificador, GPSCoordinate cord, boolean operativo, int plazas, int altura) { - comprobarValoresNulos(identificador, cord); - comprobarValoresMuelle(identificador, plazas, altura); + public Muelle (String identificador, GPSCoordinate cord, estado estadoActual, int plazas, int altura) { + if(identificador == null || cord == null) + throw new IllegalArgumentException("Los valores del identificador y coordenada no pueden ser nulos"); + if(plazas<1 || altura<1) + throw new IllegalArgumentException("Los tamaños (altura y plaza) no puedne ser menores a 1"); + if (!comprobarIdentificador(identificador)) + throw new IllegalArgumentException("El formato del identificador es incorrecto"); + this.identificador = identificador; this.cord = cord; - this.plazasVacias = plazas; this.plazas = new Plaza[plazas]; - this.operativo = operativo; - + this.estadoActual = estadoActual; //Inicializamos el array de las plazas for (int i = 0; i < plazas; i++) { this.plazas[i] = new Plaza(altura); } - } /** - * Metodo para comporbar que los valores no sean nulos a la hora de crear un Objeto de tipo Muelle + * Metodo que comprueba si el identificador es correcto * @param identificador Identificador del muelle - * @param cord Coordenadas de muelle (clase GPSCoordinate) - * @throws IllegalArgumentException si el identificador o la coordenada son nulos + * @return true si es correcto o false si no lo es */ - private void comprobarValoresNulos(String identificador, GPSCoordinate cord) { - if (identificador == null) throw new IllegalArgumentException("Identificador no puede ser nulo"); - if (cord == null) throw new IllegalArgumentException("Identificador no puede ser nulo"); + private boolean comprobarIdentificador(String identificador) { + return (IDENTIFICADOR_REGUEX.matcher(identificador).matches()) ? true : false; } - /** - * Metodo que comprueba si el identificador es correcto (2 digitos) - * @param identificador identificador del muelle - * @throws IllegalArgumentException si la altura o la plaza son menores que 1, o si el identificador - * no es correcto - */ - private void comprobarValoresMuelle(String identificador, int plazas, int altura) { - if (plazas<1) throw new IllegalArgumentException("Numero de plazas debe ser 1 o mas"); - if (altura<1) throw new IllegalArgumentException("La altura debe ser 1 o mayor"); - if (identificador.length() != 2 || !identificador.matches("\\d{2}")) { - throw new IllegalArgumentException("Formato incorrecto. Debe ser un entero de 2 dÃgitos numéricos (por ejemplo, 04, 15, 65)"); - } - } - - /** - * Metodo que sirve para si un codigo de contenedor es correcto - * @param codigo Codigo del contenedor que se comprueba - * @throws IllegalArgumentException si el codigo es nulo o no corresponde a un codigo correcto - */ - private void comprobarCodigoContenedor(String codigo) { - if (codigo == null) throw new IllegalArgumentException("Codigo no puede ser nulo"); - if (!codigo.matches("[A-Z]{4}\\d{7}")) throw new IllegalArgumentException("El codigo no pertenece a un codigo de contenedor"); - } - - /** - * Metodo que devuelve el identificador de un muelle. Este identificador sera de 2 digitos. - * @return identificador del muelle - */ - public String getIdentificador() { - return this.identificador; - } - - /** - * Metodo que indica si el Muelle esta operativo o no - * @return Si esta operativo (true) o no (false) - */ - public boolean estaOperativo() { - return this.operativo; - } - - /** - * Metodo que devuelve el punto de coordenadas del muelle - * Este punto pertenece a la clase GPSCoordinate - * @return coordenadas del muelle; - */ - public GPSCoordinate getGPSCoordinate() { - return this.cord; - } + /*************************************** + * EMPLEACION DE LOS METODOS QUE PIDEN * + ****************************************/ /** * 1.1.7 Metodo que devuelve el numero de plazas totales que tiene el muelle @@ -216,26 +208,35 @@ public class Muelle { * @return numero de plazas vacias. */ public int plazasVacias() { - return this.plazasVacias; + int c = 0; + for (Plaza p : this.plazas) + if(p.plazaVacia()) c++; + return c; } /** * 1.1.8 Metodo que devuelve el numero de plazas llenas. Una plaza llena es la que: * - Se encuentran con el numero máximo de contenedores apilados en la plaza * - El contenedor o el ultimo contenedor apilado no tiene techo, lo que no se peden colocar más. - * @return plazasLlenas + * @return numero de plazas llenas */ public int plazasLlenas() { - return this.plazasLlenas; + int c = 0; + for (Plaza p: this.plazas) + if (p.plazaLlena()) c++; + return c; } /** * 1.1.8 Metodo que devuelve el numero de plazas semillenas. Las plazas semillenas son aquellas que * contienen un contenedor y se puede apilar mas encima de el (tiene techo) - * @return plazasSemillenas + * @return numero de plazas semillenas */ public int plazasSemillenas() { - return this.plazasSemillenas; + int c = 0; + for (Plaza p: this.plazas) + if (!p.plazaLlena() && !p.plazaVacia()) c++; + return c; } /** @@ -245,7 +246,11 @@ public class Muelle { * @return la plaza del contenedor o -1 si no se encuentra en ninguna plaza */ public int plazaActual(String codigo) { - this.comprobarCodigoContenedor(codigo); + if(codigo == null) + throw new IllegalArgumentException("El codigo no puede ser nulo"); + if(!comprobarCodigoContenedor(codigo)) + throw new IllegalArgumentException("El codigo de contenedor es incorrecto"); + for (int i = 0; i < this.plazas.length; i++) { if (this.plazas[i].numeroContenedores() != 0 && this.plazas[i].contieneContenedor(codigo)) { return i; @@ -261,7 +266,10 @@ public class Muelle { * @return el nivel en el que se encuentra el contenedor o -1 si no se encuentra */ public int nivelEnPlaza(String codigo) { - this.comprobarCodigoContenedor(codigo); + if(codigo == null) + throw new IllegalArgumentException("Codigo del contenedor no puede ser nulo"); + if(!this.comprobarCodigoContenedor(codigo)) + throw new IllegalArgumentException("El codigo de contenedor no tiene el formato correcto"); for (Plaza plaza : this.plazas) { if (plaza.numeroContenedores() != 0 && plaza.contieneContenedor(codigo)) { return plaza.nivelContenedor(codigo); @@ -274,185 +282,127 @@ public class Muelle { * 1.1.11 Metodo para colocar un contenedor en una plaza y apilarlo si es posible * @param codigo Codigo del contenedor que queremos colocar * @param plaza La plaza del contenedor - * @throws IllegalArgumentException si el contenedor es nulo, si la plaza esta fuera de rango, si ese contenedor ya esta apilado - * Si ese contenedor essta en transito, si el contenedor donde se coloca encima no tiene techo o si la plaza - * esta llena + * @throws IllegalArgumentException si el contenedor es nulo + * @throws IllegalArgumentException si la plaza esta fuera de rango, + * @throws IllegalStateException si el muelle no esta operativo + * @throws IllegalStateException si ese contenedor ya esta apilado + * @throws IllegalStateException si ese contenedor esta en transito, + * @throws IllegalStateException si el contenedor donde se coloca encima no tiene techo + * @throws IllegalStateException si la plaza esta llena */ public void colocarContenedorEnPlaza(Contenedor contenedor, int plaza) { - if (contenedor == null) throw new IllegalArgumentException("El Ccontenedor no puede ser nulo"); - if (plaza < 0 || plaza > this.numeroDePlazasTotales()) throw new - IllegalArgumentException("La plaza debe de estar entre 0-"+ (this.plazas.length -1)); - //Si ya esta apilado - if (contenedor.estadoApilado()) { - throw new IllegalArgumentException("El Contenedor ya esta apilado"); - } + //Comprobamos si el contenedor es nulo o la plaza no pertenece al rango + if (contenedor == null) + throw new IllegalArgumentException("El Contenedor no puede ser nulo"); + if (plaza < 0 || plaza > this.numeroDePlazasTotales()) + throw new IllegalArgumentException("La plaza debe de estar entre 0-"+ (this.plazas.length -1)); + + //Comprobamos si esta operativo o no + if(!this.estaOperativo()) + throw new IllegalStateException("El muelle no esta operativo"); + //Si esta entransito - if (contenedor.estadoTransito()) { - throw new IllegalArgumentException("El Contenedor esta en transito, no se puede colocar"); + if (contenedor.contenedorEnTransito()){ + throw new IllegalStateException("El Contenedor esta en transito, no se puede colocar"); } - Contenedor ultimo = this.plazas[plaza].ultimoContenedor(); - // Verificar si hay un último contenedor y si tiene techo - boolean teniaTecho = (ultimo != null && ultimo.tieneTecho()); - if (this.plazas[plaza].colocarContenedor(contenedor)) { - contenedor.cambiarEstadoApilado(); - int plazasDespues = this.plazas[plaza].numeroContenedores(); - int plazasAntes = plazasDespues - 1; - this.actualizarPlazas(plazasAntes, plazasDespues, this.plazas[plaza], teniaTecho); - } - else { - if (!this.plazas[plaza].ultimoContenedor().tieneTecho()) - throw new IllegalArgumentException("El contenedor no tiene techo"); - throw new IllegalArgumentException("La plaza está llena"); - } + //Si ya se encuentra apilado el contenedor en el muelle + if (nivelEnPlaza(contenedor.getCodigo()) != -1) { + throw new IllegalStateException("El Contenedor ya esta apilado"); + } + + //Verificar si la plaza esta llena + Plaza p = this.plazas[plaza]; + if(p.contenedores.size() == p.altura()) + throw new IllegalStateException("La plaza está llena"); + + //Verificamos si el ultimo contenedor tiene techo + if(p.contenedores.size() > 0 && !p.ultimoContenedor().tieneTecho()) + throw new IllegalStateException("El contenedor no tiene techo"); + else{ + this.plazas[plaza].colocarContenedor(contenedor); + } } /** * 1.1.12 Metodo que sirve para sacar un contenedor de una Plaza y desapilarlo si es posible - * @param contenedor: Contenedor a desapilar de la plaza - * @throws IllegalArgumentException si el contenedor es nulo, si no se encuentra apilado en ningun sitio o - * si el contenedor no se encuentra en la ultima posicion (no se podria desapilar) + * @param contenedor Contenedor a desapilar de la plaza + * @throws IllegalArgumentException si el contenedor es nulo + * @throws IllegalStateException si el contenedor se encuentra en transito + * @throws IllegalStateException si el contenedor no se encuentra apilado en el muelle + * @throws IllegalStateException si el contenedor no se encuentra en la ultima plaza */ - public void sacarContenedorDePlaza(Contenedor contenedor) { - if (contenedor == null) throw new IllegalArgumentException("El Ccontenedor no puede ser nulo"); - if (!contenedor.estadoApilado()) throw new IllegalArgumentException("El Contenedor no esta en ninguna plaza. Se encuentra en transito o en recogida"); - + //Comprobamos que el contenedor no sea nulo o que esté en transito + if (contenedor == null) + throw new IllegalArgumentException("El Contenedor no puede ser nulo"); + if (contenedor.contenedorEnTransito()) + throw new IllegalStateException("El Contenedor se encuentra en transito"); + //Comprobar si se encuentra en funcionamiento + if(!this.estaOperativo()) + throw new IllegalStateException("El muelle se encuentra fuera de servicio"); + + String c = contenedor.getCodigo(); + //Buscamos que el contenedor este en el muelle + if (plazaActual(c) == -1) + throw new IllegalStateException("El contenedor no se encuentra apilado en este muelle"); + //Buscamos el contenedor y desapilamos el contenedor si se encuentra en el ultimo nivel for (Plaza plaza : this.plazas) { - if (plaza.contieneContenedor(contenedor.getCodigo())) { - if (plaza.estaEnUltimoNivel(contenedor.getCodigo())) { - int plazasAntes = plaza.numeroContenedores(); - boolean teniaTecho = plaza.ultimoContenedor().tieneTecho(); + if (plaza.contieneContenedor(c)) { + if (plaza.estaEnUltimoNivel(c)) plaza.desapilarContenedor(); - contenedor.cambiarEstadoDesapilado(); - int plazasDespues = plaza.numeroContenedores(); - this.actualizarPlazas(plazasAntes, plazasDespues, plaza, teniaTecho); - } - else { - throw new IllegalArgumentException("El Contenedor No esta en el ultimo nivel"); - } + else + throw new IllegalStateException("El Contenedor no esta en el ultimo nivel, no se puede desapilar"); } } } /** - * Metodo que cambia el techo a un contenedor comprobando que este sea el ultimo de la plaza para evitar - * problemas, ya que no se puede cambiar el techo a un contenedor que tenga apilado otro encima - * @param contenedor Contenedor que se cambia el techo - * @throws IllegalArgumentException si el contenedero es nulo, si el contenedor no se encuentra en la ultima - * plaza (no se puede cambiar el techo) o si el contenedor no se encuentra en el muelle + * Metodo para alternar si esta operativo o no (Test) */ - public void alternarTechoContenedor(Contenedor contenedor) { - if (contenedor == null) throw new IllegalArgumentException("El contenedor no puede ser nulo"); - String codigo = contenedor.getCodigo(); - boolean encontrado = false; - for (Plaza plaza: this.plazas) { - if (plaza.contieneContenedor(codigo)) { - encontrado = true; - //Si el contenedor esta en el ultimo nivel de una plaza se puede cambiar el techo - if (plaza.estaEnUltimoNivel(codigo)) { - plaza.ultimoContenedor().alternarTecho(); - //Si la cantidad de contenedores es menor a la altura, hay cambios en el numero de plazas - if (plaza.numeroContenedores() < plaza.altura()) { - //Si ahora tiene techo, las llenas son uno mas y semillenas uno menos - if (plaza.ultimoContenedor().tieneTecho()) { - this.plazasLlenas--; - this.plazasSemillenas++; - } - //Si ahora no lo tiene, las llenas son una mas y semillenas uno menos - else { - this.plazasLlenas++; - this.plazasSemillenas--; - } - } - } - //No se encuentra en la ultima plaza - else { - throw new IllegalArgumentException("El contenedor no esta en la ultima plaza (no se puede cambiar el techo"); - } - } - } - if(!encontrado) throw new IllegalArgumentException("No se en cuentra el contenedor"); + public void alternarOperativo() { + this.estadoActual = (this.estadoActual == estado.OPERATIVO) ? estado.FUERA_DE_SERVICIO : estado.OPERATIVO; + } + + /** + * Metodo que sirve para si un codigo de contenedor es correcto + * @param codigo Codigo del contenedor que se comprueba + * @return true si el codigo es correcto o false si no lo es + */ + private boolean comprobarCodigoContenedor(String codigo) { + return (this.CODIGO_CONTENEDOR.matcher(codigo).matches()) ? true : false; } /** - * Metodo para alternar si esta operativo o no (Test) + * Metodo que devuelve el identificador de un muelle. Este identificador sera de 2 digitos. + * @return identificador del muelle */ - public void alternarOperativo() { - this.operativo = !this.operativo; - } + public String getIdentificador() { + return this.identificador; + } /** - * Metodo que actualiza el numero de plazas (vacias, llenas, semillenas) al añadir o eliminar un contenedor - * @param plazasAntes El numero de plazas antes de añadir o eliminar un contenedor - * @param plazasDespues El numero despues - * @param plaza La plaza donde se ha realizado una de esas 2 acciones (eliminar/añadir) + * Metodo que indica si el Muelle esta operativo o no + * @return Si esta operativo (true) o no (false) */ - private void actualizarPlazas(int plazasAntes, int plazasDespues, Plaza plaza, boolean teniaTecho) { - int alturaMaxima = plaza.altura(); - boolean esVacio = plazasDespues == 0; - boolean esPrimerContenedor = plazasDespues == 1; - boolean esPenultimoContenedor = plazasDespues == (alturaMaxima - 1); - boolean esLleno = plazasDespues == alturaMaxima; - - // Eliminación de contenedor - if (plazasDespues < plazasAntes) { - //Plaza queda vacia - if (esVacio) { - if (alturaMaxima == 1 || !teniaTecho) { - this.plazasLlenas--; - this.plazasVacias++; - } - else { - this.plazasSemillenas--; - this.plazasVacias++; - } - } - //Se queda con el penultimo contenedor - else if (esPenultimoContenedor) { - this.plazasLlenas--; - this.plazasSemillenas++; - } - - //Se elimina un contenedor que no sea ni el primero ni el ultimo - else { - //Si el contenedor eliminado tenia no techo Llenas a Semillenas - if (!teniaTecho) { - this.plazasLlenas--; - this.plazasSemillenas++; - } - } - - } - // Adición de contenedor - else { - //Si coloca el ultimo contenedor - if (esLleno) { - if (alturaMaxima == 1) { - plazasVacias--; - plazasLlenas++; - } - else { - plazasSemillenas--; - plazasLlenas++; - } - } - //Si coloca el primer contenedor - else if (esPrimerContenedor) { - if (plaza.ultimoContenedor().tieneTecho()) { - plazasVacias--; - plazasSemillenas++; - } - else { - plazasVacias--; - plazasLlenas++; - } - } - //Resto de contenedores sin ser el primero ni el ultimo - else if (!plaza.ultimoContenedor().tieneTecho()) { - plazasSemillenas--; - plazasLlenas++; - } - } - } + public boolean estaOperativo() { + return this.estadoActual == estado.OPERATIVO; + } + + /** + * Metodo que devuelve el punto de coordenadas del muelle + * Este punto pertenece a la clase GPSCoordinate + * @return coordinates del muelle; + */ + public GPSCoordinate getGPSCoordinate() { + return this.cord; + } + + /** + * Metodo que devuelve la lista de las plazas + * @return Lista de las plazas + */ + public Plaza[] plazas() { + return this.plazas.clone(); + } } \ No newline at end of file diff --git a/src/es/markse/Puerto.java b/src/es/markse/Puerto.java index 9b46c177f9a65fa4c8b4b56312267853e04698bb..e69dae9c8f06fb0f63fd1762dc45c9ca514025ee 100644 --- a/src/es/markse/Puerto.java +++ b/src/es/markse/Puerto.java @@ -6,6 +6,7 @@ package es.markse; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import es.uva.inf.poo.maps.GPSCoordinate; @@ -13,79 +14,66 @@ import es.uva.inf.poo.maps.GPSCoordinate; * Implementacion de la clase Puerto. * @author javcalv * @author victorm - * */ public class Puerto { - private String pais; - private String ciudad; - private List<Muelle> muelles = new ArrayList<>(); + private final String pais; + private final String ciudad; + private final List<Muelle> muelles = new ArrayList<>(); + private final Pattern PAIS_REGUEX = Pattern.compile("[A-Za-z]{2}"); + private final Pattern CIUDAD_REGUEX = Pattern.compile("[A-Za-z]{3}"); + + /** * Constructor del objeto Puerto. * @param pais Pais al que pertenece el puerto (2 letras) * @param ciudad Ciudad al que pertenece el puerto (3 letras) */ public Puerto(String pais, String ciudad) { - comprobarIdentificador(pais, ciudad); + if(pais == null || ciudad == null) + throw new IllegalArgumentException("El pais o la ciudad no pueden ser nulos"); + if(!comprobarIdentifiadores(pais.toUpperCase(), ciudad.toUpperCase())) + throw new IllegalArgumentException("El pais o la ciudad no tiene el formato incorrecto. 'XX' pais y 'XXX' ciudad."); this.pais = pais.toUpperCase(); this.ciudad = ciudad.toUpperCase(); } /** - * Metodo que comprueba si tanto el pais como la ciudad son correctos (2 y 3 letras respectivamente) - * @param pais Pais del puerto (2 letras) - * @param ciudad Ciudad del puerto(3 letras) - * @throws IllegalArgumentException si el pais o la ciudad no corresponden con sus respectivos formatos o - * cuando son nulos + * Metodo que comprueba si el pais o la ciudad tienen el formato correcto mediante expresiones regulares. + * @param pais Pais del puerto a comprobar + * @param ciudad Ciudad del puerto a comprobar + * @return true si es el formto correcto o false si no lo es */ - private void comprobarIdentificador(String pais, String ciudad) { - if (pais == null || ciudad == null) { - throw new IllegalArgumentException("El pais o la ciudad no pueden ser nulos"); - } - if (!(pais.matches("[A-Za-z]{2}") && ciudad.matches("[A-Za-z]{3}"))) { - throw new IllegalArgumentException("Formato incorrecto. Debe ser en el formato 'XX-XXX', donde XX es el paÃs y XXX es la ciudad, usando solo letras."); - } + private boolean comprobarIdentifiadores(String pais, String ciudad) { + return (PAIS_REGUEX.matcher(pais).matches() && CIUDAD_REGUEX.matcher(ciudad).matches()) ? true: false; } /** * 1.1.1. Metodo que agrega un nuevo muelle al puerto. Se comprueba que ese muelle no se encuentre ya agregado. * Si no lo esta, lo agrega, si ya se encuentra agregado, no. * @param m objeto tipo Muelle + * @return true si el muelle se ha agregado, o false si el muelle ya esta agregado * @throws IllegalArgumentException si el muelle es nulo */ public boolean anyadirMuelle(Muelle m) { - if (m == null) throw new IllegalArgumentException("Muelle no puede ser nulo"); - if (!this.comprobarMuelleEnPuerto(m)) { + if (m == null) + throw new IllegalArgumentException("Muelle no puede ser nulo"); + if (!this.comprobarMuelleEnPuerto(m)) return this.muelles.add(m); - } return false; } /** - * 1.1.2 Método que elimina un muelle del puerto. + * 1.1.2 Método que elimina un muelle del puerto. Si encuentra uno con el mismo ID, lo elimina * @param id : Identificador del muelle que se elimina + * @return true si se ha eliminado el muelle y false si no se ha eliminado ninguno (n) + * @throws IllegalArgumentException si el id es nulo; */ public boolean eliminarMuelle(String id) { - if (id == null) throw new IllegalArgumentException("Identificador no puede ser nulo"); + if (id == null || id == "") + throw new IllegalArgumentException("Identificador no puede ser nulo o vacio"); return this.muelles.removeIf(muelle -> muelle.getIdentificador().equals(id)); } - /** - * Metodo para comprobar si un muelle esta en ese puerto o no, para agregarle, ya que solo puede haber un muelle con el mismo - * identificador para cada puerto. - * @param m obtejo Muelle - * @return true si esta, y false si no se encuentra en el puerto - */ - public boolean comprobarMuelleEnPuerto(Muelle m) { - String id = m.getIdentificador(); - GPSCoordinate cord = m.getGPSCoordinate(); - for (Muelle muelle : this.muelles) { - if (id.equals(muelle.getIdentificador())|| (cord.getDistanceTo(muelle.getGPSCoordinate())==0)) { - return true; - } - } - return false; - } - /** * 1.1.3 Metodo que comprueba si un puerto esta Lleno o no * @return true (si esta lleno) o false (si no lo esta) @@ -153,7 +141,28 @@ public class Puerto { } } return cercanos.toArray(new Muelle[0]); - } + } + + /** + * Metodo para comprobar si un muelle esta en ese puerto o no, para agregarle, + * ya que solo puede haber un muelle con el mismo identificador para cada puerto. + * @param m obtejo Muelle + * @return true si esta, y false si no se encuentra en el puerto + * @throws IllegalArgumentException si el muelle es nulo + */ + public boolean comprobarMuelleEnPuerto(Muelle m) { + if (m == null) + throw new IllegalArgumentException("El muelle no puede ser nulo"); + String id = m.getIdentificador(); + GPSCoordinate cord = m.getGPSCoordinate(); + for (Muelle muelle : this.muelles) { + if (id.equals(muelle.getIdentificador()) || (cord.getDistanceTo(muelle.getGPSCoordinate())==0)) { + return true; + } + } + return false; + } + /** * Metodo que devuelve el pais del puerto * @return pais del perto diff --git a/src/es/markse/Trayecto.java b/src/es/markse/Trayecto.java index 6de811b5cbe4f680f3f23b1303e920a91ee76eca..d1365920a2927ae4ccee0c47f47aeda68c3b482e 100644 --- a/src/es/markse/Trayecto.java +++ b/src/es/markse/Trayecto.java @@ -3,6 +3,8 @@ */ package es.markse; +import java.io.Serializable; + /** * Implementacion de la clase Trayecto * @author vicmtorm @@ -25,14 +27,31 @@ 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) { - disponibilidadMuelle(muelleOrigen); - disponibilidadMuelle(muelleDestino); - muellePerteneceAlPuerto(muelleOrigen,puertoOrigen); - muellePerteneceAlPuerto(muelleDestino,puertoDestino); - comprobacionMuellesDistintos(muelleOrigen, muelleDestino, puertoOrigen, puertoDestino); - comprobacionFecha(fechaInicioTrayecto); - comprobacionFecha(fechaFinTrayecto); - comprobacionOrdenFechas(fechaInicioTrayecto,fechaFinTrayecto); + //Comprobamos si los valores no son nulos + if(muelleOrigen == null || muelleDestino == null) + throw new IllegalArgumentException("Los muelles no pueden ser nulos"); + if(puertoOrigen == null || puertoDestino == null) + throw new IllegalArgumentException("Los puertos no pueden ser nulos"); + if(fechaInicioTrayecto == null || fechaFinTrayecto == null) + throw new IllegalArgumentException("Las fechas no pueden ser nulas"); + + //Comprobamos si los muelles estan operativos + if (!muelleOrigen.estaOperativo()) + throw new IllegalStateException("El muelle de origen esta fuera de servicio"); + if (!muelleDestino.estaOperativo()) + throw new IllegalStateException("El muelle de destino esta fuera de servicio"); + + //Comprobamos si los muelles pertenecen al puerto + if (!puertoOrigen.comprobarMuelleEnPuerto(muelleOrigen)) + throw new MuelleNoPerteneceAlPuertoException("El muelle no pertenece al puerto"); + if (!puertoDestino.comprobarMuelleEnPuerto(muelleDestino)) + throw new MuelleNoPerteneceAlPuertoException("El muelle no pertenece al puerto"); + + if (!comprobacionMuellesDistintos(muelleOrigen, muelleDestino, puertoOrigen, puertoDestino)) + throw new IllegalArgumentException("El muelle de origen no puede ser igual al de destino"); + 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"); + this.muelleOrigen=muelleOrigen; this.puertoOrigen=puertoOrigen; this.fechaInicioTrayecto=fechaInicioTrayecto; @@ -41,141 +60,43 @@ public class Trayecto { this.fechaFinTrayecto = fechaFinTrayecto; } - /** - * Método que Devuelve el Muelle de Origen - * @return muelleOrigen - */ - - public Muelle getMuelleOrigen() { - return this.muelleOrigen; - } - - /** - * Método que Devuelve el Muelle de Destino - * @return muelleDestino - */ - - public Muelle getMuelleDestino() { - return this.muelleDestino; - } - - /** - * Método que Devuelve el Puerto de Origen - * @return puertoOrigen - */ - - public Puerto getPuertoOrigen() { - return this.puertoOrigen; - } - - /** - * Método que Devuelve el Puerto de Destino - * @return puertoDestino - */ - - public Puerto getPuertoDestino() { - return this.puertoDestino; - } - - /** - * Método que Devuelve la Fecha del Inicio del Trayecto - * @return fechaInicioTrayecto - */ - - public Fecha getFechaInicioTrayecto() { - return this.fechaInicioTrayecto; - } - - /** - * Método que Devuelve la Fecha del Fin del Trayecto - * @return fechaFinTrayecto - */ - - public Fecha getFechaFinTrayecto() { - return this.fechaFinTrayecto; - } - - /** - * Método que comprueba si un Muelle está Operativo o está Fuera de Servicio - * @param muelle Muelle para el que queremos conocer su disponibilidad - * @throws Illegal Argument Exception En el caso de que el Muelle se encuentre Fuera de Servicio - */ - - private void disponibilidadMuelle(Muelle muelle) { - if (!muelle.estaOperativo()) throw new IllegalArgumentException ("¡El Muelle Introducido está Fuera de Servicio!"); - } - - /** - * Método que comprueba si un Muelle Introducido pertenece al Puerto Introducido - * @param muelle Tipo Muelle - * @param puerto Tipo Puerto - * @throws Illegal Argument Exception En el caso de que el Muelle no se encuentre en ese Puerto - */ - - private void muellePerteneceAlPuerto(Muelle muelle, Puerto puerto) { - if (!puerto.comprobarMuelleEnPuerto(muelle))throw new IllegalArgumentException ("¡El Muelle Introducido no Pertenece al Puerto Introducido!"); - } - /** * 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 + * @return true si los muelles son distintos o false si son los mismos */ - - private void comprobacionMuellesDistintos(Muelle muelleOrigen, Muelle muelleDestino, Puerto puertoOrigen, Puerto puertoDestino) { - if (muelleOrigen.getIdentificador()== muelleDestino.getIdentificador()&& puertoOrigen.identificadorPuerto().equals(puertoDestino.identificadorPuerto())) { - throw new IllegalArgumentException ("¡El Muelle de Origen no puede ser igual al Muelle de Destino!"); - } + private boolean comprobacionMuellesDistintos(Muelle muelleOrigen, Muelle muelleDestino, Puerto puertoOrigen, Puerto puertoDestino) { + return (muelleOrigen.getIdentificador() == muelleDestino.getIdentificador() && + puertoOrigen.identificadorPuerto().equals(puertoDestino.identificadorPuerto())) ? false : true; } - /** - * 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 - */ - - private void comprobacionFecha(Fecha fechaDada) { - if (fechaDada == null) { - throw new IllegalArgumentException ("La Fecha introducida no puede ser nula"); - } - } - - /** - * 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(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"); - } - } + /********************************************* + * IMPLEMENTACION DE FUNCIONALIDADES BASICAS * + *********************************************/ /** - * Método que indica si la Fecha de Fin de Trayecto es superior a una Fecha Dada + * 1.1.21 Método que indica si la Fecha de Fin de Trayecto es superior a una Fecha Dada * @param fechaDada Fecha de Introducida por el usuario * @return True si la Fecha de Fin de Trayecto es Superior, y False si la Fecha de Fin de Trayecto no es Superior */ - public boolean FechaFinTrayectoSuperior(Fecha fechaDada) { - if (fechaDada == null) throw new IllegalArgumentException("Fecha no puede ser nula"); + if (fechaDada == null) + throw new IllegalArgumentException("Fecha no puede ser nula"); if (fechaFinTrayecto.getDiasDesdeEpoch()>fechaDada.getDiasDesdeEpoch()) { return false; } else { return true; } - } /** - * Método que, introduciendo el coste diario y el coste por milla, devuelve el precio calculado en Euros de un Trayecto + * 1.1.22. Metodo que, introduciendo el coste diario y el coste por milla, devuelve el precio calculado en Euros de un Trayecto * @param costeDiarioTrayecto Valor en Euros del Coste Diario de un Trayecto * @param costePorMilla Valor en Euros del Coste por Milla de un Trayecto * @return Precio del Trayecto Calculado en Euros */ - public double precioTrayectoEnEuros(double costeDiarioTrayecto, double costePorMilla) { if (costeDiarioTrayecto <= 0) { throw new IllegalArgumentException ("El Coste Diario del Trayecto no es válido"); @@ -183,26 +104,23 @@ public class Trayecto { else if(costePorMilla <= 0) { throw new IllegalArgumentException ("El Coste por Milla del Trayecto no es válido"); } - int dias = (fechaFinTrayecto.getDiasDesdeEpoch()-fechaInicioTrayecto.getDiasDesdeEpoch())+1; + int dias = numeroDeDiasDeTrayceto(); double dist = distanciaMillasMarinas(); return ((dias*costeDiarioTrayecto)+(dist*costePorMilla)); } /** - * Método que devuelve la Distancia calculada en Millas Marinas entre 2 Muelles Distintos + * 1.1.23 Método que devuelve la Distancia calculada en Millas Marinas entre 2 Muelles Distintos * @return Distancia entre 2 Muelles Distintos calculada en Millas Marinas - * */ - public double distanciaMillasMarinas() { return muelleOrigen.getGPSCoordinate().getDistanceTo(muelleDestino.getGPSCoordinate()); } - + /** - * Método que Proporciona Información acerca del Trayecto: Localidad y PaÃs de los Puertos de Origen y Destino, y Fechas de Inicio y Fin del Trayecto + * 1.1.24 Método que Proporciona Información acerca del Trayecto: Localidad y PaÃs de los Puertos de Origen y Destino, y Fechas de Inicio y Fin del Trayecto * @return Información Sobre el Origen (Ciudad, Pais, Fecha Inicio) y el Destino (Ciudad, Pais, Fecha Fin) */ - public String inforTrayecto() { String ciudadOrig = this.puertoOrigen.ciudadDelPuerto(); String paisOrig = this.puertoOrigen.paisDelPuerto(); @@ -210,8 +128,77 @@ public class Trayecto { String ciudadDest = this.puertoDestino.ciudadDelPuerto(); String paisDest = this.puertoDestino.paisDelPuerto(); String FechaFin = this.fechaFinTrayecto.aCadena(); - return"INFORMACION SOBRE EL ORIGEN: \nCiudad Origen: "+ciudadOrig+"\nPais Origen: "+paisOrig+"\nInicio del Trayecto: "+FechaInicio+ "\n\nINFORMACION SOBRE EL DESTINO: \nCiudad Destino: "+ciudadDest+"\nPais Destino: "+paisDest+"\nFin del Trayecto: "+FechaFin+"\n"; } + + /************************* + * OTRAS FUNCIONALIDADES * + *************************/ + + /** + * Metodo que devuelve el numero de dias de un trayecto + */ + private int numeroDeDiasDeTrayceto(){ + return (this.fechaFinTrayecto.getDiasDesdeEpoch()- this.fechaInicioTrayecto.getDiasDesdeEpoch()) +1; + } + + /** + * Método que Devuelve el Muelle de Origen + * @return muelleOrigen + */ + public Muelle getMuelleOrigen() { + return this.muelleOrigen; + } + + /** + * Método que Devuelve el Muelle de Destino + * @return muelleDestino + */ + public Muelle getMuelleDestino() { + return this.muelleDestino; + } + /** + * Método que Devuelve el Puerto de Origen + * @return puertoOrigen + */ + + public Puerto getPuertoOrigen() { + return this.puertoOrigen; + } + /** + * Método que Devuelve el Puerto de Destino + * @return puertoDestino + */ + public Puerto getPuertoDestino() { + return this.puertoDestino; + } + + /** + * Método que Devuelve la Fecha del Inicio del Trayecto + * @return fechaInicioTrayecto + */ + public Fecha getFechaInicioTrayecto() { + return this.fechaInicioTrayecto; + } + + /** + * Método que Devuelve la Fecha del Fin del Trayecto + * @return fechaFinTrayecto + */ + public Fecha getFechaFinTrayecto() { + return this.fechaFinTrayecto; + } + + /** + * Excpcion lanzada para indicar que un muelle no pertenece al puerto + * @author javcalv + * @author victorm + */ + public class MuelleNoPerteneceAlPuertoException extends RuntimeException implements Serializable{ + private static final long serialVersionUID = 1L; + public MuelleNoPerteneceAlPuertoException(String m) { + super(m); + } + } } \ No newline at end of file diff --git a/uses/es/markse/ContenedorTest.java b/uses/es/markse/ContenedorTest.java index 3964a12b644acc102838abc2046e6cc224a5d6e4..573f76fe8eb09822c6abcb7c780cd47a142b7f36 100644 --- a/uses/es/markse/ContenedorTest.java +++ b/uses/es/markse/ContenedorTest.java @@ -5,6 +5,10 @@ package es.markse; import static org.junit.Assert.*; import org.junit.Test; +import es.markse.Contenedor.estados; +import es.markse.Contenedor.pesos; +import es.markse.Contenedor.volumenes; +import es.markse.Muelle.estado; import es.uva.inf.poo.maps.GPSCoordinate; /** @@ -16,233 +20,230 @@ public class ContenedorTest { @Test public void testContenedor() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - assertEquals("RTFZ0654328", c.getCodigo()); - assertEquals(100.0f, c.obtenerPesoKilos(), 0.001f); - Contenedor c2 = new Contenedor("ABC", 'U', "123456", 200, 500, 1000, true, true); - assertEquals(500.0f, c2.cargaUtilContenedor(), 0.001f); - Contenedor c3 = new Contenedor("TOO", 'J', "123459", 200, 500, 1000, true, true); - assertEquals(1000f, c3.volumenEnMetrosCubicos(), 0.001f); - + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + assertEquals("ZREJ0567310", c1.getCodigo()); + assertEquals(100.0f, c1.obtenerPesoKilos(), 0.001f); + assertEquals(400.0f, c1.cargaUtilContenedorKilos(), 0.001f); + assertEquals(500.0f, c1.volumenEnMetrosCubicos(), 0.001f); } @Test(expected = IllegalArgumentException.class) - public void testContenedorCodigoDuenoNulo(){ - new Contenedor(null, 'U', "123456", 200, 500, 1000, true, true); + public void testContenedorTaraInvalida(){ + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + new Contenedor(i1, -0.54f, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); } @Test(expected = IllegalArgumentException.class) - public void testContenedorCodigoDuenoInvalido(){ - new Contenedor("e34", 'J', "123456", 200, 500, 1000, true, true); + public void testContenedorCargaInvalida(){ + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + new Contenedor(i1, 100, 0, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); } @Test(expected = IllegalArgumentException.class) - public void testContenedorCodigoDuenoTamanyoInvalido(){ - new Contenedor("e34433", 'Z', "123456", 200, 500, 1000, true, true); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorEquipamientoInvalido(){ - new Contenedor("e34433", 'R', "123456", 200, 500, 1000, true, true); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorEquipamientoInvalido_R(){ - new Contenedor("ABC", 'R', "123456", 200, 500, 1000, true, true); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorEquipamientoInvalido_X(){ - new Contenedor("DEF", 'X', "654321", 300, 600, 1200, false, false); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorNumeroSerieNulo(){ - new Contenedor("DEF", 'J', null, 300, 600, 1200, false, false); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorNumeroSerieLetras(){ - new Contenedor("DEF", 'J', "R450T0", 300, 600, 1200, false, false); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorNumeroSerieInvalido(){ - new Contenedor("DEF", 'J', "59392020", 300, 600, 1200, false, false); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorTaraMenorA1(){ - new Contenedor("DEF", 'J', "134567", 0, 600, 1200, false, false); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorCargaMenorA1(){ - new Contenedor("DEF", 'J', "134567", 100, -4, 1200, false, false); - } - - @Test(expected = IllegalArgumentException.class) - public void testContenedorVolumenMenorA1(){ - new Contenedor("DEF", 'J', "134567", 100, 600, 0.5f, false, false); - } - - @Test - public final void testTieneTecho() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - Contenedor c2 = new Contenedor("ACC", 'Z', "493212", 100, 400, 1000, false, false); - assertTrue(c.tieneTecho()); - assertFalse(c2.tieneTecho()); + public void testContenedorVolumenInvalida(){ + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + new Contenedor(i1, 100, 400, -0.45f, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); } @Test public final void testCambiarEstadoARecogida() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, true, true); - c.cambiarEstadoARecogida(); - assertTrue(c.estadoRecogida()); - assertFalse(c.estadoTransito()); - Contenedor c2 = new Contenedor("RTT", 'Z', "555432", 100, 400, 1000, false, true); - GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); - m.colocarContenedorEnPlaza(c2, 0); - assertFalse(c2.estadoRecogida()); - } - - @Test(expected = IllegalArgumentException.class) - public final void testCambiarEstadoARecogidaContenedorApilado() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); - m.colocarContenedorEnPlaza(c, 0); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, true); + assertFalse(c.contenedorEnRecogida()); c.cambiarEstadoARecogida(); + assertTrue(c.contenedorEnRecogida()); } @Test public final void testCambiarEstadoATransito() { - Contenedor c = new Contenedor("RTT", 'Z', "555432", 100, 400, 1000, false, true); - assertFalse(c.estadoTransito()); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + assertFalse(c.contenedorEnTransito()); c.cambiarEstadoATransito(); - assertTrue(c.estadoTransito()); + assertTrue(c.contenedorEnTransito()); } - @Test (expected = IllegalArgumentException.class) - public final void testCambiarEstadoATransitoContenedorApilado() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); - assertFalse(c.estadoTransito()); - m.colocarContenedorEnPlaza(c, 1); - assertFalse(c.estadoTransito()); - c.cambiarEstadoATransito(); + @Test + public final void testAlternarTecho() { + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, false); + assertFalse(c.tieneTecho()); + c.alternarTecho(); + assertTrue(c.tieneTecho()); + c.alternarTecho(); + assertFalse(c.tieneTecho()); } + @Test + public void testVolumenEnMetrosCubicos() { + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, false); + assertEquals(500f, c.volumenEnMetrosCubicos(), 0.01f); + ISO6346 i2 = new ISO6346("DRT", 'U', 56731); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.PIES, false); + assertEquals(500 * 0.0283168f, c2.volumenEnMetrosCubicos(), 0.01f); + } @Test public void testVolumenEnPiesCubicos() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - assertEquals(1000*35.3147f, c.volumenEnPiesCubicos(), 0.001f); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, false); + assertEquals(500f * 35.3147f, c.volumenEnPiesCubicos(), 0.01f); + ISO6346 i2 = new ISO6346("DRT", 'U', 56731); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.PIES, false); + assertEquals(500f, c2.volumenEnPiesCubicos(), 0.001f); } + @Test + public void testObtenerPesoKilos() { + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, false); + assertEquals(100f, c.obtenerPesoKilos(), 0.01f); + ISO6346 i2 = new ISO6346("DFT", 'J', 589012); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); + assertEquals(100f *0.453592, c2.obtenerPesoKilos(), 0.01f); + } + @Test public void testObtenerPesoLibras() { - Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); - assertEquals(100*2.20462f, c.obtenerPesoLibras(), 0.001f); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); + assertEquals(100f, c.obtenerPesoLibras(), 0.01f); + ISO6346 i2 = new ISO6346("DRT", 'U', 56731); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.PIES, false); + assertEquals(100f * 2.20462, c2.obtenerPesoLibras(), 0.01f); + } + + @Test + public void testCargaUtilContenedorKilos() { + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, false); + assertEquals(400f, c.cargaUtilContenedorKilos(), 0.01f); + ISO6346 i2 = new ISO6346("DRT", 'U', 56731); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.PIES, false); + assertEquals(400f *0.453592, c2.cargaUtilContenedorKilos(), 0.01f); + } + + @Test + public void testCargaUtilContenedorLibras() { + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); + assertEquals(400f, c.cargaUtilContenedorLibras(), 0.01f); + ISO6346 i2 = new ISO6346("DRT", 'U', 56731); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.PIES, false); + assertEquals(400f * 2.20462, c2.cargaUtilContenedorLibras(), 0.01f); } + @Test public void testAnyadirTrayecto() { - 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"); + Muelle m1 = new Muelle("01", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); origen.anyadirMuelle(m1); destino.anyadirMuelle(m2); - assertTrue(origen.comprobarMuelleEnPuerto(m1)); - assertTrue(destino.comprobarMuelleEnPuerto(m2)); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); 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); + Muelle m3 = new Muelle("02", new GPSCoordinate(13d,11d), estado.OPERATIVO, 2, 2); destino.anyadirMuelle(m3); - Fecha fFinal = new Fecha(1,12,2024); - Trayecto t2 = new Trayecto(m2,destino,fFin,m3,destino,fFinal); + Trayecto t2 = new Trayecto(m2,destino,fFin,m3,destino,fFin); c.anyadirTrayecto(t2); } - @Test(expected = IllegalArgumentException.class) + @Test (expected = IllegalArgumentException.class) public void testAnyadirTrayectoNulo() { - Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); 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); + @Test (expected = IllegalStateException.class) + public void testAnyadirTrayectoFechaInicialAnteriorALaFinalDelUltimo() { Puerto origen = new Puerto("ES" , "BAR"); Puerto destino = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("01", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); origen.anyadirMuelle(m1); destino.anyadirMuelle(m2); - assertTrue(origen.comprobarMuelleEnPuerto(m1)); - assertTrue(destino.comprobarMuelleEnPuerto(m2)); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); 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); + Muelle m3 = new Muelle("02", new GPSCoordinate(13d,11d), estado.OPERATIVO, 2, 2); 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); + Fecha fInicioT2 = new Fecha(29,11,2024); + Trayecto t2 = new Trayecto(m2,destino,fInicioT2,m3,destino,fFin); 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); + @Test (expected = IllegalStateException.class) + public void testAnyadirTrayectoPuertosDistintos() { Puerto origen = new Puerto("ES" , "BAR"); Puerto destino = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("01", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); origen.anyadirMuelle(m1); destino.anyadirMuelle(m2); - assertTrue(origen.comprobarMuelleEnPuerto(m1)); - assertTrue(destino.comprobarMuelleEnPuerto(m2)); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); 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); + Muelle m3 = new Muelle("02", new GPSCoordinate(13d,11d), estado.OPERATIVO, 2, 2); destino.anyadirMuelle(m3); - Fecha fFin2 = new Fecha(4,12,2024); - Trayecto t2 = new Trayecto(m2,origen,fFin,m3,destino,fFin2); + Trayecto t2 = new Trayecto(m2,origen,fFin,m3,destino,fFin); c.anyadirTrayecto(t2); } - @Test(expected = IllegalArgumentException.class) - public void testAnyadirTrayectoMuelleOrigenDistintoAlMuelleDestinoAnteriro() { - Contenedor c = new Contenedor("RTS", 'U', "056413", 100, 200, 1000, false, true); + @Test (expected = IllegalStateException.class) + public void testAnyadirTrayectoMuellesDistintos() { + Puerto origen = new Puerto("ES" , "BAR"); + Puerto destino = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("01", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); 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); + origen.anyadirMuelle(m1); + destino.anyadirMuelle(m2); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); + Trayecto t1 = new Trayecto(m1,origen,fInicio,m2,destino,fFin); + c.anyadirTrayecto(t1); + Muelle m3 = new Muelle("42", new GPSCoordinate(15d,15d), estado.OPERATIVO, 2, 2); + destino.anyadirMuelle(m3); + Trayecto t2 = new Trayecto(m3,destino,fFin,m2,destino,fFin); + c.anyadirTrayecto(t2); + } + + @Test + public void testPrecioTransporteTotalContenedor() { Puerto origen = new Puerto("ES" , "BAR"); Puerto destino = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("01", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("01", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); origen.anyadirMuelle(m1); destino.anyadirMuelle(m2); - assertTrue(origen.comprobarMuelleEnPuerto(m1)); - assertTrue(destino.comprobarMuelleEnPuerto(m2)); + ISO6346 i = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.TRANSITO, pesos.LIBRAS, volumenes.METROS, false); + assertEquals(0.0f, c.precioTransporteTotalContenedor(50f, 0.5f),0.01f); 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); + Muelle m3 = new Muelle("02", new GPSCoordinate(13d,11d), estado.OPERATIVO, 2, 2); 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); + Trayecto t2 = new Trayecto(m2,destino,fFin,m3,destino,fFin); c.anyadirTrayecto(t2); + assertEquals(1432.395f, c.precioTransporteTotalContenedor(50f, 0.5f), 0.01f); } } \ No newline at end of file diff --git a/uses/es/markse/ISO6346Test.java b/uses/es/markse/ISO6346Test.java new file mode 100644 index 0000000000000000000000000000000000000000..db0ee907697b7ed57cae33395f2f5f911e898840 --- /dev/null +++ b/uses/es/markse/ISO6346Test.java @@ -0,0 +1,61 @@ +/** + * Copyright Universidad de Valladolid 2024/2025 + */ +package es.markse; + +import static org.junit.Assert.*; +import org.junit.Test; + +/** + * Test para la clase ISO6346 + * @author javcalv + * @author victorm + */ +public class ISO6346Test { + + @Test + public final void testISO6346() { + ISO6346 codigo = new ISO6346("RTX", 'J', 893); + assertEquals("RTX", codigo.codigoDuenyo()); + assertEquals('J', codigo.equipamiento()); + assertEquals(893, codigo.numeroSerie()); + assertEquals("RTXJ0008931", codigo.codigoContenedor()); + } + + @Test + public final void testISO6346EquipamientoZ() { + ISO6346 codigo = new ISO6346("RTX", 'Z', 893); + assertEquals('Z', codigo.equipamiento()); + } + + @Test + public final void testISO6346EquipamientoU() { + ISO6346 codigo = new ISO6346("RTX", 'U', 893); + assertEquals('U', codigo.equipamiento()); + } + + @Test (expected = IllegalArgumentException.class) + public final void testISO6346CodigoNulo() { + new ISO6346(null, 'J', 893); + } + + @Test (expected = IllegalArgumentException.class) + public final void testISO6346CodigoInvalido() { + new ISO6346("r4", 'J', 893); + } + + @Test (expected = IllegalArgumentException.class) + public final void testISO6346EquipamientoInvalido() { + new ISO6346("r4", '4', 893); + } + + @Test (expected = IllegalArgumentException.class) + public final void testISO6346NumeroSerieMenor() { + new ISO6346("r4", '4', -405); + } + + @Test (expected = IllegalArgumentException.class) + public final void testISO6346NumeroSerieMayor() { + new ISO6346("r4", '4', 56789012); + } +} diff --git a/uses/es/markse/MuelleTest.java b/uses/es/markse/MuelleTest.java index 18cc2d328f9214a0e85133702e6277c42beb70f7..309b22f562068b8d0306fabf4f7bc1c06a016a53 100644 --- a/uses/es/markse/MuelleTest.java +++ b/uses/es/markse/MuelleTest.java @@ -5,7 +5,8 @@ package es.markse; import static org.junit.Assert.*; import org.junit.Test; - +import es.markse.Muelle.estado; +import es.markse.Contenedor.*; import es.uva.inf.poo.maps.GPSCoordinate; /** @@ -21,7 +22,7 @@ public class MuelleTest { @Test public void testMuelle() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 2, 2); assertEquals("01", m.getIdentificador()); assertEquals(cord, m.getGPSCoordinate()); assertTrue(m.estaOperativo()); @@ -31,81 +32,79 @@ public class MuelleTest { @Test(expected = IllegalArgumentException.class) public void testMuelleIdentificadorVacio() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - new Muelle(null, cord, true, 2,2); + new Muelle(null, cord, estado.OPERATIVO, 2, 2); } @Test(expected = IllegalArgumentException.class) public void testMuelleGPSVacio() { - new Muelle("04", null, true, 2,2); + new Muelle("01", null, estado.OPERATIVO, 2, 2); } @Test(expected = IllegalArgumentException.class) public void testMuelleIdentificadorInvalido() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - new Muelle("r3", cord, true, 2,2); + new Muelle("r3", cord, estado.OPERATIVO, 2, 2); } @Test(expected = IllegalArgumentException.class) - public void testMuelleIdentificadorInvalidoTamanyo() { + public void testMuelleIdentificadorPatronInvalido() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - new Muelle("r432432", cord, true, 2,2); + new Muelle("r432432", cord, estado.OPERATIVO, 2, 2); } @Test(expected = IllegalArgumentException.class) public void testMuellePlazasInvalida() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - new Muelle("12", cord, true, -3,2); + new Muelle("01", cord, estado.OPERATIVO, -2, 2); } @Test(expected = IllegalArgumentException.class) public void testMuelleAlturaInvalida() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - new Muelle("12", cord, true, 1,-2); + new Muelle("01", cord, estado.OPERATIVO, 2, -2); } - @Test public void testGetIdentificador() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 2, 2); assertEquals("01", m.getIdentificador()); } - @Test public void testEstaOperativo() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m1 = new Muelle("01", cord, true, 2,2); - Muelle m2 = new Muelle("02", cord, false, 2,2); + Muelle m1 = new Muelle("01", cord, estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("02", cord, estado.FUERA_DE_SERVICIO, 2, 2); assertTrue(m1.estaOperativo()); assertFalse(m2.estaOperativo()); } - + @Test public void testGetGPSCoordinate() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 2, 2); assertEquals(cord, m.getGPSCoordinate()); } - @Test public void testNumeroDePlazasTotales() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 2, 2); assertEquals(2,m.numeroDePlazasTotales()); } - @Test public void testPlazasVacias() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,1); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 2, 1); assertEquals(2, m.plazasVacias()); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c2 = new Contenedor("TRR", 'J', "056731", 100, 400, 500, false, true); - m.colocarContenedorEnPlaza(c, 0); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + m.colocarContenedorEnPlaza(c1, 0); assertEquals(1, m.plazasVacias()); m.colocarContenedorEnPlaza(c2, 1); assertEquals(0, m.plazasVacias()); @@ -115,31 +114,33 @@ public class MuelleTest { @Test public void testPlazasLlenas() { - Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,2); - p.anyadirMuelle(m); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); assertEquals(0, m.plazasLlenas()); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); + ISO6346 i = new ISO6346("ZRE", 'J' , 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 0); assertEquals(0, m.plazasLlenas()); - m.alternarTechoContenedor(c); - assertEquals(1, m.plazasLlenas()); + m.colocarContenedorEnPlaza(c2, 0); + assertEquals(1, m.plazasLlenas()); } @Test public void testPlazasSemillenas() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); assertEquals(0, m.plazasSemillenas()); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c2 = new Contenedor("TRR", 'J', "056731", 100, 400, 500, false, true); - m.colocarContenedorEnPlaza(c, 0); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + m.colocarContenedorEnPlaza(c1, 0); assertEquals(1, m.plazasSemillenas()); - m.alternarTechoContenedor(c); + c1.alternarTecho(); assertEquals(0, m.plazasSemillenas()); - m.alternarTechoContenedor(c); - assertEquals(1, m.plazasSemillenas()); + c1.alternarTecho(); m.colocarContenedorEnPlaza(c2, 0); assertEquals(0, m.plazasSemillenas()); } @@ -147,24 +148,31 @@ public class MuelleTest { @Test public void testPlazaActual() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 10,2); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); + ISO6346 i = new ISO6346("ZRE", 'J' , 56731); + Contenedor c = new Contenedor(i, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 4); assertEquals(4, m.plazaActual(c.getCodigo())); - assertEquals(-1, m.plazaActual("RUTJ0438521")); + } + + @Test + public void testPlazaActualCodigoNoEstaEnMuelle() { + GPSCoordinate cord = new GPSCoordinate(5d, 5d); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); + assertEquals(-1, m.plazaActual("RTTU8989890")); } @Test(expected = IllegalArgumentException.class) public void testPlazaActualCodigoInvalido() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 10,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); m.plazaActual("HOLA"); } @Test(expected = IllegalArgumentException.class) public void testPlazaActualCodigoNulo() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 10,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); m.plazaActual(null); } @@ -172,223 +180,196 @@ public class MuelleTest { @Test public void testNivelEnPlaza() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 10,2); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c2 = new Contenedor("ZEX", 'Z', "666731", 100, 400, 500, false, true); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 4); m.colocarContenedorEnPlaza(c2, 4); assertEquals(1, m.nivelEnPlaza(c.getCodigo())); assertEquals(2, m.nivelEnPlaza(c2.getCodigo())); + } + + @Test + public void testNivelEnPlazaContenedorNoPerteneceA() { + GPSCoordinate cord = new GPSCoordinate(5d, 5d); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); assertEquals(-1, m.nivelEnPlaza("RUTJ0438521")); } + @Test(expected = IllegalArgumentException.class) public void testNivelEnPlazaCodigoInvalido() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 10,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); m.nivelEnPlaza("HOLA"); } @Test(expected = IllegalArgumentException.class) public void testNivelEnPlazaCodigoNulo() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 10,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); m.nivelEnPlaza(null); } @Test public void testColocarContenedorEnPlaza() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,1); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c2 = new Contenedor("ZEX", 'Z', "666731", 100, 400, 500, false, true); - m.colocarContenedorEnPlaza(c, 0); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 10, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + m.colocarContenedorEnPlaza(c1, 0); m.colocarContenedorEnPlaza(c2, 1); } @Test(expected = IllegalArgumentException.class) public void testColocarContenedorEnPlazaContenedorVacio() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 2,1); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); m.colocarContenedorEnPlaza(null, 0); } @Test(expected = IllegalArgumentException.class) - public void testColocarContenedorEnPlazaFueraRango() { + public void testColocarContenedorEnPlazaFueraRangoArriba() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 2,1); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 13); } @Test(expected = IllegalArgumentException.class) public void testColocarContenedorEnPlazaFueraRangoAbajo() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 2,1); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, -2); } - @Test(expected = IllegalArgumentException.class) - public void testColocarContenedorYaApilado() { + @Test(expected = IllegalStateException.class) + public void testColocarContenedorMuelleFueraServicio() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 2,1); + Muelle m = new Muelle("01", cord, estado.FUERA_DE_SERVICIO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i1, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 0); - m.colocarContenedorEnPlaza(c, 1); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void testColocarContenedorEnTransito() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 2,1); - c.cambiarEstadoATransito(); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i1, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 0); } - @Test(expected = IllegalArgumentException.class) - public void testColocarContenedorEncimaDeUnoSinTecho() { + @Test(expected = IllegalStateException.class) + public void testColocarContenedorYaApilado() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, false); - Muelle m = new Muelle("01", cord, true, 1,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m.colocarContenedorEnPlaza(c, 0); - Contenedor c2 = new Contenedor("ZTG", 'J', "582940", 100, 400, 500, false, false); - m.colocarContenedorEnPlaza(c2, 0); + m.colocarContenedorEnPlaza(c, 1); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void testColocarContenedorEnPlazaLLena() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 1,1); - m.colocarContenedorEnPlaza(c, 0); - Contenedor c2 = new Contenedor("ZTG", 'J', "582940", 100, 400, 500, false, true); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 2, 1); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + m.colocarContenedorEnPlaza(c1, 0); m.colocarContenedorEnPlaza(c2, 0); } - @Test(expected = IllegalArgumentException.class) - public void testColocarContenedorEnDosMuelles() { + @Test(expected = IllegalStateException.class) + public void testColocarContenedorEncimaDeUnoSinTecho() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 1,1); - Muelle m2 = new Muelle("01", cord, true, 1,1); - m.colocarContenedorEnPlaza(c, 0); - m2.colocarContenedorEnPlaza(c, 0); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, false); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + m.colocarContenedorEnPlaza(c1, 0); + m.colocarContenedorEnPlaza(c2, 0); } - + @Test public void testSacarContenedorDePlaza() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 1,1); - m.colocarContenedorEnPlaza(c, 0); - m.sacarContenedorDePlaza(c); - } - - @Test(expected = IllegalArgumentException.class) - public void testSacarContenedorDePlazaQueNoEstaEnUltimoNivel() { - GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c2 = new Contenedor("RJF", 'Z', "401932", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 1,2); - m.colocarContenedorEnPlaza(c, 0); - m.colocarContenedorEnPlaza(c2, 0); - m.sacarContenedorDePlaza(c); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, false); + m.colocarContenedorEnPlaza(c1, 0); + assertEquals(1, m.plazasLlenas()); + m.sacarContenedorDePlaza(c1); + assertEquals(0, m.plazasLlenas()); } @Test(expected = IllegalArgumentException.class) public void testSacarContenedorDePlazaContenedorVacio() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,1); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); m.sacarContenedorDePlaza(null); } - @Test(expected = IllegalArgumentException.class) - public void testSacarContenedorDePlazaQueNoEstaApilado() { + @Test(expected = IllegalStateException.class) + public void testSacarContenedorEnTransito() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 1,1); - m.sacarContenedorDePlaza(c); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.TRANSITO, pesos.KILOS, volumenes.METROS, false); + m.sacarContenedorDePlaza(c1); } - @Test - public void testAlternarTechoContenedor() { + @Test(expected = IllegalStateException.class) + public void testSacarContenedorMuelleFueraServicio() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Muelle m = new Muelle("01", cord, true, 2,2); - m.colocarContenedorEnPlaza(c, 0); - m.alternarTechoContenedor(c); - Contenedor c2 = new Contenedor("XCD", 'J', "401941", 100, 400, 500, false, true); - Contenedor c3 = new Contenedor("RTR", 'J', "405012", 100, 400, 500, false, true); - m.colocarContenedorEnPlaza(c2, 1); - m.colocarContenedorEnPlaza(c3, 1); - m.alternarTechoContenedor(c3); - } - - @Test(expected = IllegalArgumentException.class) - public void testAlternarTechoContenedorVacio() { - GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,2); - m.alternarTechoContenedor(null); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, false); + m.colocarContenedorEnPlaza(c1, 0); + m.alternarOperativo(); + m.sacarContenedorDePlaza(c1); } - @Test(expected = IllegalArgumentException.class) - public void testAlternarTechoContenedorQueNoEsta() { + @Test(expected = IllegalStateException.class) + public void testSacarContenedorDePlazaQueNoEstaApilado() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,2); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - m.alternarTechoContenedor(c); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, false); + m.sacarContenedorDePlaza(c1); } - @Test(expected = IllegalArgumentException.class) - public void testAlternarTechoContenedorQueNoEstaEnUltimaPlaza() { + @Test(expected = IllegalStateException.class) + public void testSacarContenedorDePlazaQueNoEstaEnUltimoNivel() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,2); - Contenedor c = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c2 = new Contenedor("EWE", 'J', "456321", 100, 400, 500, false, true); - m.colocarContenedorEnPlaza(c, 0); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); + ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c2 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + m.colocarContenedorEnPlaza(c1, 0); m.colocarContenedorEnPlaza(c2, 0); - m.alternarTechoContenedor(c); + m.sacarContenedorDePlaza(c1); } @Test public void testAlternarOperativo() { GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,2); + Muelle m = new Muelle("01", cord, estado.OPERATIVO, 1, 2); m.alternarOperativo(); assertFalse(m.estaOperativo()); m.alternarOperativo(); assertTrue(m.estaOperativo()); } - - @Test - public void testGestionPlazasGeneral() { - GPSCoordinate cord = new GPSCoordinate(5d, 5d); - Muelle m = new Muelle("01", cord, true, 1,3); - Muelle m2 = new Muelle("01", cord, true, 1,2); - Contenedor c = new Contenedor("DFR", 'J', "056731", 100, 400, 500, false, false); - Contenedor c2 = new Contenedor("ZZE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c3 = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, false); - Contenedor c4 = new Contenedor("ZRR", 'J', "432422", 100, 400, 500, false, true); - m.colocarContenedorEnPlaza(c, 0); - assertEquals(0, m.plazasVacias(), m.plazasSemillenas()); - m.sacarContenedorDePlaza(c); - assertEquals(1, m.plazasVacias()); - assertEquals(0, m.plazasSemillenas()); - m2.colocarContenedorEnPlaza(c2, 0); - m2.colocarContenedorEnPlaza(c3, 0); - m2.sacarContenedorDePlaza(c3); - assertEquals(1, m2.plazasSemillenas()); - m2.sacarContenedorDePlaza(c2); - assertEquals(0, m2.plazasSemillenas(), m2.plazasLlenas()); - m.colocarContenedorEnPlaza(c2, 0); - m.colocarContenedorEnPlaza(c, 0); - assertEquals(0, m.plazasVacias(), m.plazasSemillenas()); - m.sacarContenedorDePlaza(c); - m.colocarContenedorEnPlaza(c4, 0); - assertEquals(1, m.plazasSemillenas()); - m.sacarContenedorDePlaza(c4); - } - } \ No newline at end of file diff --git a/uses/es/markse/PuertoTest.java b/uses/es/markse/PuertoTest.java index 6e87569f6bc3185b3516c6f257c9771c5bf63420..b20f2bb7a96a14a3544ecce62480029989416afe 100644 --- a/uses/es/markse/PuertoTest.java +++ b/uses/es/markse/PuertoTest.java @@ -1,13 +1,14 @@ /** * Copyright UVa 2024/2025 */ + package es.markse; import static org.junit.Assert.*; import org.junit.Test; - +import es.markse.Muelle.estado; +import es.markse.Contenedor.*; import es.uva.inf.poo.maps.GPSCoordinate; - /** * Test realizados para la clase Puerto * @author javcalv @@ -20,6 +21,7 @@ public class PuertoTest { Puerto p = new Puerto("ES","BAR"); assertEquals("ES", p.paisDelPuerto()); assertEquals("BAR", p.ciudadDelPuerto()); + assertEquals("ES-BAR", p.identificadorPuerto()); } @Test(expected = IllegalArgumentException.class) @@ -56,7 +58,7 @@ public class PuertoTest { public void testAnyadirMuelle() { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord = new GPSCoordinate(5d, 10d); - Muelle m = new Muelle("03", cord, true, 40, 5); + Muelle m = new Muelle("03", cord, estado.OPERATIVO, 40, 5); assertTrue(p.anyadirMuelle(m)); } @@ -68,23 +70,31 @@ public class PuertoTest { @Test - public void testAnyadirMuelleRepetido() { + public void testAnyadirMuelleIDRepetido() { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord1 = new GPSCoordinate(5d, 10d); GPSCoordinate cord2 = new GPSCoordinate(20d, -10d); - Muelle m = new Muelle("03", cord1, true, 40, 5); - Muelle mismoID = new Muelle("03", cord2, true, 40, 5); - Muelle mismaCoordenada = new Muelle("05", cord1, true, 40, 5); + Muelle m = new Muelle("03", cord1, estado.OPERATIVO, 40, 5); + Muelle mismoID = new Muelle("03", cord2, estado.OPERATIVO, 40, 5); p.anyadirMuelle(m); - assertFalse(p.anyadirMuelle(mismaCoordenada)); assertFalse(p.anyadirMuelle(mismoID)); } + @Test + public void testAnyadirMuelleCoordenadaRepetida() { + Puerto p = new Puerto("ES","BAR"); + GPSCoordinate cord = new GPSCoordinate(5d, 10d); + Muelle m = new Muelle("03", cord, estado.OPERATIVO, 40, 5); + Muelle mismaCoordenada = new Muelle("05", cord, estado.OPERATIVO, 40, 5); + p.anyadirMuelle(m); + assertFalse(p.anyadirMuelle(mismaCoordenada)); + } + @Test public void testEliminarMuelle() { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord = new GPSCoordinate(5d, 10d); - Muelle m = new Muelle("03", cord, true, 40, 5); + Muelle m = new Muelle("03", cord, estado.OPERATIVO, 40, 5); p.anyadirMuelle(m); assertTrue(p.eliminarMuelle("03")); } @@ -93,11 +103,20 @@ public class PuertoTest { public void testEliminarMuelleNulo() { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord = new GPSCoordinate(5d, 10d); - Muelle m = new Muelle("03", cord, true, 40, 5); + Muelle m = new Muelle("03", cord, estado.OPERATIVO, 40, 5); p.anyadirMuelle(m); p.eliminarMuelle(null); } + @Test(expected = IllegalArgumentException.class) + public void testEliminarMuelleVacio() { + Puerto p = new Puerto("ES","BAR"); + GPSCoordinate cord = new GPSCoordinate(5d, 10d); + Muelle m = new Muelle("03", cord, estado.OPERATIVO, 40, 5); + p.anyadirMuelle(m); + p.eliminarMuelle(""); + } + @Test public void testEliminarMuelleQueNoEstaEnPuerto() { Puerto p = new Puerto("ES","BAR"); @@ -109,13 +128,16 @@ public class PuertoTest { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord1 = new GPSCoordinate(5d, 10d); GPSCoordinate cord2 = new GPSCoordinate(20d, -10d); - Muelle m1 = new Muelle("01", cord1, true, 1, 1); - Muelle m2 = new Muelle("04", cord2, true, 2, 1); + Muelle m1 = new Muelle("01", cord1, estado.OPERATIVO, 1, 1); p.anyadirMuelle(m1); + Muelle m2 = new Muelle("04", cord2, estado.OPERATIVO, 2, 1); p.anyadirMuelle(m2); - Contenedor c11 = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c21 = new Contenedor("RTZ", 'Z', "569026", 100, 400, 500, false, true); - Contenedor c22 = new Contenedor("WCD", 'Z', "432012", 100, 400, 500, false, true); + ISO6346 i1 = new ISO6346("ZRE", 'J' , 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + ISO6346 i3 = new ISO6346("WCD", 'Z', 432012); + Contenedor c11 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c21 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c22 = new Contenedor(i3, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m1.colocarContenedorEnPlaza(c11, 0); m2.colocarContenedorEnPlaza(c21, 0); m2.colocarContenedorEnPlaza(c22, 1); @@ -127,12 +149,14 @@ public class PuertoTest { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord1 = new GPSCoordinate(5d, 10d); GPSCoordinate cord2 = new GPSCoordinate(20d, -10d); - Muelle m1 = new Muelle("01", cord1, true, 1, 1); - Muelle m2 = new Muelle("04", cord2, true, 2, 1); + Muelle m1 = new Muelle("01", cord1, estado.OPERATIVO, 1, 1); p.anyadirMuelle(m1); + Muelle m2 = new Muelle("04", cord2, estado.OPERATIVO, 2, 1); p.anyadirMuelle(m2); - Contenedor c11 = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); - Contenedor c21 = new Contenedor("RTZ", 'Z', "569026", 100, 400, 500, false, true); + ISO6346 i1 = new ISO6346("ZRE", 'J' , 56731); + ISO6346 i2 = new ISO6346("RTZ", 'Z', 569026); + Contenedor c11 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c21 = new Contenedor(i2, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m1.colocarContenedorEnPlaza(c11, 0); m2.colocarContenedorEnPlaza(c21, 0); assertFalse(p.comprobarSiEstaLleno()); @@ -143,42 +167,38 @@ public class PuertoTest { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord1 = new GPSCoordinate(5d, 10d); GPSCoordinate cord2 = new GPSCoordinate(20d, -10d); - Muelle m1 = new Muelle("01", cord1, false, 1, 1); - Muelle m2 = new Muelle("04", cord2, false, 2, 1); + Muelle m1 = new Muelle("01", cord1, estado.OPERATIVO, 1, 1); p.anyadirMuelle(m1); + Muelle m2 = new Muelle("04", cord2, estado.FUERA_DE_SERVICIO, 2, 1); p.anyadirMuelle(m2); - assertEquals(0, p.muellesOperativos().length); - m1.alternarOperativo(); - m2.alternarOperativo(); - Muelle[] muellesEsperados = {m1, m2}; + Muelle[] muellesEsperados = {m1}; assertArrayEquals(muellesEsperados, p.muellesOperativos()); } - @Test public void testMuellesConEspacio() { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord1 = new GPSCoordinate(5d, 10d); - Muelle m1 = new Muelle("01", cord1, true, 1, 1); + Muelle m1 = new Muelle("01", cord1, estado.OPERATIVO, 1, 1); p.anyadirMuelle(m1); Muelle[] muellesEsperados = {m1}; assertArrayEquals(muellesEsperados, p.muellesConEspacio()); - Contenedor c11 = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true); + ISO6346 i1 = new ISO6346("ZRE", 'J' , 56731); + Contenedor c11 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); m1.colocarContenedorEnPlaza(c11, 0); assertEquals(0, p.muellesConEspacio().length); } - @Test public void testMuellesCercanoAPunto() { Puerto p = new Puerto("ES","BAR"); GPSCoordinate cord1 = new GPSCoordinate(10d, 10d); GPSCoordinate cord2 = new GPSCoordinate(-10d, -10d); - Muelle m1 = new Muelle("01", cord1, true, 1, 1); - Muelle m2 = new Muelle("05", cord2, true, 2, 2); - GPSCoordinate puntoDado = new GPSCoordinate(15d , 15d); + Muelle m1 = new Muelle("01", cord1, estado.OPERATIVO, 1, 1); p.anyadirMuelle(m1); + Muelle m2 = new Muelle("04", cord2, estado.OPERATIVO, 2, 1); p.anyadirMuelle(m2); + GPSCoordinate puntoDado = new GPSCoordinate(15d , 15d); Muelle[] muelleCercanos = {m1}; assertArrayEquals(muelleCercanos, p.muellesCercanoAPunto(puntoDado)); puntoDado = new GPSCoordinate(0d , 0d); @@ -190,6 +210,5 @@ public class PuertoTest { public void testMuellesCercanoAPuntoVacio() { Puerto p = new Puerto("ES","BAR"); p.muellesCercanoAPunto(null); - } - + } } \ No newline at end of file diff --git a/uses/es/markse/TrayectoTest.java b/uses/es/markse/TrayectoTest.java index 2c0e2d2d6a70fceef1b8d18be890cfe2b295ed99..bd40ad44e4bee8d40ff92aa3ce7820e3f1aee470 100644 --- a/uses/es/markse/TrayectoTest.java +++ b/uses/es/markse/TrayectoTest.java @@ -1,23 +1,22 @@ package es.markse; import static org.junit.Assert.*; - import org.junit.Test; +import es.markse.Muelle.estado; +import es.markse.Trayecto.MuelleNoPerteneceAlPuertoException; import es.uva.inf.poo.maps.GPSCoordinate; public class TrayectoTest { @Test public void testTrayecto() { - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(5d,5d); - Muelle m1 = new Muelle ("01",c1,true,2,2); - Muelle m2 = new Muelle ("01",c1,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); assertEquals(m1,t.getMuelleOrigen()); assertEquals(p1,t.getPuertoOrigen()); @@ -27,302 +26,247 @@ public class TrayectoTest { assertEquals(f2,t.getFechaFinTrayecto()); } - @Test(expected = IllegalArgumentException.class) - public void testTrayectoFechaNull() { - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(5d,5d); - Muelle m1 = new Muelle ("01",c1,true,2,2); - Muelle m2 = new Muelle ("01",c1,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); - p1.anyadirMuelle(m1); + @Test (expected = IllegalArgumentException.class) + public void testTrayectoMuelleOrigenNulo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p2.anyadirMuelle(m2); - Fecha f2 = new Fecha(11,11,2024); - new Trayecto(m1,p1,null,m2,p2,f2); + new Trayecto(null,p1,f1,m2,p2,f2); } - @Test(expected = IllegalArgumentException.class) - public void testTrayectoMuelleNoPertenecePuerto() { - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(5d,5d); - Muelle m1 = new Muelle ("01",c1,true,2,2); - Muelle m2 = new Muelle ("01",c1,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + @Test (expected = IllegalArgumentException.class) + public void testTrayectoMuelleDestinoNulo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); + new Trayecto(m1,p1,f1,null,p2,f2); } - @Test(expected = IllegalArgumentException.class) - public void testTrayectoFechaInicioPosteriorAFin() { - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(5d,5d); - Muelle m1 = new Muelle ("01",c1,true,2,2); - Muelle m2 = new Muelle ("01",c1,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); - p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f2,m2,p2,f1); + @Test (expected = IllegalArgumentException.class) + public void testTrayectoPuertoOrigenNulo() { + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); + new Trayecto(m1,null,f1,m2,p2,f2); } - - @Test - public void testGetMuelleOrigen() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("AR","BUE"); - p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - assertEquals(m1,t.getMuelleOrigen()); + + @Test (expected = IllegalArgumentException.class) + public void testTrayectoPuertoDestinoNulo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); + new Trayecto(m1,p1,f1,m2,null,f2); } - - @Test - public void testGetMuelleDestino() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("AR","BUE"); - p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - assertEquals(m2,t.getMuelleDestino()); + + @Test (expected = IllegalArgumentException.class) + public void testTrayectoFechaOrigenNulo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f2 = new Fecha(30,11,2024); + new Trayecto(m1,p1,null,m2,p2,f2); } - - @Test - public void testGetPuertoOrigen() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("AR","BUE"); - p1.anyadirMuelle(m1); + + @Test (expected = IllegalArgumentException.class) + public void testTrayectoFechaFinNulo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + new Trayecto(m1,p1,f1,m2,p2,null); + } + + @Test (expected = IllegalStateException.class) + public void testTrayectoMuelleOrigenFueraDeServicio() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.FUERA_DE_SERVICIO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); + new Trayecto(m1,p1,f1,m2,p2,f2); + } + + @Test (expected = IllegalStateException.class) + public void testTrayectoMuelleDestinoFueraDeServicio() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.FUERA_DE_SERVICIO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); + new Trayecto(m1,p1,f1,m2,p2,f2); + } + + @Test (expected = MuelleNoPerteneceAlPuertoException.class) + public void testTrayectoMuelleOrigenNoEstaEnPuerto() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - assertEquals(p1,t.getPuertoOrigen()); + new Trayecto(m1,p1,f1,m2,p2,f2); } - - @Test - public void testGetPuertoDestino() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("AR","BUE"); + + @Test (expected = MuelleNoPerteneceAlPuertoException.class) + public void testTrayectoMuelleDestinoNoEstaEnPuerto() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - assertEquals(p2,t.getPuertoDestino()); + new Trayecto(m1,p1,f1,m2,p2,f2); } - - @Test - public void testGetFechaInicioTrayecto() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("AR","BUE"); + + @Test (expected = IllegalArgumentException.class) + public void testTrayectoMuellesIguales() { + Puerto p1 = new Puerto("ES" , "BAR"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - assertEquals(f1,t.getFechaInicioTrayecto()); + new Trayecto(m1,p1,f1,m1,p1,f2); } - + @Test - public void testGetFechaFinTrayecto() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("AR","BUE"); + public void testTrayectoMuellesIgualesPeroPuertosNo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("12", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - 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",c1,true,2,2); - Puerto p1 = new Puerto ("ES","PAL"); - Puerto p2 = new Puerto ("ES","PAL"); - p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); - Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - + new Trayecto(m1,p1,f1,m2,p2,f2); } - - - @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"); - p1.anyadirMuelle(m1); - p2.anyadirMuelle(m2); - 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"); + @Test (expected = IllegalArgumentException.class) + public void testFechaInicioPosteriorAFin() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = null; - new Trayecto(m1,p1,f1,m2,p2,f2); + new Trayecto(m1,p1,f2,m2,p2,f1); } @Test - public void testFechaFinTrayectoSuperior() { - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(5d,5d); - Muelle m1 = new Muelle ("01",c1,true,2,2); - Muelle m2 = new Muelle ("01",c1,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + public void testFechaFinTrayectoSuperiorTrue() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - assertFalse(t.FechaFinTrayectoSuperior(f1)); - Fecha f3 = new Fecha(13,11,2024); - assertTrue(t.FechaFinTrayectoSuperior(f3)); + Fecha fecha = new Fecha(03,12,2024); + assertTrue(t.FechaFinTrayectoSuperior(fecha)); } - @Test(expected = IllegalArgumentException.class) - public void testFechaFinTrayectoSuperiorNula() { - GPSCoordinate c1 = new GPSCoordinate(5d,5d); - GPSCoordinate c2 = new GPSCoordinate(5d,5d); - Muelle m1 = new Muelle ("01",c1,true,2,2); - Muelle m2 = new Muelle ("01",c1,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + @Test + public void testFechaFinTrayectoSuperiorFalse() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - t.FechaFinTrayectoSuperior(null); + assertFalse(t.FechaFinTrayectoSuperior(f1)); } - @Test - public void testDistanciaMillasMarinas() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + @Test (expected = IllegalArgumentException.class) + public void testFechaFinTrayectoSuperiorNula() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(-3d, 20d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - double v = 781.1062793857914; - assertEquals(v, t.distanciaMillasMarinas(), 0.001); + assertFalse(t.FechaFinTrayectoSuperior(null)); } - + @Test - public void testprecioTrayectoEurosBien() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + public void testPrecioTransporeEuros() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(0d, 0d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - t.precioTrayectoEnEuros(5,5); + assertEquals(1865.1090f, t.precioTrayectoEnEuros(50f, 1f), 0.01f); } - @Test(expected = IllegalArgumentException.class) - public void testprecioTrayectoEurosMalPrimero() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + + @Test (expected = IllegalArgumentException.class) + public void testPrecioTransporeEurosCosteDiarioNegativo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(0d, 0d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - t.precioTrayectoEnEuros(0,5); + t.precioTrayectoEnEuros(-5f, 1f); } - @Test(expected = IllegalArgumentException.class) - public void testprecioTrayectoEurosMalSegundo() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + + @Test (expected = IllegalArgumentException.class) + public void testPrecioTransporeEurosCosteMillaNegativo() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(0d, 0d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - t.precioTrayectoEnEuros(5,0); + t.precioTrayectoEnEuros(50f, -1f); } + @Test - public void testinforTrayecto() { - 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,true,2,2); - Puerto p1 = new Puerto ("ES","BAR"); - Puerto p2 = new Puerto ("AR","BUE"); + public void testInforTrayceto() { + Puerto p1 = new Puerto("ES" , "BAR"); + Puerto p2 = new Puerto("IT" , "NAP"); + Muelle m1 = new Muelle("12", new GPSCoordinate(0d, 0d), estado.OPERATIVO, 2, 2); + Muelle m2 = new Muelle("34", new GPSCoordinate(10d,10d), estado.OPERATIVO, 2, 2); + Fecha f1 = new Fecha (25,11,2024); + Fecha f2 = new Fecha(30,11,2024); p1.anyadirMuelle(m1); p2.anyadirMuelle(m2); - Fecha f1 = new Fecha (9,11,2024); - Fecha f2 = new Fecha(11,11,2024); Trayecto t = new Trayecto(m1,p1,f1,m2,p2,f2); - t.inforTrayecto(); + String str = t.inforTrayecto(); + assertEquals(str, t.inforTrayecto()); } } \ No newline at end of file