package pt.up.fe.comp.fsa;

import junit.framework.Assert;
import org.junit.Test;
import static junit.framework.TestCase.assertTrue;

import java.util.Arrays;
import java.util.LinkedHashSet;

import static junit.framework.TestCase.fail;

public class FSAUnreachableAndUseless {

    @Test
    public void TestRemoveUnreachable() {
        try {
            FSA newAut = new FSA("aut", "S", new LinkedHashSet<String>());
            newAut.addEdge("S", 'a', "A");
            newAut.addEdge("A", 'a', "S");
            newAut.addEdge("A", 'b', "B");
            newAut.addEdge("B", 'b', "A");
            newAut.addNode("C");
            newAut.addEdge("C", 'a', "A");
            newAut.addEdge("C", 'b', "B");

            newAut.removeUnreachableStates();

            assertTrue(newAut.getNodes().containsAll(Arrays.asList("S", "A", "B")));
            assertTrue(newAut.getNodes().size() == 3);

        } catch (FSAException e) {
            e.printStackTrace();
            fail();
        }
    }

    @Test
    public void TestRemoveUseless() {
        try {
            FSA newAut = new FSA("aut", "S", new LinkedHashSet<String>());
            newAut.addEdge("S", 'a', "A");
            newAut.addEdge("A", 'a', "S");
            newAut.addEdge("A", 'b', "B");
            newAut.addEdge("A", 'a', "C");
            newAut.addEdge("B", 'b', "C");
            newAut.addFinalState("A");

            newAut.removeUselessStates();

            assertTrue(newAut.getNodes().containsAll(Arrays.asList("S", "A")));
            assertTrue(newAut.getNodes().size() == 2);
            assertTrue(newAut.getNodeEdges("A").size() == 1);
            assertTrue(newAut.getNodeEdges("S").size() == 1);

        } catch (FSAException e) {
            e.printStackTrace();
            fail();
        }
    }
}
@@ -25,39 +25,8 @@
 a;%0A%0A
-import junit.framework.Assert;%0A
 impo
@@ -44,16 +44,16 @@
 t.Test;%0A
+
 import s
@@ -94,16 +94,68 @@
 ertTrue;
+%0Aimport static junit.framework.TestCase.assertFalse;
 %0A%0Aimport
@@ -252,16 +252,16 @@
 .fail;%0A%0A
-
 public c
@@ -293,16 +293,842 @@
 less %7B%0A%0A
+    @Test%0A    public void TestEmptyLanguage() %7B%0A        try %7B%0A            FSA newAut = new FSA(%22aut%22, %22S%22, new LinkedHashSet%3CString%3E());%0A            newAut.addEdge(%22S%22, 'a', %22A%22);%0A            newAut.addEdge(%22A%22, 'a', %22S%22);%0A            newAut.addEdge(%22A%22, 'b', %22B%22);%0A            newAut.addEdge(%22B%22, 'b', %22A%22);%0A            newAut.addNode(%22C%22);%0A            newAut.addEdge(%22C%22, 'a', %22A%22);%0A            newAut.addEdge(%22C%22, 'b', %22B%22);%0A%0A            newAut.addFinalState(%22C%22);%0A%0A            assertTrue(newAut.doesNotAcceptAnything());%0A%0A            newAut.addFinalState(%22B%22);%0A            assertFalse(newAut.doesNotAcceptAnything());%0A            %0A            assertTrue(newAut.getFinalStates().containsAll(Arrays.asList(%22B%22,%22C%22)));%0A%0A        %7D catch (FSAException e) %7B%0A            e.printStackTrace();%0A            fail();%0A        %7D%0A    %7D%0A%0A
     @Tes

Add test for empty language check.