KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > jre12 > soda > collections > STHashtableETTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.db4ounit.jre12.soda.collections;
22 import java.util.*;
23
24 import com.db4o.query.*;
25
26
27
28 public class STHashtableETTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
29     
30     public static class ExtendHashtable extends Hashtable{
31         
32     }
33     
34     ExtendHashtable col;
35
36     public STHashtableETTestCase() {
37     }
38     
39     public STHashtableETTestCase(Object JavaDoc[] arr) {
40         col = new ExtendHashtable();
41         for (int i = 0; i < arr.length; i++) {
42             col.put(arr[i], new Integer JavaDoc(i));
43         }
44     }
45
46     public Object JavaDoc[] createData() {
47         return new Object JavaDoc[] {
48             new STHashtableETTestCase(),
49             new STHashtableETTestCase(new Object JavaDoc[0]),
50             new STHashtableETTestCase(new Object JavaDoc[] { new Integer JavaDoc(0), new Integer JavaDoc(0)}),
51             new STHashtableETTestCase(
52                 new Object JavaDoc[] {
53                     new Integer JavaDoc(1),
54                     new Integer JavaDoc(17),
55                     new Integer JavaDoc(Integer.MAX_VALUE - 1)}),
56             new STHashtableETTestCase(
57                 new Object JavaDoc[] {
58                     new Integer JavaDoc(3),
59                     new Integer JavaDoc(17),
60                     new Integer JavaDoc(25),
61                     new Integer JavaDoc(Integer.MAX_VALUE - 2)}),
62             new STHashtableETTestCase(new Object JavaDoc[] { "foo", new STElement("bar", "barbar")}),
63             new STHashtableETTestCase(new Object JavaDoc[] { "foo2", new STElement("bar", "barbar2")})
64         };
65     }
66
67     public void testDefaultContainsInteger() {
68         Query q = newQuery();
69         
70         q.constrain(new STHashtableETTestCase(new Object JavaDoc[] { new Integer JavaDoc(17)}));
71         expect(q, new int[] { 3, 4 });
72     }
73
74     public void testDefaultContainsString() {
75         Query q = newQuery();
76         
77         q.constrain(new STHashtableETTestCase(new Object JavaDoc[] { "foo" }));
78         expect(q, new int[] { 5 });
79     }
80
81     public void testDefaultContainsTwo() {
82         Query q = newQuery();
83         
84         q.constrain(new STHashtableETTestCase(new Object JavaDoc[] { new Integer JavaDoc(17), new Integer JavaDoc(25)}));
85         expect(q, new int[] { 4 });
86     }
87
88     public void testDescendOne() {
89         Query q = newQuery();
90         
91         q.constrain(STHashtableETTestCase.class);
92         q.descend("col").constrain(new Integer JavaDoc(17));
93         expect(q, new int[] { 3, 4 });
94     }
95
96     public void testDescendTwo() {
97         Query q = newQuery();
98         
99         q.constrain(STHashtableETTestCase.class);
100         Query qElements = q.descend("col");
101         qElements.constrain(new Integer JavaDoc(17));
102         qElements.constrain(new Integer JavaDoc(25));
103         expect(q, new int[] { 4 });
104     }
105
106     public void testDescendSmaller() {
107         Query q = newQuery();
108         
109         q.constrain(STHashtableETTestCase.class);
110         Query qElements = q.descend("col");
111         qElements.constrain(new Integer JavaDoc(3)).smaller();
112         expect(q, new int[] { 2, 3 });
113     }
114     
115     public void testDefaultContainsObject() {
116         Query q = newQuery();
117         
118         q.constrain(new STHashtableETTestCase(new Object JavaDoc[] { new STElement("bar", null)}));
119         expect(q, new int[] { 5, 6 });
120     }
121     
122     public void testDescendToObject() {
123         Query q = newQuery();
124         
125         q.constrain(new STHashtableETTestCase());
126         q.descend("col").descend("foo1").constrain("bar");
127         expect(q, new int[] { 5, 6 });
128     }
129
130 }
Popular Tags