MCPcopy
hub / github.com/golang/geo / testIteratorMethods

Function testIteratorMethods

s2/shapeindex_test.go:240–354  ·  view source on GitHub ↗
(t *testing.T, index *ShapeIndex)

Source from the content-addressed store, hash-verified

238}
239
240func testIteratorMethods(t *testing.T, index *ShapeIndex) {
241 it := index.Iterator()
242 if it.Prev() {
243 t.Fatalf("new iterator should not be able to go backwards")
244 }
245
246 it.End()
247 if !it.Done() {
248 t.Errorf("iterator positioned at end should report as done")
249 }
250
251 var ids []CellID
252 // minCellID is the first CellID in a complete traversal.
253 minCellID := CellIDFromFace(0).ChildBeginAtLevel(MaxLevel)
254
255 for it.Begin(); !it.Done(); it.Next() {
256 // Get the next cell in the iterator.
257 ci := it.CellID()
258 skipped := CellUnionFromRange(minCellID, ci.RangeMin())
259
260 it2 := NewShapeIndexIterator(index, IteratorEnd)
261 for i := range skipped {
262 if it2.LocatePoint(skipped[i].Point()) {
263 t.Errorf("iterator should not have been able to find the cell %v which was not in the index", skipped[i].Point())
264 }
265
266 if got := it2.LocateCellID(skipped[i]); got != Disjoint {
267 t.Errorf("CellID location should be Disjoint for non-existent entry, got %v", got)
268 }
269 it2.Begin()
270 it2.seek(skipped[i])
271 if ci != it2.CellID() {
272 t.Errorf("seeking the current cell in the skipped list should match the current cellid. got %v, want %v", it2.CellID(), ci)
273 }
274 }
275
276 if len(ids) != 0 {
277 prevCell := ids[len(ids)-1]
278 // C++ overloads operator= to clone the iterator. We can't
279 // just assign directly since it2 will than change it when
280 // it should not.
281 it2 = copyIterator(it)
282 if !it2.Prev() {
283 t.Errorf("should have been able to go back because there are cells")
284 }
285 if prevCell != it2.CellID() {
286 t.Errorf("ShapeIndexIterator should be positioned at the beginning and not equal to last entry")
287 }
288
289 it2.Next()
290 if ci != it2.CellID() {
291 t.Errorf("advancing back one spot should give us the current cell")
292 }
293
294 it2.seek(prevCell)
295 if prevCell != it2.CellID() {
296 t.Errorf("seek from beginning for the first previous cell %v should not give us the current cell %v", prevCell, it.CellID())
297 }

Calls 15

LocatePointMethod · 0.95
LocateCellIDMethod · 0.95
BeginMethod · 0.95
seekMethod · 0.95
CellIDMethod · 0.95
PrevMethod · 0.95
NextMethod · 0.95
CellIDFromFaceFunction · 0.85
CellUnionFromRangeFunction · 0.85
NewShapeIndexIteratorFunction · 0.85
copyIteratorFunction · 0.85
IteratorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…