KickJava   Java API By Example, From Geeks To Geeks.

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


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.assertFalse;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.sablecc.sablecc.alphabet.Realms;
28 import org.sablecc.sablecc.exception.InternalException;
29
30 public class GroupPairTest {
31
32     GroupPair<Integer JavaDoc> groupPair;
33
34     Group<Integer JavaDoc> group1;
35
36     Group<Integer JavaDoc> group2;
37
38     Partition<Integer JavaDoc> partition1;
39
40     Partition<Integer JavaDoc> partition2;
41
42     Dfa<Integer JavaDoc> dfa1;
43
44     Dfa<Integer JavaDoc> dfa2;
45
46     Nfa<Integer JavaDoc> nfa1;
47
48     Nfa<Integer JavaDoc> nfa2;
49
50     @Before
51     public void setUp()
52             throws Exception JavaDoc {
53
54         // For group 1
55
this.nfa1 = new Nfa<Integer JavaDoc>(Realms.getInteger().createInterval(50))
56                 .zeroOrMore();
57
58         this.dfa1 = new Dfa<Integer JavaDoc>(this.nfa1);
59
60         this.partition1 = new Partition<Integer JavaDoc>(this.dfa1);
61
62         this.group1 = new Group<Integer JavaDoc>(this.partition1);
63
64         // For group 2
65
this.nfa2 = new Nfa<Integer JavaDoc>(Realms.getInteger().createInterval(25))
66                 .zeroOrMore();
67
68         this.dfa2 = new Dfa<Integer JavaDoc>(this.nfa2);
69
70         this.partition2 = new Partition<Integer JavaDoc>(this.dfa2);
71
72         this.group2 = new Group<Integer JavaDoc>(this.partition2);
73
74         this.groupPair = new GroupPair<Integer JavaDoc>(this.group1, this.group2);
75     }
76
77     @SuppressWarnings JavaDoc("unused")
78     @Test
79     public void testGroupPair() {
80
81         // Case with null groups
82
Group<Integer JavaDoc> nullGroup = null;
83
84         try {
85             GroupPair<Integer JavaDoc> groupPair = new GroupPair<Integer JavaDoc>(nullGroup,
86                     this.group2);
87             fail("group1 may not be null");
88         }
89         catch (InternalException e) {
90             // Expected
91
}
92
93         try {
94             GroupPair<Integer JavaDoc> groupPair = new GroupPair<Integer JavaDoc>(this.group1,
95                     nullGroup);
96             fail("group2 may not be null");
97         }
98         catch (InternalException e) {
99             // Expected
100
}
101
102         assertEquals("group1 has not been entered correctly", this.group1,
103                 this.groupPair.getGroup1());
104
105         assertEquals("group2 has not been entered correctly", this.group2,
106                 this.groupPair.getGroup2());
107     }
108
109     @Test
110     public void testEqualsObject() {
111
112         // Case with null object
113
Object JavaDoc nullObject = null;
114
115         assertFalse("groupPair should not be equal to null", this.groupPair
116                 .equals(nullObject));
117
118         // Case with wrong instance
119
assertFalse("groupPair should not be equal to an Integer",
120                 this.groupPair.equals(10));
121
122         // Typical cases
123
assertTrue("a groupPair should be equal to himself", this.groupPair
124                 .equals(this.groupPair));
125
126         GroupPair<Integer JavaDoc> sameGroupPair = new GroupPair<Integer JavaDoc>(this.group1,
127                 this.group2);
128
129         assertTrue("groupPair should be equal to this instance", this.groupPair
130                 .equals(sameGroupPair));
131     }
132
133 }
134
Popular Tags