package ru.dyatel.tsuschedule.parsing;

import org.junit.BeforeClass;
import org.junit.Test;
import ru.dyatel.tsuschedule.parsing.util.Filter;
import ru.dyatel.tsuschedule.parsing.util.IterableFilter;

import java.util.Set;

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

public class ParserTest {

    private Filter<Lesson> oddParity = new Filter<Lesson>() {
        @Override
        public boolean accept(Lesson obj) {
            return obj.getParity().equals(Parity.ODD) || obj.getParity().equals(Parity.BOTH);
        }
    };
    private Filter<Lesson> firstSubgroup = new Filter<Lesson>() {
        @Override
        public boolean accept(Lesson obj) {
            return obj.getSubgroup() == 0 || obj.getSubgroup() == 1;
        }
    };

    private static Set<Lesson> lessons;

    @BeforeClass
    public static void setup() throws Exception {
        lessons = Parser.getLessons("221251");
    }

    @Test
    public void testGetLessonsMonday() throws Exception {
        IterableFilter<Lesson> filter = new IterableFilter<Lesson>();
        filter.apply(oddParity);
        filter.apply(new Filter<Lesson>() {
            @Override
            public boolean accept(Lesson obj) {
                return obj.getWeekday().equals("");
            }
        });
        filter.apply(firstSubgroup);

        Set<Lesson> result = filter.filter(lessons);
        assertEquals(3, result.size());
        assertTrue(containsDiscipline(result, ":"));
        assertTrue(containsDiscipline(result, ":"));
        assertTrue(containsDiscipline(result, ": "));
    }

    @Test
    public void testGetLessonsTuesday() throws Exception {
        IterableFilter<Lesson> filter = new IterableFilter<Lesson>();
        filter.apply(oddParity);
        filter.apply(new Filter<Lesson>() {
            @Override
            public boolean accept(Lesson obj) {
                return obj.getWeekday().equals("");
            }
        });
        filter.apply(firstSubgroup);

        Set<Lesson> result = filter.filter(lessons);
        assertEquals(3, result.size());
        assertTrue(containsDiscipline(result, " "));
        assertTrue(containsDiscipline(result, ": "));
        assertTrue(containsDiscipline(result, ":   "));
    }

    private boolean containsDiscipline(Set<Lesson> lessons, String discipline) {
        for (Lesson l : lessons) {
            if (l.getDiscipline().equals(discipline)) return true;
        }
        return false;
    }

}
@@ -334,16 +334,253 @@
 Test %7B%0A%0A
+    private Filter%3CLesson%3E evenParity = new Filter%3CLesson%3E() %7B%0A        @Override%0A        public boolean accept(Lesson obj) %7B%0A            return obj.getParity().equals(Parity.EVEN) %7C%7C obj.getParity().equals(Parity.BOTH);%0A        %7D%0A    %7D;%0A
     priv
@@ -2505,24 +2505,1902 @@
 %22));%0A    %7D%0A%0A
+    @Test%0A    public void testGetLessonsFridayEven() throws Exception %7B%0A        IterableFilter%3CLesson%3E filter = new IterableFilter%3CLesson%3E();%0A        filter.apply(evenParity);%0A        filter.apply(new Filter%3CLesson%3E() %7B%0A            @Override%0A            public boolean accept(Lesson obj) %7B%0A                return obj.getWeekday().equals(%22%22);%0A            %7D%0A        %7D);%0A        filter.apply(firstSubgroup);%0A%0A        Set%3CLesson%3E result = filter.filter(lessons);%0A        assertEquals(4, result.size());%0A        assertTrue(containsDiscipline(result, %22: %22));%0A        assertTrue(containsDiscipline(result, %22:   %22));%0A        Lesson lab = null;%0A        for (Lesson l : result) %7B%0A            if (l.getDiscipline().equals(%22:   %22)) %7B%0A                lab = l;%0A                break;%0A            %7D%0A        %7D%0A        result.remove(lab);%0A        assertTrue(containsDiscipline(result, %22:   %22));%0A        assertTrue(containsDiscipline(result, %22:   %22));%0A    %7D%0A%0A    @Test%0A    public void testGetLessonsFridayOdd() throws Exception %7B%0A        IterableFilter%3CLesson%3E filter = new IterableFilter%3CLesson%3E();%0A        filter.apply(oddParity);%0A        filter.apply(new Filter%3CLesson%3E() %7B%0A            @Override%0A            public boolean accept(Lesson obj) %7B%0A                return obj.getWeekday().equals(%22%22);%0A            %7D%0A        %7D);%0A        filter.apply(firstSubgroup);%0A%0A        Set%3CLesson%3E result = filter.filter(lessons);%0A        assertEquals(4, result.size());%0A        assertTrue(containsDiscipline(result, %22: %22));%0A        assertTrue(containsDiscipline(result, %22:   %22));%0A        Lesson lab = null;%0A        for (Lesson l : result) %7B%0A            if (l.getDiscipline().equals(%22:   %22)) %7B%0A                lab = l;%0A                break;%0A            %7D%0A        %7D%0A        result.remove(lab);%0A        assertTrue(containsDiscipline(result, %22:   %22));%0A        assertTrue(containsDiscipline(result, %22: %22));%0A    %7D%0A%0A
     private 

Add more tests