1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.onemind.commons.java.datastructure;
22
23 import org.onemind.commons.java.datastructure.NametableStack;
24 import junit.framework.TestCase;
25 /***
26 * Test for nametable stack
27 * @author TiongHiang Lee (thlee@onemindsoft.org)
28 * @version $Id: NametableStackTest.java,v 1.3 2005/04/06 15:40:43 thlee Exp $ $Name: $
29 */
30 public class NametableStackTest extends TestCase
31 {
32
33 public void testCloseScope()
34 {
35 NametableStack stack = new NametableStack();
36
37 for (int i = 0; i < 5; i++)
38 {
39 String name = String.valueOf(i);
40 stack.declare(name, name);
41 }
42
43 int scope = stack.newScope();
44
45 for (int i = 5; i < 10; i++)
46 {
47 String name = String.valueOf(i);
48 stack.declare(name, name);
49 }
50
51 for (int i = 0; i < 10; i++)
52 {
53 String name = String.valueOf(i);
54 assertEquals(stack.access(name), name);
55 }
56
57 stack.closeScope(scope);
58
59 for (int i = 5; i < 10; i++)
60 {
61 String name = String.valueOf(i);
62 assertFalse(stack.containsName(name));
63 }
64 for (int i = 0; i < 5; i++)
65 {
66 String name = String.valueOf(i);
67 assertEquals(stack.access(name), name);
68 }
69 }
70
71 public void testLocalScope()
72 {
73 NametableStack stack = new NametableStack();
74
75 for (int i = 0; i < 5; i++)
76 {
77 String name = String.valueOf(i);
78 stack.declare(name, name);
79 }
80
81 int scope = stack.newLocalScope();
82
83 for (int i = 2; i < 7; i++)
84 {
85 String name = String.valueOf(i);
86 stack.declare(name, name);
87 }
88
89 for (int i = 0; i < 7; i++)
90 {
91 String name = String.valueOf(i);
92 assertEquals(stack.access(name), name);
93 }
94
95 stack.closeLocalScope(scope);
96
97 for (int i = 5; i < 7; i++)
98 {
99 String name = String.valueOf(i);
100 assertFalse(stack.containsName(name));
101 }
102 for (int i = 0; i < 5; i++)
103 {
104 String name = String.valueOf(i);
105 assertEquals(stack.access(name), name);
106 }
107
108
109 }
110 }