mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-23 11:22:09 +03:00
Import 'rtree' extension. (CVS 5159)
FossilOrigin-Name: b104dcd6adadbd3fe15a348fe9d4d290119e139e
This commit is contained in:
144
ext/rtree/rtree2.test
Normal file
144
ext/rtree/rtree2.test
Normal file
@ -0,0 +1,144 @@
|
||||
# 2008 Feb 19
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# The focus of this file is testing the r-tree extension.
|
||||
#
|
||||
# $Id: rtree2.test,v 1.1 2008/05/26 18:41:54 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file join [file dirname $argv0] .. .. test]
|
||||
source $testdir/tester.tcl
|
||||
source [file join [file dirname $argv0] rtree_util.tcl]
|
||||
|
||||
ifcapable !rtree {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
set ::NROW 1000
|
||||
set ::NDEL 10
|
||||
set ::NSELECT 100
|
||||
|
||||
for {set nDim 1} {$nDim <= 5} {incr nDim} {
|
||||
|
||||
do_test rtree2-$nDim.1 {
|
||||
set cols [list]
|
||||
foreach c [list c0 c1 c2 c3 c4 c5 c6 c7 c8 c9] {
|
||||
lappend cols "$c REAL"
|
||||
}
|
||||
set cols [join [lrange $cols 0 [expr {$nDim*2-1}]] ", "]
|
||||
execsql "
|
||||
CREATE VIRTUAL TABLE t1 USING rtree(ii, $cols);
|
||||
CREATE TABLE t2 (ii, $cols);
|
||||
"
|
||||
} {}
|
||||
|
||||
do_test rtree2-$nDim.2 {
|
||||
db transaction {
|
||||
for {set ii 0} {$ii < $::NROW} {incr ii} {
|
||||
#puts "Row $ii"
|
||||
set values [list]
|
||||
for {set jj 0} {$jj<$nDim*2} {incr jj} {
|
||||
lappend values [expr int(rand()*1000)]
|
||||
}
|
||||
set values [join $values ,]
|
||||
#puts [rtree_treedump db t1]
|
||||
#puts "INSERT INTO t2 VALUES($ii, $values)"
|
||||
set rc [catch {db eval "INSERT INTO t1 VALUES($ii, $values)"}]
|
||||
if {$rc} {
|
||||
incr ii -1
|
||||
} else {
|
||||
db eval "INSERT INTO t2 VALUES($ii, $values)"
|
||||
}
|
||||
#if {[rtree_check db t1]} {
|
||||
#puts [rtree_treedump db t1]
|
||||
#exit
|
||||
#}
|
||||
}
|
||||
}
|
||||
|
||||
set t1 [execsql {SELECT * FROM t1 ORDER BY ii}]
|
||||
set t2 [execsql {SELECT * FROM t2 ORDER BY ii}]
|
||||
set rc [expr {$t1 eq $t2}]
|
||||
if {$rc != 1} {
|
||||
puts $t1
|
||||
puts $t2
|
||||
}
|
||||
set rc
|
||||
} {1}
|
||||
|
||||
do_test rtree2-$nDim.3 {
|
||||
rtree_check db t1
|
||||
} 0
|
||||
|
||||
set OPS [list < > <= >= =]
|
||||
for {set ii 0} {$ii < $::NSELECT} {incr ii} {
|
||||
do_test rtree2-$nDim.4.$ii.1 {
|
||||
set where [list]
|
||||
foreach look_three_dots! {. . .} {
|
||||
set colidx [expr int(rand()*($nDim*2+1))-1]
|
||||
if {$colidx<0} {
|
||||
set col ii
|
||||
} else {
|
||||
set col "c$colidx"
|
||||
}
|
||||
set op [lindex $OPS [expr int(rand()*[llength $OPS])]]
|
||||
set val [expr int(rand()*1000)]
|
||||
lappend where "$col $op $val"
|
||||
}
|
||||
set where [join $where " AND "]
|
||||
|
||||
set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"]
|
||||
set t2 [execsql "SELECT * FROM t2 WHERE $where ORDER BY ii"]
|
||||
set rc [expr {$t1 eq $t2}]
|
||||
if {$rc != 1} {
|
||||
puts $where
|
||||
puts $t1
|
||||
puts $t2
|
||||
puts [rtree_treedump db t1]
|
||||
breakpoint
|
||||
set t1 [execsql "SELECT * FROM t1 WHERE $where ORDER BY ii"]
|
||||
exit
|
||||
}
|
||||
set rc
|
||||
} {1}
|
||||
}
|
||||
|
||||
for {set ii 0} {$ii < $::NROW} {incr ii $::NDEL} {
|
||||
#puts [rtree_treedump db t1]
|
||||
do_test rtree2-$nDim.5.$ii.1 {
|
||||
execsql "DELETE FROM t2 WHERE ii <= $::ii"
|
||||
execsql "DELETE FROM t1 WHERE ii <= $::ii"
|
||||
|
||||
set t1 [execsql {SELECT * FROM t1 ORDER BY ii}]
|
||||
set t2 [execsql {SELECT * FROM t2 ORDER BY ii}]
|
||||
set rc [expr {$t1 eq $t2}]
|
||||
if {$rc != 1} {
|
||||
puts $t1
|
||||
puts $t2
|
||||
}
|
||||
set rc
|
||||
} {1}
|
||||
do_test rtree2-$nDim.5.$ii.2 {
|
||||
rtree_check db t1
|
||||
} {0}
|
||||
}
|
||||
|
||||
do_test rtree2-$nDim.6 {
|
||||
execsql {
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
}
|
||||
} {}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user