Unit test for BTreeFile.indexIterator()
()
| 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 |
no test coverage detected