Skip to content
Snippets Groups Projects

DATASET_2_clasificacion_Entrenar_ResNet50.ipynb

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ContenedorTest.java 10.36 KiB
    /**
     * Copyright UVa 2024/2025
     */
    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;
    
    /**
     * Implementacon de los Test para la clase Contenedor
     * @author victorm
     * @author javcalv
     */
    public class ContenedorTest {
    	
    	@Test
    	public void testContenedor() {
    		ISO6346 i1 = new ISO6346("ZRE", 'J', 56731);
    		Contenedor c1 = new Estandar(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 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 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 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() {
    		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() {
    		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.contenedorEnTransito());
    	}
    	
    	@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() {
    		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() {
    		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() {
    		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);
    		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(13d,11d), estado.OPERATIVO, 2, 2);
    		destino.anyadirMuelle(m3);
    		Trayecto t2 = new Trayecto(m2,destino,fFin,m3,destino,fFin);
    		c.anyadirTrayecto(t2);
    	}
    	
    	@Test (expected = IllegalArgumentException.class)
    	public void testAnyadirTrayectoNulo() {
    		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 = 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);
    		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(13d,11d), estado.OPERATIVO, 2, 2);
    		destino.anyadirMuelle(m3);
    		Fecha fInicioT2 = new Fecha(29,11,2024);
    		Trayecto t2 = new Trayecto(m2,destino,fInicioT2,m3,destino,fFin);
    		c.anyadirTrayecto(t2);
    	}
    	
    	@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);
    		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(13d,11d), estado.OPERATIVO, 2, 2);
    		destino.anyadirMuelle(m3);
    		Trayecto t2 = new Trayecto(m2,origen,fFin,m3,destino,fFin);
    		c.anyadirTrayecto(t2);
    	}
    	
    	@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);
    		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);
    		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(13d,11d), estado.OPERATIVO, 2, 2);
    		destino.anyadirMuelle(m3);
    		Trayecto t2 = new Trayecto(m2,destino,fFin,m3,destino,fFin);
    		c.anyadirTrayecto(t2);
    		assertEquals(1432.395f, c.precioTransporteTotalContenedor(50f, 0.5f), 0.01f);
    	}
    	
    }