xref: /sqlite-3.40.0/ext/rtree/rtreeE.test (revision b640595f)
1# 2010 August 28
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
6#    May you do good and not evil.
7#    May you find forgiveness for yourself and forgive others.
8#    May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file contains tests for the r-tree module. Specifically, it tests
12# that new-style custom r-tree queries (geometry callbacks) work.
13#
14
15if {![info exists testdir]} {
16  set testdir [file join [file dirname [info script]] .. .. test]
17}
18source $testdir/tester.tcl
19ifcapable !rtree { finish_test ; return }
20ifcapable rtree_int_only { finish_test; return }
21
22
23#-------------------------------------------------------------------------
24# Test the example 2d "circle" geometry callback.
25#
26register_circle_geom db
27
28do_execsql_test rtreeE-1.1 {
29  PRAGMA page_size=512;
30  CREATE VIRTUAL TABLE rt2 USING rtree(id,x0,x1,y0,y1);
31
32  /* A tight pattern of small boxes near 0,0 */
33  WITH RECURSIVE
34    x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4),
35    y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4)
36  INSERT INTO rt2 SELECT x+5*y, x, x+2, y, y+2 FROM x, y;
37
38  /* A looser pattern of small boxes near 100, 0 */
39  WITH RECURSIVE
40    x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4),
41    y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4)
42  INSERT INTO rt2 SELECT 100+x+5*y, x*3+100, x*3+102, y*3, y*3+2 FROM x, y;
43
44  /* A looser pattern of larger boxes near 0, 200 */
45  WITH RECURSIVE
46    x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4),
47    y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4)
48  INSERT INTO rt2 SELECT 200+x+5*y, x*7, x*7+15, y*7+200, y*7+215 FROM x, y;
49} {}
50
51if 0 {
52# Queries against each of the three clusters */
53do_execsql_test rtreeE-1.1 {
54  SELECT id FROM rt2 WHERE id MATCH Qcircle(0.0, 0.0, 50.0) ORDER BY id;
55} {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24}
56do_execsql_test rtreeE-1.2 {
57  SELECT id FROM rt2 WHERE id MATCH Qcircle(100.0, 0.0, 50.0) ORDER BY id;
58} {100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124}
59do_execsql_test rtreeE-1.3 {
60  SELECT id FROM rt2 WHERE id MATCH Qcircle(0.0, 200.0, 50.0) ORDER BY id;
61} {200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224}
62}
63
64# The Qcircle geometry function gives a lower score to larger leaf-nodes.
65# This causes the 200s to sort before the 100s and the 0s to sort before
66# last.
67#
68do_execsql_test rtreeE-1.4 {
69  SELECT id FROM rt2 WHERE id MATCH Qcircle(0,0,1000) AND id%100==0
70} {200 100 0}
71
72finish_test
73