Annotation of embedaddon/sqlite3/test/boundary3.tcl, revision 1.1

1.1     ! misho       1: puts {# 2008 December 11
        !             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 implements regression tests for SQLite library.
        !            12: #
        !            13: # This file is automatically generated from a separate TCL script.
        !            14: # This file seeks to exercise integer boundary values.
        !            15: #
        !            16: # $Id: boundary3.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $
        !            17: 
        !            18: set testdir [file dirname $argv0]
        !            19: source $testdir/tester.tcl
        !            20: 
        !            21: # Many of the boundary tests depend on a working 64-bit implementation.
        !            22: if {![working_64bit_int]} { finish_test; return }
        !            23: }
        !            24: 
        !            25: expr srand(0)
        !            26: 
        !            27: # Generate interesting boundary numbers
        !            28: #
        !            29: foreach x {
        !            30:   0
        !            31:   1
        !            32:   0x7f
        !            33:   0x7fff
        !            34:   0x7fffff
        !            35:   0x7fffffff
        !            36:   0x7fffffffff
        !            37:   0x7fffffffffff
        !            38:   0x7fffffffffffff
        !            39:   0x7fffffffffffffff
        !            40: } {
        !            41:   set x [expr {wide($x)}]
        !            42:   set boundarynum($x) 1
        !            43:   set boundarynum([expr {$x+1}]) 1
        !            44:   set boundarynum([expr {-($x+1)}]) 1
        !            45:   set boundarynum([expr {-($x+2)}]) 1
        !            46:   set boundarynum([expr {$x+$x+1}]) 1
        !            47:   set boundarynum([expr {$x+$x+2}]) 1
        !            48: }
        !            49: set x [expr {wide(127)}]
        !            50: for {set i 1} {$i<=9} {incr i} {
        !            51:   set boundarynum($x) 1
        !            52:   set boundarynum([expr {$x+1}]) 1
        !            53:   set x [expr {wide($x*128 + 127)}]
        !            54: }
        !            55: 
        !            56: # Scramble the $inlist into a random order.
        !            57: #
        !            58: proc scramble {inlist} {
        !            59:   set y {}
        !            60:   foreach x $inlist {
        !            61:     lappend y [list [expr {rand()}] $x]
        !            62:   }
        !            63:   set y [lsort $y]
        !            64:   set outlist {}
        !            65:   foreach x $y {
        !            66:     lappend outlist [lindex $x 1]
        !            67:   }
        !            68:   return $outlist
        !            69: }
        !            70: 
        !            71: # A simple selection sort.  Not trying to be efficient.
        !            72: #
        !            73: proc sort {inlist} {
        !            74:   set outlist {}
        !            75:   set mn [lindex $inlist 0]
        !            76:   foreach x $inlist {
        !            77:     if {$x<$mn} {set mn $x}
        !            78:   }
        !            79:   set outlist $mn
        !            80:   set mx $mn
        !            81:   while {1} {
        !            82:     set valid 0
        !            83:     foreach x $inlist {
        !            84:       if {$x>$mx && (!$valid || $mn>$x)} {
        !            85:         set mn $x
        !            86:         set valid 1
        !            87:       }
        !            88:     }
        !            89:     if {!$valid} break
        !            90:     lappend outlist $mn
        !            91:     set mx $mn
        !            92:   }
        !            93:   return $outlist
        !            94: }
        !            95: 
        !            96: # Reverse the order of a list
        !            97: #
        !            98: proc reverse {inlist} {
        !            99:   set i [llength $inlist]
        !           100:   set outlist {}
        !           101:   for {incr i -1} {$i>=0} {incr i -1} {
        !           102:     lappend outlist [lindex $inlist $i]
        !           103:   }
        !           104:   return $outlist
        !           105: }
        !           106: 
        !           107: set nums1 [scramble [array names boundarynum]]
        !           108: set nums2 [scramble [array names boundarynum]]
        !           109: 
        !           110: set tname boundary3
        !           111: puts "do_test $tname-1.1 \173"
        !           112: puts "  db eval \173"
        !           113: puts "    CREATE TABLE t1(a,x);"
        !           114: set a 0
        !           115: foreach r $nums1 {
        !           116:   incr a
        !           117:   set t1ra($r) $a
        !           118:   set t1ar($a) $r
        !           119:   set x [format %08x%08x [expr {wide($r)>>32}] $r]
        !           120:   set t1rx($r) $x
        !           121:   set t1xr($x) $r
        !           122:   puts "    INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');"
        !           123: }
        !           124: puts "    CREATE INDEX t1i1 ON t1(a);"
        !           125: puts "    CREATE INDEX t1i2 ON t1(x);"
        !           126: puts "  \175"
        !           127: puts "\175 {}"
        !           128: 
        !           129: puts "do_test $tname-1.2 \173"
        !           130: puts "  db eval \173"
        !           131: puts "    SELECT count(*) FROM t1"
        !           132: puts "  \175"
        !           133: puts "\175 {64}"
        !           134: 
        !           135: puts "do_test $tname-1.3 \173"
        !           136: puts "  db eval \173"
        !           137: puts "    CREATE TABLE t2(r,a);"
        !           138: puts "    INSERT INTO t2 SELECT rowid, a FROM t1;"
        !           139: puts "    CREATE INDEX t2i1 ON t2(r);"
        !           140: puts "    CREATE INDEX t2i2 ON t2(a);"
        !           141: puts "    INSERT INTO t2 VALUES(9.22337303685477580800e+18,65);"
        !           142: set t1ra(9.22337303685477580800e+18) 65
        !           143: set t1ar(65) 9.22337303685477580800e+18)
        !           144: puts "    INSERT INTO t2 VALUES(-9.22337303685477580800e+18,66);"
        !           145: set t1ra(-9.22337303685477580800e+18) 66
        !           146: set t1ar(66) -9.22337303685477580800e+18)
        !           147: puts "    SELECT count(*) FROM t2;"
        !           148: puts "  \175"
        !           149: puts "\175 {66}"
        !           150: 
        !           151: set nums3 $nums2
        !           152: lappend nums3 9.22337303685477580800e+18
        !           153: lappend nums3 -9.22337303685477580800e+18
        !           154: 
        !           155: set i 0
        !           156: foreach r $nums3 {
        !           157:   incr i
        !           158: 
        !           159:   set r5 $r.5
        !           160:   set r0 $r.0
        !           161:   if {abs($r)<9.22337203685477580800e+18} {
        !           162:     set x $t1rx($r)
        !           163:     set a $t1ra($r)
        !           164:     puts "do_test $tname-2.$i.1 \173"
        !           165:     puts "  db eval \173"
        !           166:     puts "    SELECT t1.* FROM t1, t2 WHERE t1.rowid=$r AND t2.a=t1.a"
        !           167:     puts "  \175"
        !           168:     puts "\175 {$a $x}"
        !           169:     puts "do_test $tname-2.$i.2 \173"
        !           170:     puts "  db eval \173"
        !           171:     puts "    SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='$x'"
        !           172:     puts "  \175"
        !           173:     puts "\175 {$r $a}"
        !           174:     puts "do_test $tname-2.$i.3 \173"
        !           175:     puts "  db eval \173"
        !           176:     puts "    SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=$a"
        !           177:     puts "  \175"
        !           178:     puts "\175 {$r $x}"
        !           179:   }
        !           180: 
        !           181:   foreach op {> >= < <=} subno {gt ge lt le} {
        !           182: 
        !           183:     ################################################################ 2.x.y.1
        !           184:     set rset {}
        !           185:     set aset {}
        !           186:     foreach rx $nums2 {
        !           187:       if "\$rx $op \$r" {
        !           188:         lappend rset $rx
        !           189:         lappend aset $t1ra($rx)
        !           190:       }
        !           191:     }
        !           192:     puts "do_test $tname-2.$i.$subno.1 \173"
        !           193:     puts "  db eval \173"
        !           194:     puts "    SELECT t2.a FROM t1 JOIN t2 USING(a)"
        !           195:     puts "     WHERE t1.rowid $op $r ORDER BY t2.a"
        !           196:     puts "  \175"
        !           197:     puts "\175 {[sort $aset]}"
        !           198:   
        !           199:     ################################################################ 2.x.y.2
        !           200:     puts "do_test $tname-2.$i.$subno.2 \173"
        !           201:     puts "  db eval \173"
        !           202:     puts "    SELECT t2.a FROM t2 NATURAL JOIN t1"
        !           203:     puts "     WHERE t1.rowid $op $r ORDER BY t1.a DESC"
        !           204:     puts "  \175"
        !           205:     puts "\175 {[reverse [sort $aset]]}"
        !           206: 
        !           207: 
        !           208:     ################################################################ 2.x.y.3
        !           209:     set ax $t1ra($r)
        !           210:     set aset {}
        !           211:     foreach rx [sort $rset] {
        !           212:       lappend aset $t1ra($rx)
        !           213:     }
        !           214:     puts "do_test $tname-2.$i.$subno.3 \173"
        !           215:     puts "  db eval \173"
        !           216:     puts "    SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
        !           217:     puts "     WHERE t2.a=$ax"
        !           218:     puts "     ORDER BY t1.rowid"
        !           219:     puts "  \175"
        !           220:     puts "\175 {$aset}"
        !           221:   
        !           222:     ################################################################ 2.x.y.4
        !           223:     set aset {}
        !           224:     foreach rx [reverse [sort $rset]] {
        !           225:       lappend aset $t1ra($rx)
        !           226:     }
        !           227:     puts "do_test $tname-2.$i.$subno.4 \173"
        !           228:     puts "  db eval \173"
        !           229:     puts "    SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
        !           230:     puts "     WHERE t2.a=$ax"
        !           231:     puts "     ORDER BY t1.rowid DESC"
        !           232:     puts "  \175"
        !           233:     puts "\175 {$aset}"
        !           234:   
        !           235:     ################################################################ 2.x.y.5
        !           236:     set aset {}
        !           237:     set xset {}
        !           238:     foreach rx $rset {
        !           239:       lappend xset $t1rx($rx)
        !           240:     }
        !           241:     foreach x [sort $xset] {
        !           242:       set rx $t1xr($x)
        !           243:       lappend aset $t1ra($rx)
        !           244:     }
        !           245:     puts "do_test $tname-2.$i.$subno.5 \173"
        !           246:     puts "  db eval \173"
        !           247:     puts "    SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
        !           248:     puts "     WHERE t2.a=$ax"
        !           249:     puts "     ORDER BY x"
        !           250:     puts "  \175"
        !           251:     puts "\175 {$aset}"
        !           252:   
        !           253:     ################################################################ 2.x.y.10
        !           254:     if {[string length $r5]>15} continue
        !           255:     set rset {}
        !           256:     set aset {}
        !           257:     foreach rx $nums2 {
        !           258:       if "\$rx $op \$r0" {
        !           259:         lappend rset $rx
        !           260:       }
        !           261:     }
        !           262:     foreach rx [sort $rset] {
        !           263:       lappend aset $t1ra($rx)
        !           264:     }
        !           265:     puts "do_test $tname-2.$i.$subno.10 \173"
        !           266:     puts "  db eval \173"
        !           267:     puts "    SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)"
        !           268:     puts "     WHERE t2.a=$ax"
        !           269:     puts "     ORDER BY t1.rowid"
        !           270:     puts "  \175"
        !           271:     puts "\175 {$aset}"
        !           272:   
        !           273:     ################################################################ 2.x.y.11
        !           274:     set aset {}
        !           275:     foreach rx [reverse [sort $rset]] {
        !           276:       lappend aset $t1ra($rx)
        !           277:     }
        !           278:     puts "do_test $tname-2.$i.$subno.11 \173"
        !           279:     puts "  db eval \173"
        !           280:     puts "    SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)"
        !           281:     puts "     WHERE t2.a=$ax"
        !           282:     puts "     ORDER BY t1.rowid DESC"
        !           283:     puts "  \175"
        !           284:     puts "\175 {$aset}"
        !           285:   }
        !           286:   
        !           287: }
        !           288: 
        !           289: 
        !           290: puts {finish_test}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>