1 17 18 package org.sablecc.sablecc.automaton; 19 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertTrue; 22 import static org.junit.Assert.fail; 23 24 import org.junit.Before; 25 import org.junit.Test; 26 import org.sablecc.sablecc.alphabet.Interval; 27 import org.sablecc.sablecc.alphabet.Realms; 28 import org.sablecc.sablecc.alphabet.Symbol; 29 import org.sablecc.sablecc.exception.InternalException; 30 31 public class MinimalDfaStateTest { 32 33 MinimalDfaState<Integer > minimalDfaStartState; 34 35 MinimalDfa<Integer > minimalDfa; 36 37 Dfa<Integer > dfa; 38 39 Symbol<Integer > symbol; 40 41 Interval<Integer > interval; 42 43 @SuppressWarnings ("unchecked") 44 @Before 45 public void setUp() 46 throws Exception { 47 48 this.interval = Realms.getInteger().createInterval(50); 49 50 this.symbol = new Symbol(this.interval); 51 52 this.dfa = new Dfa<Integer >(new Nfa<Integer >(this.interval).oneOrMore()); 53 54 this.minimalDfa = new MinimalDfa<Integer >(this.dfa); 55 56 this.minimalDfaStartState = this.minimalDfa.getStartState(); 57 } 58 59 @SuppressWarnings ("unused") 60 @Test 61 public void testMinimalDfaState() { 62 63 MinimalDfa<Integer > nullMinimalDfa = null; 65 try { 66 MinimalDfaState<Integer > minimalDfaState = new MinimalDfaState<Integer >( 67 nullMinimalDfa); 68 fail("minimalDfa may not be null"); 69 } 70 catch (InternalException e) { 71 } 73 74 assertEquals("the state dont have the correct minimalDfa", 76 this.minimalDfa, this.minimalDfaStartState.getMinimalDfa()); 77 assertTrue( 78 "from the startState, the correct symbol should lead to an acceptionState", 79 this.minimalDfaStartState.getTarget(this.symbol) == this.minimalDfa 80 .getAcceptStates().first()); 81 } 82 83 @Test 84 public void testGetTarget() { 85 86 Symbol<Integer > nullSymbol = null; 88 try { 89 this.minimalDfaStartState.getTarget(nullSymbol); 90 fail("symbol may not be null"); 91 } 92 catch (InternalException e) { 93 } 95 96 Symbol<Integer > newSymbol = new Symbol<Integer >(Realms.getInteger() 98 .createInterval(999)); 99 try { 100 this.minimalDfaStartState.getTarget(newSymbol); 101 fail("invalid symbol"); 102 } 103 catch (InternalException e) { 104 } 106 } 107 108 @Test 109 public void testEqualsObject() { 110 111 assertTrue("a minimalState should be equals to himself", 112 this.minimalDfaStartState.equals(this.minimalDfaStartState)); 113 114 assertTrue("the two minimalState should be equals", 115 this.minimalDfaStartState.equals(this.minimalDfa 116 .getStartState())); 117 } 118 119 @Test 120 public void testCompareTo() { 121 122 MinimalDfaState<Integer > lowerMinimalState = this.minimalDfa 124 .getStates().first(); 125 assertTrue( 126 "minimalDfaStartState should be greater than lowerMinimalState", 127 this.minimalDfaStartState.compareTo(lowerMinimalState) > 0); 128 129 assertTrue("the two minimalState should be equals", 131 this.minimalDfaStartState.compareTo(this.minimalDfa 132 .getStartState()) == 0); 133 134 MinimalDfaState<Integer > greaterMinimalState = this.minimalDfa 136 .getStates().last(); 137 assertTrue( 138 "minimalDfaStartState should be lower than greaterMinimalState", 139 this.minimalDfaStartState.compareTo(greaterMinimalState) < 0); 140 } 141 142 @Test 143 public void testAddTransition() { 144 145 try { 147 this.minimalDfaStartState.addTransition(this.symbol, 148 this.minimalDfaStartState); 149 fail("a stable state may not be modified"); 150 } 151 catch (InternalException e) { 152 } 154 } 155 156 @Test 157 public void testStabilize() { 158 159 try { 161 this.minimalDfaStartState.stabilize(); 162 fail("the minimalState is already stable"); 163 } 164 catch (InternalException e) { 165 } 167 } 168 169 } 170 | Popular Tags |