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

Function TestCovererRandomCaps

s2/regioncoverer_test.go:116–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestCovererRandomCaps(t *testing.T) {
117 rc := &RegionCoverer{MinLevel: 0, MaxLevel: 30, LevelMod: 1, MaxCells: 1}
118 for i := range 1000 {
119 rc.MinLevel = int(rand.Int31n(MaxLevel + 1))
120 rc.MaxLevel = int(rand.Int31n(MaxLevel + 1))
121 for rc.MinLevel > rc.MaxLevel {
122 rc.MinLevel = int(rand.Int31n(MaxLevel + 1))
123 rc.MaxLevel = int(rand.Int31n(MaxLevel + 1))
124 }
125 rc.LevelMod = int(1 + rand.Int31n(3))
126 rc.MaxCells = skewedInt(10)
127
128 maxArea := math.Min(4*math.Pi, float64(3*rc.MaxCells+1)*AvgAreaMetric.Value(rc.MinLevel))
129 r := Region(randomCap(0.1*AvgAreaMetric.Value(MaxLevel), maxArea))
130
131 covering := rc.Covering(r)
132 checkCovering(t, rc, r, covering, false)
133 interior := rc.InteriorCovering(r)
134 checkCovering(t, rc, r, interior, true)
135
136 // Check that Covering is deterministic.
137 covering2 := rc.Covering(r)
138 if !reflect.DeepEqual(covering, covering2) {
139 t.Errorf("Iteration %d, got covering = %v, want covering = %v", i, covering2, covering)
140 }
141
142 // Also check Denormalize. The denormalized covering
143 // may still be different and smaller than "covering" because
144 // s2.RegionCoverer does not guarantee that it will not output all four
145 // children of the same parent.
146 covering.Denormalize(rc.MinLevel, rc.LevelMod)
147 checkCovering(t, rc, r, covering, false)
148 }
149}
150
151func TestRegionCovererInteriorCovering(t *testing.T) {
152 // We construct the region the following way. Start with Cell of level l.

Callers

nothing calls this directly

Calls 8

CoveringMethod · 0.95
InteriorCoveringMethod · 0.95
skewedIntFunction · 0.85
RegionInterface · 0.85
randomCapFunction · 0.85
checkCoveringFunction · 0.85
ValueMethod · 0.80
DenormalizeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…