KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.exception.InternalException;
27
28 public class DfaTest {
29
30     Dfa<Integer JavaDoc> dfa;
31
32     Nfa<Integer JavaDoc> nfa;
33
34     @Before
35     public void setUp()
36             throws Exception JavaDoc {
37
38         this.nfa = new Nfa<Integer JavaDoc>();
39         this.dfa = new Dfa<Integer JavaDoc>(this.nfa);
40     }
41
42     @SuppressWarnings JavaDoc("unused")
43     @Test
44     public void testDfa() {
45
46         // Case with null Nfa
47
Nfa<Integer JavaDoc> nullNfa = null;
48
49         try {
50             Dfa<Integer JavaDoc> dfa = new Dfa<Integer JavaDoc>(nullNfa);
51         }
52         catch (InternalException e) {
53             // Expected
54
}
55
56         // Typical Case
57
assertTrue("the startState should be an acceptationState", this.dfa
58                 .getAcceptStates().first() == this.dfa.getStartState());
59         assertEquals("there should only be one acceptationState", 1, this.dfa
60                 .getAcceptStates().size());
61     }
62
63     @Test
64     public void testShortest() {
65
66         // Case with null Nfa
67
Nfa<Integer JavaDoc> nullNfa = null;
68
69         try {
70             this.dfa = Dfa.shortest(nullNfa);
71             fail("nfa may not be null");
72         }
73         catch (InternalException e) {
74             // Expected
75
}
76
77     }
78
79     @Test
80     public void testDifference() {
81
82         // Case with null Nfa
83
Nfa<Integer JavaDoc> nullNfa = null;
84
85         try {
86             this.dfa = Dfa.difference(nullNfa, this.nfa);
87             fail("this Nfa may not be null");
88         }
89         catch (InternalException e) {
90             // Expected
91
}
92
93         try {
94             this.dfa = Dfa.difference(this.nfa, nullNfa);
95             fail("nfa may not be null");
96         }
97         catch (InternalException e) {
98             // Expected
99
}
100
101     }
102
103     @Test
104     public void testIntersection() {
105
106         // Case with null Nfa
107
Nfa<Integer JavaDoc> nullNfa = null;
108
109         try {
110             this.dfa = Dfa.intersection(nullNfa, this.nfa);
111             fail("this Nfa may not be null");
112         }
113         catch (InternalException e) {
114             // Expected
115
}
116
117         try {
118             this.dfa = Dfa.intersection(this.nfa, nullNfa);
119             fail("nfa may not be null");
120         }
121         catch (InternalException e) {
122             // Expected
123
}
124
125     }
126 }
127
Popular Tags