3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # The focus of this file is testing the r-tree extension.
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
18 source [file join [file dirname [info script]] rtree_util.tcl]
19 source $testdir/tester.tcl
30 if {[info exists G(isquick)] && $G(isquick)} {
35 foreach module {rtree_i32 rtree} {
36 for {set nDim 1} {$nDim <= 5} {incr nDim} {
38 do_test rtree2-$module.$nDim.1 {
40 foreach c [list c0 c1 c2 c3 c4 c5 c6 c7 c8 c9] {
41 lappend cols "$c REAL"
43 set cols [join [lrange $cols 0 [expr {$nDim*2-1}]] ", "]
45 CREATE VIRTUAL TABLE t1 USING ${module}(ii, $cols);
46 CREATE TABLE t2 (ii, $cols);
50 do_test rtree2-$module.$nDim.2 {
52 for {set ii 0} {$ii < $::NROW} {incr ii} {
55 for {set jj 0} {$jj<$nDim*2} {incr jj} {
56 lappend values [expr int(rand()*1000)]
58 set values [join $values ,]
59 #puts [rtree_treedump db t1]
60 #puts "INSERT INTO t2 VALUES($ii, $values)"
61 set rc [catch {db eval "INSERT INTO t1 VALUES($ii, $values)"}]
65 db eval "INSERT INTO t2 VALUES($ii, $values)"
67 #if {[rtree_check db t1]} {
68 #puts [rtree_treedump db t1]
74 set t1 [execsql {SELECT * FROM t1 ORDER BY ii}]
75 set t2 [execsql {SELECT * FROM t2 ORDER BY ii}]
76 set rc [expr {$t1 eq $t2}]
84 do_test rtree2-$module.$nDim.3 {
88 set OPS [list < > <= >= =]
89 for {set ii 0} {$ii < $::NSELECT} {incr ii} {
90 do_test rtree2-$module.$nDim.4.$ii.1 {
92 foreach look_three_dots! {. . .} {
93 set colidx [expr int(rand()*($nDim*2+1))-1]
99 set op [lindex $OPS [expr int(rand()*[llength $OPS])]]
100 set val [expr int(rand()*1000)]
101 lappend where "$col $op $val"
103 set where [join $where " AND "]
105 set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"]
106 set t2 [execsql "SELECT * FROM t2 WHERE $where ORDER BY ii"]
107 set rc [expr {$t1 eq $t2}]
112 #puts [rtree_treedump db t1]
114 #set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"]
121 for {set ii 0} {$ii < $::NROW} {incr ii $::NDEL} {
122 #puts [rtree_treedump db t1]
123 do_test rtree2-$module.$nDim.5.$ii.1 {
124 execsql "DELETE FROM t2 WHERE ii <= $::ii"
125 execsql "DELETE FROM t1 WHERE ii <= $::ii"
127 set t1 [execsql {SELECT * FROM t1 ORDER BY ii}]
128 set t2 [execsql {SELECT * FROM t2 ORDER BY ii}]
129 set rc [expr {$t1 eq $t2}]
136 do_test rtree2-$module.$nDim.5.$ii.2 {
141 do_test rtree2-$module.$nDim.6 {