<commit_before><commit_msg>Add some basic tests for epsilon elimination.<commit_after>package rationals.transformations;

import java.util.Arrays;

import org.junit.Test;

import junit.framework.TestCase;
import rationals.Automaton;
import rationals.State;
import rationals.Transition;
import rationals.TransitionBuilder;
import rationals.properties.ContainsEpsilon;

public class EpsilonTransitionRemoverTest extends TestCase {

    private Automaton<String, Transition<String>, TransitionBuilder<String>> automaton;

    protected void setUp() throws Exception {
        super.setUp();
        automaton = new Automaton<>();
        State s1 = automaton.addState(true, true);
        State s2 = automaton.addState(false, false);
        State s3 = automaton.addState(false, true);
        State e1 = automaton.addState(false, false);
        State e2 = automaton.addState(false, false);
        State e3 = automaton.addState(false, false);
        String epsilon = null;
        automaton.addTransition(new Transition<>(e1, "c", e1));
        automaton.addTransition(new Transition<>(s1, epsilon, e1));
        automaton.addTransition(new Transition<>(e1, epsilon, s1));
        automaton.addTransition(new Transition<>(s1, "a", s2));
        automaton.addTransition(new Transition<>(s2, epsilon, e2));
        automaton.addTransition(new Transition<>(e2, epsilon, e3));
        automaton.addTransition(new Transition<>(e3, "b", s3));
        automaton.addTransition(new Transition<>(s3, "a", s2));
        automaton.addTransition(new Transition<>(e2, "b", s1));
    }

    public EpsilonTransitionRemoverTest(String arg0) {
        super(arg0);
    }

    @Test
    public void test1() {
    	EpsilonTransitionRemover<String, Transition<String>, TransitionBuilder<String>> norm = new EpsilonTransitionRemover<>();
        Automaton<String, Transition<String>, TransitionBuilder<String>> b = norm.transform(automaton);
        assertTrue(new ContainsEpsilon<String, Transition<String>, TransitionBuilder<String>>().test(b));
        String[] word = new String[] { "a", "b", "a", "b" };
        assertTrue(b.accept(Arrays.asList(word)));
    }

    @Test
    public void test2() {
    	EpsilonTransitionRemover<String, Transition<String>, TransitionBuilder<String>> norm = new EpsilonTransitionRemover<>();
        Automaton<String, Transition<String>, TransitionBuilder<String>> b = norm.transform(automaton);
        assertTrue(new ContainsEpsilon<String, Transition<String>, TransitionBuilder<String>>().test(b));
        String[] word3 = new String[] { };
        assertTrue(b.accept(Arrays.asList(word3)));
    }
    
    @Test
    public void test3() {
    	EpsilonTransitionRemover<String, Transition<String>, TransitionBuilder<String>> norm = new EpsilonTransitionRemover<>();
        Automaton<String, Transition<String>, TransitionBuilder<String>> b = norm.transform(automaton);
        assertTrue(new ContainsEpsilon<String, Transition<String>, TransitionBuilder<String>>().test(b));
        String[] word2 = new String[] { "c","c","a", "b", "a", "b", "a", "b" };
        assertTrue(b.accept(Arrays.asList(word2)));
    }

    @Test
    public void test4() {
    	EpsilonTransitionRemover<String, Transition<String>, TransitionBuilder<String>> norm = new EpsilonTransitionRemover<>();
        Automaton<String, Transition<String>, TransitionBuilder<String>> b = norm.transform(automaton);
        assertTrue(new ContainsEpsilon<String, Transition<String>, TransitionBuilder<String>>().test(b));
        String[] word1 = new String[] { "a", "b", "a", "b", "a" };
        assertTrue(!b.accept(Arrays.asList(word1)));
    }

    @Test
    public void test5() {
    	EpsilonTransitionRemover<String, Transition<String>, TransitionBuilder<String>> norm = new EpsilonTransitionRemover<>();
        Automaton<String, Transition<String>, TransitionBuilder<String>> b = norm.transform(automaton);
        assertTrue(new ContainsEpsilon<String, Transition<String>, TransitionBuilder<String>>().test(b));
        String[] word2 = new String[] { "c","c","c"};
        assertTrue(b.accept(Arrays.asList(word2)));
    }
}
{'fraction_non_alphanumeric': 0.14105365379946588, 'fraction_numerical': 0.009468317552804079, 'mean_word_length': 4.302445302445302, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3638059', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1167, 'n_words': 246}