MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / indexIterator

Method indexIterator

test/simpledb/BTreeFileReadTest.java:142–208  ·  view source on GitHub ↗

Unit test for BTreeFile.indexIterator()

()

Source from the content-addressed store, hash-verified

140 * Unit test for BTreeFile.indexIterator()
141 */
142 @Test public void indexIterator() throws Exception {
143 BTreeFile twoLeafPageFile = BTreeUtility.createBTreeFile(2, 520,
144 null, null, 0);
145 Field f = new IntField(5);
146
147 // greater than
148 IndexPredicate ipred = new IndexPredicate(Op.GREATER_THAN, f);
149 DbFileIterator it = twoLeafPageFile.indexIterator(tid, ipred);
150 it.open();
151 int count = 0;
152 while(it.hasNext()) {
153 Tuple t = it.next();
154 assertTrue(t.getField(0).compare(Op.GREATER_THAN, f));
155 count++;
156 }
157 assertEquals(515, count);
158 it.close();
159
160 // less than or equal to
161 ipred = new IndexPredicate(Op.LESS_THAN_OR_EQ, f);
162 it = twoLeafPageFile.indexIterator(tid, ipred);
163 it.open();
164 count = 0;
165 while(it.hasNext()) {
166 Tuple t = it.next();
167 assertTrue(t.getField(0).compare(Op.LESS_THAN_OR_EQ, f));
168 count++;
169 }
170 assertEquals(5, count);
171 it.close();
172
173 // equal to
174 ipred = new IndexPredicate(Op.EQUALS, f);
175 it = twoLeafPageFile.indexIterator(tid, ipred);
176 it.open();
177 count = 0;
178 while(it.hasNext()) {
179 Tuple t = it.next();
180 assertTrue(t.getField(0).compare(Op.EQUALS, f));
181 count++;
182 }
183 assertEquals(1, count);
184 it.close();
185
186 // now insert a record and ensure EQUALS returns both records
187 twoLeafPageFile.insertTuple(tid, BTreeUtility.getBTreeTuple(5, 2));
188 ipred = new IndexPredicate(Op.EQUALS, f);
189 it = twoLeafPageFile.indexIterator(tid, ipred);
190 it.open();
191 count = 0;
192 while(it.hasNext()) {
193 Tuple t = it.next();
194 assertTrue(t.getField(0).compare(Op.EQUALS, f));
195 count++;
196 }
197 assertEquals(2, count);
198 it.close();
199

Callers 1

setUpMethod · 0.45

Calls 10

createBTreeFileMethod · 0.95
indexIteratorMethod · 0.95
openMethod · 0.95
hasNextMethod · 0.95
nextMethod · 0.95
getFieldMethod · 0.95
closeMethod · 0.95
insertTupleMethod · 0.95
getBTreeTupleMethod · 0.95
compareMethod · 0.65

Tested by

no test coverage detected