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_rtree_integrity_test rtree2-$module.$nDim.3 t1
86 set OPS [list < > <= >= =]
87 for {set ii 0} {$ii < $::NSELECT} {incr ii} {
88 do_test rtree2-$module.$nDim.4.$ii.1 {
90 foreach look_three_dots! {. . .} {
91 set colidx [expr int(rand()*($nDim*2+1))-1]
97 set op [lindex $OPS [expr int(rand()*[llength $OPS])]]
98 set val [expr int(rand()*1000)]
99 lappend where "$col $op $val"
101 set where [join $where " AND "]
103 set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"]
104 set t2 [execsql "SELECT * FROM t2 WHERE $where ORDER BY ii"]
105 set rc [expr {$t1 eq $t2}]
110 #puts [rtree_treedump db t1]
112 #set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"]
119 for {set ii 0} {$ii < $::NROW} {incr ii $::NDEL} {
120 #puts [rtree_treedump db t1]
121 do_test rtree2-$module.$nDim.5.$ii.1 {
122 execsql "DELETE FROM t2 WHERE ii <= $::ii"
123 execsql "DELETE FROM t1 WHERE ii <= $::ii"
125 set t1 [execsql {SELECT * FROM t1 ORDER BY ii}]
126 set t2 [execsql {SELECT * FROM t2 ORDER BY ii}]
127 set rc [expr {$t1 eq $t2}]
134 do_rtree_integrity_test rtree2-$module.$nDim.5.$ii.2 t1
137 do_test rtree2-$module.$nDim.6 {