package ch.epfl.isochrone.timetable;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.junit.Ignore;
import org.junit.Test;

import ch.epfl.isochrone.geo.PointWGS84;
import ch.epfl.isochrone.timetable.Date.DayOfWeek;
import ch.epfl.isochrone.timetable.Date.Month;

public class TestTimeTable {
    // Le "test" suivant n'en est pas un à proprement parler, raison pour
    // laquelle il est ignoré (annotation @Ignore). Son seul but est de garantir
    // que les noms des classes et méthodes sont corrects.
    @Test
    @Ignore
    public void namesAreOk() {
        TimeTable t = new TimeTable(Collections.<Stop> emptySet(),
                Collections.<Service> emptySet());
        t.stops();
        t.servicesForDate(new Date(1, Month.JANUARY, 2000));

        TimeTable.Builder b = new TimeTable.Builder();
        b.addStop(new Stop("s", new PointWGS84(0, 0)));
        Date d = new Date(1, Month.APRIL, 2000);
        b.addService(new Service("s", d, d, Collections.<DayOfWeek> emptySet(),
                Collections.<Date> emptySet(), Collections.<Date> emptySet()));
        b.build();
    }

    @Test
    public void immu() {
        Date d = new Date(1, Month.APRIL, 2000);

        Stop s = new Stop("bonjour", new PointWGS84(1.0, 1.0));
        Set<Date.DayOfWeek> dOW = new HashSet<Date.DayOfWeek>();
        dOW.add(d.dayOfWeek());
        Service serv = new Service("s", d, d, dOW,
                Collections.<Date> emptySet(), Collections.<Date> emptySet());
        Set<Stop> stops = new HashSet<Stop>();
        Set<Service> services = new HashSet<Service>();

        stops.add(s);
        services.add(serv);

        TimeTable t = new TimeTable(stops, services);

        stops.clear();
        services.clear();

        assertTrue(!t.stops().isEmpty());
        assertTrue(!t.servicesForDate(d).isEmpty());
    }

    @Test
    public void stopsAreTheSame() {
        Date d = new Date(1, Month.APRIL, 2000);

        Stop s = new Stop("bonjour", new PointWGS84(1.0, 1.0));
        Set<Date.DayOfWeek> dOW = new HashSet<Date.DayOfWeek>();
        dOW.add(d.dayOfWeek());
        Service serv = new Service("s", d, d, dOW,
                Collections.<Date> emptySet(), Collections.<Date> emptySet());
        Set<Stop> stops = new HashSet<Stop>();
        Set<Service> services = new HashSet<Service>();

        stops.add(s);
        services.add(serv);

        TimeTable t = new TimeTable(stops, services);

        assertEquals(t.stops(), stops);

    }

    @Test
    public void servicesAreTheSame() {
        Date d = new Date(1, Month.APRIL, 2000);

        Stop s = new Stop("bonjour", new PointWGS84(1.0, 1.0));
        Set<Date.DayOfWeek> dOW = new HashSet<Date.DayOfWeek>();
        dOW.add(d.dayOfWeek());
        Service serv = new Service("s", d, d, dOW,
                Collections.<Date> emptySet(), Collections.<Date> emptySet());
        Set<Stop> stops = new HashSet<Stop>();
        Set<Service> services = new HashSet<Service>();

        stops.add(s);
        services.add(serv);

        TimeTable t = new TimeTable(stops, services);

        assertEquals(t.servicesForDate(d), services);

    }

}
