| OLD | NEW |
| (Empty) |
| 1 # 2008 Feb 19 | |
| 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 # | |
| 12 # The focus of this file is testing the r-tree extension. | |
| 13 # | |
| 14 # $Id: rtree2.test,v 1.4 2008/07/14 15:37:01 danielk1977 Exp $ | |
| 15 # | |
| 16 | |
| 17 if {![info exists testdir]} { | |
| 18 set testdir [file join [file dirname $argv0] .. .. test] | |
| 19 } | |
| 20 source [file join [file dirname [info script]] rtree_util.tcl] | |
| 21 source $testdir/tester.tcl | |
| 22 | |
| 23 ifcapable !rtree { | |
| 24 finish_test | |
| 25 return | |
| 26 } | |
| 27 | |
| 28 set ::NROW 1000 | |
| 29 set ::NDEL 10 | |
| 30 set ::NSELECT 100 | |
| 31 | |
| 32 if {[info exists ISQUICK] && $ISQUICK} { | |
| 33 set ::NROW 100 | |
| 34 set ::NSELECT 10 | |
| 35 } | |
| 36 | |
| 37 foreach module {rtree_i32 rtree} { | |
| 38 for {set nDim 1} {$nDim <= 5} {incr nDim} { | |
| 39 | |
| 40 do_test rtree2-$module.$nDim.1 { | |
| 41 set cols [list] | |
| 42 foreach c [list c0 c1 c2 c3 c4 c5 c6 c7 c8 c9] { | |
| 43 lappend cols "$c REAL" | |
| 44 } | |
| 45 set cols [join [lrange $cols 0 [expr {$nDim*2-1}]] ", "] | |
| 46 execsql " | |
| 47 CREATE VIRTUAL TABLE t1 USING ${module}(ii, $cols); | |
| 48 CREATE TABLE t2 (ii, $cols); | |
| 49 " | |
| 50 } {} | |
| 51 | |
| 52 do_test rtree2-$module.$nDim.2 { | |
| 53 db transaction { | |
| 54 for {set ii 0} {$ii < $::NROW} {incr ii} { | |
| 55 #puts "Row $ii" | |
| 56 set values [list] | |
| 57 for {set jj 0} {$jj<$nDim*2} {incr jj} { | |
| 58 lappend values [expr int(rand()*1000)] | |
| 59 } | |
| 60 set values [join $values ,] | |
| 61 #puts [rtree_treedump db t1] | |
| 62 #puts "INSERT INTO t2 VALUES($ii, $values)" | |
| 63 set rc [catch {db eval "INSERT INTO t1 VALUES($ii, $values)"}] | |
| 64 if {$rc} { | |
| 65 incr ii -1 | |
| 66 } else { | |
| 67 db eval "INSERT INTO t2 VALUES($ii, $values)" | |
| 68 } | |
| 69 #if {[rtree_check db t1]} { | |
| 70 #puts [rtree_treedump db t1] | |
| 71 #exit | |
| 72 #} | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 set t1 [execsql {SELECT * FROM t1 ORDER BY ii}] | |
| 77 set t2 [execsql {SELECT * FROM t2 ORDER BY ii}] | |
| 78 set rc [expr {$t1 eq $t2}] | |
| 79 if {$rc != 1} { | |
| 80 puts $t1 | |
| 81 puts $t2 | |
| 82 } | |
| 83 set rc | |
| 84 } {1} | |
| 85 | |
| 86 do_test rtree2-$module.$nDim.3 { | |
| 87 rtree_check db t1 | |
| 88 } 0 | |
| 89 | |
| 90 set OPS [list < > <= >= =] | |
| 91 for {set ii 0} {$ii < $::NSELECT} {incr ii} { | |
| 92 do_test rtree2-$module.$nDim.4.$ii.1 { | |
| 93 set where [list] | |
| 94 foreach look_three_dots! {. . .} { | |
| 95 set colidx [expr int(rand()*($nDim*2+1))-1] | |
| 96 if {$colidx<0} { | |
| 97 set col ii | |
| 98 } else { | |
| 99 set col "c$colidx" | |
| 100 } | |
| 101 set op [lindex $OPS [expr int(rand()*[llength $OPS])]] | |
| 102 set val [expr int(rand()*1000)] | |
| 103 lappend where "$col $op $val" | |
| 104 } | |
| 105 set where [join $where " AND "] | |
| 106 | |
| 107 set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"] | |
| 108 set t2 [execsql "SELECT * FROM t2 WHERE $where ORDER BY ii"] | |
| 109 set rc [expr {$t1 eq $t2}] | |
| 110 if {$rc != 1} { | |
| 111 #puts $where | |
| 112 puts $t1 | |
| 113 puts $t2 | |
| 114 #puts [rtree_treedump db t1] | |
| 115 #breakpoint | |
| 116 #set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"] | |
| 117 #exit | |
| 118 } | |
| 119 set rc | |
| 120 } {1} | |
| 121 } | |
| 122 | |
| 123 for {set ii 0} {$ii < $::NROW} {incr ii $::NDEL} { | |
| 124 #puts [rtree_treedump db t1] | |
| 125 do_test rtree2-$module.$nDim.5.$ii.1 { | |
| 126 execsql "DELETE FROM t2 WHERE ii <= $::ii" | |
| 127 execsql "DELETE FROM t1 WHERE ii <= $::ii" | |
| 128 | |
| 129 set t1 [execsql {SELECT * FROM t1 ORDER BY ii}] | |
| 130 set t2 [execsql {SELECT * FROM t2 ORDER BY ii}] | |
| 131 set rc [expr {$t1 eq $t2}] | |
| 132 if {$rc != 1} { | |
| 133 puts $t1 | |
| 134 puts $t2 | |
| 135 } | |
| 136 set rc | |
| 137 } {1} | |
| 138 do_test rtree2-$module.$nDim.5.$ii.2 { | |
| 139 rtree_check db t1 | |
| 140 } {0} | |
| 141 } | |
| 142 | |
| 143 do_test rtree2-$module.$nDim.6 { | |
| 144 execsql { | |
| 145 DROP TABLE t1; | |
| 146 DROP TABLE t2; | |
| 147 } | |
| 148 } {} | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 finish_test | |
| OLD | NEW |