Skip to content
Snippets Groups Projects
TestVoli.java 4.34 KiB
import it.uniupo.graphLib.DirectedGraph;
import it.uniupo.graphLib.Edge;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestVoli {

    @Test
    public void testTempo() {
        DirectedGraph graph = new DirectedGraph("3;0 1 3;0 2 6;1 2 1");
        Voli testVoli = new Voli(graph);
        int tempo = testVoli.tempo(0, 2);
        assertEquals(6, tempo);

        graph = new DirectedGraph("3;0 1 3");
        testVoli = new Voli(graph);
        tempo = testVoli.tempo(0, 2);
        assertEquals(-1, tempo);
    }

    @Test
    public void testTempoExc1() {
        DirectedGraph graph = new DirectedGraph("3;0 1 3;0 2 6;1 2 1");
        Voli testVoli = new Voli(graph);
        Assertions.assertThrows(java.lang.IllegalArgumentException.class, () -> {
            testVoli.tempo(-1, 2);
        });
    }

    @Test
    public void testTempoExc2() {
        DirectedGraph graph = new DirectedGraph("3;0 1 3;0 2 6;1 2 1");
        Voli testVoli = new Voli(graph);
        Assertions.assertThrows(java.lang.IllegalArgumentException.class, () -> {
            testVoli.tempo(0, 3);
        });
    }

    @Test
    public void testScali() {
        DirectedGraph graph = new DirectedGraph("3;0 1 3;0 2 6;1 2 1");
        Voli testVoli = new Voli(graph);
        int scali = testVoli.scali(0, 2);
        assertEquals(0, scali);

        graph = new DirectedGraph("3;0 1 3");
        testVoli = new Voli(graph);
        scali = testVoli.scali(0, 2);
        assertEquals(-1, scali);

        testVoli = new Voli(new DirectedGraph("5;0 1 1;1 2 1;2 3 1;0 4 15;4 3 2"));
        assertEquals(1, testVoli.scali(0, 3));
    }

    @Test
    public void testScaliExc() {
        DirectedGraph graph = new DirectedGraph("3;0 1 3;0 2 6;1 2 1");
        Voli testVoli = new Voli(graph);
        Assertions.assertThrows(java.lang.IllegalArgumentException.class, () -> {
            testVoli.scali(-1, 2);
        });
    }

    @Test
    public void testTempoMinimo() {
        DirectedGraph graph = new DirectedGraph("3;0 1 3;0 2 6;1 2 1");