KickJava   Java API By Example, From Geeks To Geeks.

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


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

18
19 package org.sablecc.sablecc.automaton;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.fail;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.sablecc.sablecc.alphabet.Interval;
28 import org.sablecc.sablecc.alphabet.Realms;
29 import org.sablecc.sablecc.alphabet.Symbol;
30 import org.sablecc.sablecc.exception.InternalException;
31
32 public class GroupTest {
33
34     private Group<Integer JavaDoc> group;
35
36     private Interval<Integer JavaDoc> interval;
37
38     private Nfa<Integer JavaDoc> nfa;
39
40     private Dfa<Integer JavaDoc> dfa;
41
42     private Partition<Integer JavaDoc> partition;
43
44     @Before
45     public void setUp()
46             throws Exception JavaDoc {
47
48         this.interval = Realms.getInteger().createInterval(50);
49
50         this.nfa = new Nfa<Integer JavaDoc>(this.interval).zeroOrMore();
51
52         this.dfa = new Dfa<Integer JavaDoc>(this.nfa);
53
54         this.partition = new Partition<Integer JavaDoc>(this.dfa);
55
56         this.group = new Group<Integer JavaDoc>(this.partition);
57     }
58
59     @Test
60     public void testGroup() {
61
62         // Case with null partition
63
Partition<Integer JavaDoc> nullPartition = null;
64         try {
65             this.group = new Group<Integer JavaDoc>(nullPartition);
66             fail("partition may not be null");
67         }
68         catch (InternalException e) {
69             // Expected
70
}
71
72         assertEquals("the group has the wrong partition", this.partition,
73                 this.group.getPartition());
74     }
75
76     @Test
77     public void testAddElement() {
78
79         // Case with null Element
80
Element<Integer JavaDoc> nullElement = null;
81         try {
82             this.group.addElement(nullElement);
83             fail("element may not be null");
84         }
85         catch (InternalException e) {
86             // Expected
87
}
88     }
89
90     @Test
91     public void testRemoveElement() {
92
93         // Case with null Element
94
Element<Integer JavaDoc> nullElement = null;
95         try {
96             this.group.removeElement(nullElement);
97             fail("element may not be null");
98         }
99         catch (InternalException e) {
100             // Expected
101
}
102     }
103
104     @Test
105     public void testAddTransition() {
106
107         // Case with null Symbol
108
Symbol<Integer JavaDoc> nullSymbol = null;
109         try {
110             this.group.addTransition(nullSymbol, this.group);
111             fail("symbol may not be null");
112         }
113         catch (InternalException e) {
114             // Expected
115
}
116         // Case with null Group
117
Symbol<Integer JavaDoc> symbol = new Symbol<Integer JavaDoc>(this.interval);
118         try {
119             this.group.addTransition(nullSymbol, this.group);
120             fail("group may not be null");
121         }
122         catch (InternalException e) {
123             // Expected
124
}
125
126         this.group.addTransition(symbol, this.group);
127         assertFalse("The set of transition of the group should not be empty",
128                 this.group.getTransitions().isEmpty());
129     }
130 }
131
Popular Tags