KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > automaton > StateMatcherTest


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Raymond Audet <raymond.audet@gmail.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.sablecc.sablecc.automaton;
19
20 import static org.junit.Assert.fail;
21
22 import java.util.SortedSet JavaDoc;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.sablecc.sablecc.exception.InternalException;
27
28 public class StateMatcherTest {
29
30     StateMatcher<Integer JavaDoc> stateMatcher;
31
32     Dfa<Integer JavaDoc> dfa;
33
34     Nfa<Integer JavaDoc> nfa;
35
36     @Before
37     public void setUp()
38             throws Exception JavaDoc {
39
40         this.nfa = new Nfa<Integer JavaDoc>();
41
42         this.dfa = new Dfa<Integer JavaDoc>(this.nfa);
43
44         this.stateMatcher = new StateMatcher<Integer JavaDoc>(this.dfa, this.nfa);
45     }
46
47     @Test
48     public void testStateMatcher() {
49
50         // Case with null dfa
51
Dfa<Integer JavaDoc> nullDfa = null;
52         try {
53             this.stateMatcher = new StateMatcher<Integer JavaDoc>(nullDfa, this.nfa);
54             fail("dfa may not be null");
55         }
56         catch (InternalException e) {
57             // Expected
58
}
59         // Case with null nfa;
60
Nfa<Integer JavaDoc> nullNfa = null;
61         try {
62             this.stateMatcher = new StateMatcher<Integer JavaDoc>(this.dfa, nullNfa);
63             fail("nfa may not be null");
64         }
65         catch (InternalException e) {
66             // Expected
67
}
68     }
69
70     @Test
71     public void testGetDfaState() {
72
73         // Case with null nfaStates
74
SortedSet JavaDoc<NfaState<Integer JavaDoc>> nfaStates = null;
75         try {
76             this.stateMatcher.getDfaState(nfaStates);
77             fail("nfaStates may not be null");
78         }
79         catch (InternalException e) {
80             // Expected
81
}
82
83     }
84
85     @Test
86     public void testGetNfaStates() {
87
88         // Case with null dfaState
89
DfaState<Integer JavaDoc> nullState = null;
90         try {
91             this.stateMatcher.getNfaStates(nullState);
92             fail("dfaState may not be null");
93         }
94         catch (InternalException e) {
95             // Expected
96
}
97
98     }
99
100     @Test
101     public void testMatch() {
102
103         // Case with null dfaState
104
DfaState<Integer JavaDoc> nullDfaState = null;
105         try {
106             this.stateMatcher.match(nullDfaState, this.nfa.getAcceptState());
107             fail("dfaState may not be null");
108         }
109         catch (InternalException e) {
110             // Expected
111
}
112
113         // Case with null nfaState
114
NfaState<Integer JavaDoc> nullNfaState = null;
115         try {
116             this.stateMatcher.match(this.dfa.getStartState(), nullNfaState);
117             fail("nfaState may not be null");
118         }
119         catch (InternalException e) {
120             // Expected
121
}
122     }
123
124 }
125
Popular Tags