forked from mirror/rtred
point test
This commit is contained in:
parent
244577df54
commit
a2f2655468
|
@ -36,6 +36,20 @@ func tRandRect(dims int) *tRect {
|
||||||
}
|
}
|
||||||
return &r
|
return &r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tPoint struct {
|
||||||
|
x, y float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *tPoint) Rect() (min, max []float64) {
|
||||||
|
return []float64{r.x, r.y}, []float64{r.x, r.y}
|
||||||
|
}
|
||||||
|
func tRandPoint() *tPoint {
|
||||||
|
return &tPoint{
|
||||||
|
rand.Float64()*200 - 100,
|
||||||
|
rand.Float64()*200 - 100,
|
||||||
|
}
|
||||||
|
}
|
||||||
func TestRTree(t *testing.T) {
|
func TestRTree(t *testing.T) {
|
||||||
tr := New()
|
tr := New()
|
||||||
|
|
||||||
|
@ -59,7 +73,7 @@ func TestRTree(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsert(t *testing.T) {
|
func TestInsertDelete(t *testing.T) {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
n := 50000
|
n := 50000
|
||||||
tr := New()
|
tr := New()
|
||||||
|
@ -94,3 +108,33 @@ func TestInsert(t *testing.T) {
|
||||||
t.Fatalf("expected %v, got %v", n, total)
|
t.Fatalf("expected %v, got %v", n, total)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestPoints(t *testing.T) {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
n := 100000
|
||||||
|
tr := New()
|
||||||
|
var points []*tPoint
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
r := tRandPoint()
|
||||||
|
points = append(points, r)
|
||||||
|
tr.Insert(r)
|
||||||
|
}
|
||||||
|
if tr.Count() != n {
|
||||||
|
t.Fatalf("expecting %v, got %v", n, tr.Count())
|
||||||
|
}
|
||||||
|
var count int
|
||||||
|
tr.Search(&tRect{-100, -100, -100, -100, 100, 100, 100, 100}, func(item Item) bool {
|
||||||
|
count++
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if count != n {
|
||||||
|
t.Fatalf("expecting %v, got %v", n, count)
|
||||||
|
}
|
||||||
|
for _, p := range points {
|
||||||
|
tr.Remove(p)
|
||||||
|
}
|
||||||
|
total := tr.Count() + count
|
||||||
|
if total != n {
|
||||||
|
t.Fatalf("expected %v, got %v", n, total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue