KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > alphabet > AlphabetMergeResultTest


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.alphabet;
19
20 import static org.junit.Assert.assertEquals;
21
22 import java.math.BigInteger JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.SortedSet JavaDoc;
26 import java.util.TreeSet JavaDoc;
27
28 import org.junit.Before;
29 import org.junit.Test;
30
31 public class AlphabetMergeResultTest {
32
33     // Integer
34
private AlphabetMergeResult<Integer JavaDoc> resultMergeInt;
35
36     private Alphabet<Integer JavaDoc> oldAlphabetInt1;
37
38     private Alphabet<Integer JavaDoc> oldAlphabetInt2;
39
40     private AdjacencyRealm<Integer JavaDoc> integerAdjacencyRealm = Realms.getInteger();
41
42     private Collection JavaDoc<Interval<Integer JavaDoc>> intervalsInt = new LinkedList JavaDoc<Interval<Integer JavaDoc>>();
43
44     private Symbol<Integer JavaDoc> symbolInt;
45
46     private SortedSet JavaDoc<Symbol<Integer JavaDoc>> symbolsInt1 = new TreeSet JavaDoc<Symbol<Integer JavaDoc>>();
47
48     private SortedSet JavaDoc<Symbol<Integer JavaDoc>> symbolsInt2 = new TreeSet JavaDoc<Symbol<Integer JavaDoc>>();
49
50     private SortedSet JavaDoc<Symbol<Integer JavaDoc>> newSymbolsInt = new TreeSet JavaDoc<Symbol<Integer JavaDoc>>();
51
52     // BigInteger
53
private AlphabetMergeResult<BigInteger JavaDoc> resultMergeBig;
54
55     private Alphabet<BigInteger JavaDoc> oldAlphabetBig1;
56
57     private Alphabet<BigInteger JavaDoc> oldAlphabetBig2;
58
59     private AdjacencyRealm<BigInteger JavaDoc> bigIntegerAdjacencyRealm = Realms
60             .getBigInteger();
61
62     private Collection JavaDoc<Interval<BigInteger JavaDoc>> intervalsBig = new LinkedList JavaDoc<Interval<BigInteger JavaDoc>>();
63
64     private Symbol<BigInteger JavaDoc> symbolBig;
65
66     private SortedSet JavaDoc<Symbol<BigInteger JavaDoc>> symbolsBig1 = new TreeSet JavaDoc<Symbol<BigInteger JavaDoc>>();
67
68     private SortedSet JavaDoc<Symbol<BigInteger JavaDoc>> symbolsBig2 = new TreeSet JavaDoc<Symbol<BigInteger JavaDoc>>();
69
70     private SortedSet JavaDoc<Symbol<BigInteger JavaDoc>> newSymbolsBig = new TreeSet JavaDoc<Symbol<BigInteger JavaDoc>>();
71
72     @Before
73     public void setUp()
74             throws Exception JavaDoc {
75
76         // For Integer
77
this.intervalsInt.clear();
78         this.intervalsInt.add(new Interval<Integer JavaDoc>(0, 10,
79                 this.integerAdjacencyRealm));
80         this.intervalsInt.add(new Interval<Integer JavaDoc>(20, 30,
81                 this.integerAdjacencyRealm));
82         this.intervalsInt.add(new Interval<Integer JavaDoc>(40, 500,
83                 this.integerAdjacencyRealm));
84         this.symbolInt = new Symbol<Integer JavaDoc>(this.intervalsInt);
85
86         this.symbolsInt1.add(this.symbolInt);
87         this.oldAlphabetInt1 = new Alphabet<Integer JavaDoc>(this.symbolsInt1);
88
89         this.newSymbolsInt.add(new Symbol<Integer JavaDoc>(this.intervalsInt));
90
91         this.intervalsInt.clear();
92         this.intervalsInt.add(new Interval<Integer JavaDoc>(100, 110,
93                 this.integerAdjacencyRealm));
94         this.intervalsInt.add(new Interval<Integer JavaDoc>(120, 130,
95                 this.integerAdjacencyRealm));
96         this.intervalsInt.add(new Interval<Integer JavaDoc>(140, 150,
97                 this.integerAdjacencyRealm));
98         this.symbolInt = new Symbol<Integer JavaDoc>(this.intervalsInt);
99         this.symbolsInt2.add(this.symbolInt);
100         this.oldAlphabetInt2 = new Alphabet<Integer JavaDoc>(this.symbolsInt2);
101
102         this.newSymbolsInt.add(new Symbol<Integer JavaDoc>(this.intervalsInt));
103
104         // For BigInteger
105
this.intervalsBig.clear();
106         this.intervalsBig.add(new Interval<BigInteger JavaDoc>(BigInteger.ZERO,
107                 BigInteger.TEN, this.bigIntegerAdjacencyRealm));
108         this.intervalsBig.add(new Interval<BigInteger JavaDoc>(new BigInteger JavaDoc("50"),
109                 new BigInteger JavaDoc("100"), this.bigIntegerAdjacencyRealm));
110         this.intervalsBig.add(new Interval<BigInteger JavaDoc>(new BigInteger JavaDoc("200"),
111                 new BigInteger JavaDoc("400"), this.bigIntegerAdjacencyRealm));
112
113         this.symbolBig = new Symbol<BigInteger JavaDoc>(this.intervalsBig);
114
115         this.symbolsBig1.add(this.symbolBig);
116         this.oldAlphabetBig1 = new Alphabet<BigInteger JavaDoc>(this.symbolsBig1);
117
118         this.newSymbolsBig.add(new Symbol<BigInteger JavaDoc>(this.intervalsBig));
119
120         this.intervalsBig.clear();
121         this.intervalsBig.add(new Interval<BigInteger JavaDoc>(new BigInteger JavaDoc("30"),
122                 new BigInteger JavaDoc("40"), this.bigIntegerAdjacencyRealm));
123         this.intervalsBig.add(new Interval<BigInteger JavaDoc>(new BigInteger JavaDoc("600"),
124                 new BigInteger JavaDoc("800"), this.bigIntegerAdjacencyRealm));
125         this.intervalsBig.add(new Interval<BigInteger JavaDoc>(new BigInteger JavaDoc("150"),
126                 new BigInteger JavaDoc("170"), this.bigIntegerAdjacencyRealm));
127
128         this.symbolBig = new Symbol<BigInteger JavaDoc>(this.intervalsBig);
129
130         this.symbolsBig2.add(this.symbolBig);
131         this.oldAlphabetBig2 = new Alphabet<BigInteger JavaDoc>(this.symbolsBig2);
132
133         this.newSymbolsBig.add(new Symbol<BigInteger JavaDoc>(this.intervalsBig));
134     }
135
136     @Test
137     public void testGetNewSymbols() {
138
139         // With Integer
140
this.resultMergeInt = this.oldAlphabetInt1
141                 .mergeWith(this.oldAlphabetInt2);
142
143         this.newSymbolsInt = this.resultMergeInt.getNewSymbols(this.symbolInt,
144                 this.oldAlphabetInt2);
145         assertEquals("The newSymbols and the old symbols should be equals.",
146                 this.symbolsInt2, this.newSymbolsInt);
147
148         // With BigInteger
149
this.resultMergeBig = this.oldAlphabetBig1
150                 .mergeWith(this.oldAlphabetBig2);
151
152         this.newSymbolsBig = this.resultMergeBig.getNewSymbols(this.symbolBig,
153                 this.oldAlphabetBig2);
154         assertEquals("The newSymbols and the old symbols should be equals.",
155                 this.symbolsBig2, this.newSymbolsBig);
156     }
157
158 }
159
Popular Tags