The first assert() added in [0ebc65481f4a3e79] is not necessarily true in a
[sqlite.git] / test / boundary4.tcl
blob20f5c9680fb8a7d781187a0ac874a86125c83644
1 puts {# 2008 December 11
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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file is automatically generated from a separate TCL script.
14 # This file seeks to exercise integer boundary values.
16 # $Id: boundary4.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # Many of the boundary tests depend on a working 64-bit implementation.
22 if {![working_64bit_int]} { finish_test; return }
23 ifcapable !altertable { finish_test; return }
26 expr srand(0)
28 # Generate interesting boundary numbers
30 foreach x {
31 0x7f
32 0x7fff
33 0x7fffff
34 0x7fffffff
35 0x7fffffffff
36 0x7fffffffffff
37 0x7fffffffffffff
38 0x7fffffffffffffff
39 } {
40 set x [expr {wide($x)}]
41 set boundarynum($x) 1
42 set boundarynum([expr {$x+1}]) 1
43 set boundarynum([expr {-($x+1)}]) 1
44 set boundarynum([expr {-($x+2)}]) 1
45 set boundarynum([expr {$x+$x+1}]) 1
46 set boundarynum([expr {$x+$x+2}]) 1
48 set x [expr {wide(127)}]
49 for {set i 127} {$i<=9} {incr i} {
50 set boundarynum($x) 1
51 set boundarynum([expr {$x+1}]) 1
52 set x [expr {wide($x*128 + 127)}]
55 # Scramble the $inlist into a random order.
57 proc scramble {inlist} {
58 set y {}
59 foreach x $inlist {
60 lappend y [list [expr {rand()}] $x]
62 set y [lsort $y]
63 set outlist {}
64 foreach x $y {
65 lappend outlist [lindex $x 1]
67 return $outlist
70 # A simple selection sort. Not trying to be efficient.
72 proc sort {inlist} {
73 set outlist {}
74 set mn [lindex $inlist 0]
75 foreach x $inlist {
76 if {$x<$mn} {set mn $x}
78 set outlist $mn
79 set mx $mn
80 while {1} {
81 set valid 0
82 foreach x $inlist {
83 if {$x>$mx && (!$valid || $mn>$x)} {
84 set mn $x
85 set valid 1
88 if {!$valid} break
89 lappend outlist $mn
90 set mx $mn
92 return $outlist
95 # Reverse the order of a list
97 proc reverse {inlist} {
98 set i [llength $inlist]
99 set outlist {}
100 for {incr i -1} {$i>=0} {incr i -1} {
101 lappend outlist [lindex $inlist $i]
103 return $outlist
106 set nums1 [scramble [array names boundarynum]]
107 set nums2 [scramble [array names boundarynum]]
109 set tname boundary4
110 puts "do_test $tname-1.1 \173"
111 puts " db eval \173"
112 puts " CREATE TABLE t1(a,x);"
113 set a 0
114 set all_rowid {}
115 set all_a {}
116 set all_x {}
117 foreach r $nums1 {
118 incr a
119 set t1ra($r) $a
120 set t1ar($a) $r
121 set x [format %08x%08x [expr {wide($r)>>32}] $r]
122 set t1rx($r) $x
123 set t1xr($x) $r
124 puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');"
125 lappend all_rowid $r
126 lappend all_a $a
127 lappend all_x $x
129 puts " CREATE INDEX t1i1 ON t1(a);"
130 puts " CREATE INDEX t1i2 ON t1(x);"
131 puts " \175"
132 puts "\175 {}"
134 puts "do_test $tname-1.2 \173"
135 puts " db eval \173"
136 puts " SELECT count(*) FROM t1"
137 puts " \175"
138 puts "\175 {[llength $nums1]}"
140 proc maketest {tnum sql answer} {
141 puts "do_test $::tname-$tnum \173"
142 puts " db eval \173"
143 puts " $sql"
144 puts " \175"
145 puts "\175 {$answer}"
148 set ans {}
149 foreach r [sort $all_rowid] {
150 lappend ans $r $t1ra($r) $t1rx($r)
152 maketest 1.3 {SELECT rowid, a, x FROM t1 ORDER BY +rowid} $ans
153 maketest 1.4 {SELECT rowid, a, x FROM t1 ORDER BY rowid} $ans
155 set ans {}
156 foreach r [reverse [sort $all_rowid]] {
157 lappend ans $r $t1ra($r) $t1rx($r)
159 maketest 1.5 {SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC} $ans
160 maketest 1.6 {SELECT rowid, a, x FROM t1 ORDER BY rowid DESC} $ans
162 set ans {}
163 foreach a [sort $all_a] {
164 set r $t1ar($a)
165 lappend ans $r $a $t1rx($r)
167 maketest 1.7 {SELECT rowid, a, x FROM t1 ORDER BY +a} $ans
168 maketest 1.8 {SELECT rowid, a, x FROM t1 ORDER BY a} $ans
170 set ans {}
171 foreach a [reverse [sort $all_a]] {
172 set r $t1ar($a)
173 lappend ans $r $a $t1rx($r)
175 maketest 1.9 {SELECT rowid, a, x FROM t1 ORDER BY +a DESC} $ans
176 maketest 1.10 {SELECT rowid, a, x FROM t1 ORDER BY a DESC} $ans
178 set ans {}
179 foreach x [sort $all_x] {
180 set r $t1xr($x)
181 lappend ans $r $t1ra($r) $x
183 maketest 1.11 {SELECT rowid, a, x FROM t1 ORDER BY +x} $ans
184 maketest 1.12 {SELECT rowid, a, x FROM t1 ORDER BY x} $ans
186 set ans {}
187 foreach x [reverse [sort $all_x]] {
188 set r $t1xr($x)
189 lappend ans $r $t1ra($r) $x
191 maketest 1.13 {SELECT rowid, a, x FROM t1 ORDER BY +x DESC} $ans
192 maketest 1.14 {SELECT rowid, a, x FROM t1 ORDER BY x DESC} $ans
194 maketest 2.1 {UPDATE t1 SET rowid=a, a=rowid} {}
196 set ans {}
197 foreach r [sort $all_rowid] {
198 lappend ans $r $t1ra($r) $t1rx($r)
200 maketest 2.3 {SELECT a, rowid, x FROM t1 ORDER BY +a} $ans
201 maketest 2.4 {SELECT a, rowid, x FROM t1 ORDER BY a} $ans
203 set ans {}
204 foreach r [reverse [sort $all_rowid]] {
205 lappend ans $r $t1ra($r) $t1rx($r)
207 maketest 2.5 {SELECT a, rowid, x FROM t1 ORDER BY +a DESC} $ans
208 maketest 2.6 {SELECT a, rowid, x FROM t1 ORDER BY a DESC} $ans
210 set ans {}
211 foreach a [sort $all_a] {
212 set r $t1ar($a)
213 lappend ans $r $a $t1rx($r)
215 maketest 2.7 {SELECT a, rowid, x FROM t1 ORDER BY +rowid} $ans
216 maketest 2.8 {SELECT a, rowid, x FROM t1 ORDER BY rowid} $ans
218 set ans {}
219 foreach a [reverse [sort $all_a]] {
220 set r $t1ar($a)
221 lappend ans $r $a $t1rx($r)
223 maketest 2.9 {SELECT a, rowid, x FROM t1 ORDER BY +rowid DESC} $ans
224 maketest 2.10 {SELECT a, rowid, x FROM t1 ORDER BY rowid DESC} $ans
226 set ans {}
227 foreach x [sort $all_x] {
228 set r $t1xr($x)
229 lappend ans $r $t1ra($r) $x
231 maketest 2.11 {SELECT a, rowid, x FROM t1 ORDER BY +x} $ans
232 maketest 2.12 {SELECT a, rowid, x FROM t1 ORDER BY x} $ans
234 set ans {}
235 foreach x [reverse [sort $all_x]] {
236 set r $t1xr($x)
237 lappend ans $r $t1ra($r) $x
239 maketest 2.13 {SELECT a, rowid, x FROM t1 ORDER BY +x DESC} $ans
240 maketest 2.14 {SELECT a, rowid, x FROM t1 ORDER BY x DESC} $ans
242 maketest 3.1 {UPDATE t1 SET rowid=a, a=rowid} {}
243 maketest 3.2 {ALTER TABLE t1 ADD COLUMN z; UPDATE t1 SET z=zeroblob(600)} {}
245 set ans {}
246 foreach r [sort $all_rowid] {
247 lappend ans $r $t1ra($r) $t1rx($r)
249 maketest 3.3 {SELECT rowid, a, x FROM t1 ORDER BY +rowid} $ans
250 maketest 3.4 {SELECT rowid, a, x FROM t1 ORDER BY rowid} $ans
252 set ans {}
253 foreach r [reverse [sort $all_rowid]] {
254 lappend ans $r $t1ra($r) $t1rx($r)
256 maketest 3.5 {SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC} $ans
257 maketest 3.6 {SELECT rowid, a, x FROM t1 ORDER BY rowid DESC} $ans
259 set ans {}
260 foreach a [sort $all_a] {
261 set r $t1ar($a)
262 lappend ans $r $a $t1rx($r)
264 maketest 3.7 {SELECT rowid, a, x FROM t1 ORDER BY +a} $ans
265 maketest 3.8 {SELECT rowid, a, x FROM t1 ORDER BY a} $ans
267 set ans {}
268 foreach a [reverse [sort $all_a]] {
269 set r $t1ar($a)
270 lappend ans $r $a $t1rx($r)
272 maketest 3.9 {SELECT rowid, a, x FROM t1 ORDER BY +a DESC} $ans
273 maketest 3.10 {SELECT rowid, a, x FROM t1 ORDER BY a DESC} $ans
275 set ans {}
276 foreach x [sort $all_x] {
277 set r $t1xr($x)
278 lappend ans $r $t1ra($r) $x
280 maketest 3.11 {SELECT rowid, a, x FROM t1 ORDER BY +x} $ans
281 maketest 3.12 {SELECT rowid, a, x FROM t1 ORDER BY x} $ans
283 set ans {}
284 foreach x [reverse [sort $all_x]] {
285 set r $t1xr($x)
286 lappend ans $r $t1ra($r) $x
288 maketest 3.13 {SELECT rowid, a, x FROM t1 ORDER BY +x DESC} $ans
289 maketest 3.14 {SELECT rowid, a, x FROM t1 ORDER BY x DESC} $ans
292 maketest 4.1 {UPDATE t1 SET rowid=a, a=rowid, x=z, z=x} {}
294 set ans {}
295 foreach r [sort $all_rowid] {
296 lappend ans $r $t1ra($r) $t1rx($r)
298 maketest 4.3 {SELECT a, rowid, z FROM t1 ORDER BY +a} $ans
299 maketest 4.4 {SELECT a, rowid, z FROM t1 ORDER BY a} $ans
301 set ans {}
302 foreach r [reverse [sort $all_rowid]] {
303 lappend ans $r $t1ra($r) $t1rx($r)
305 maketest 4.5 {SELECT a, rowid, z FROM t1 ORDER BY +a DESC} $ans
306 maketest 4.6 {SELECT a, rowid, z FROM t1 ORDER BY a DESC} $ans
308 set ans {}
309 foreach a [sort $all_a] {
310 set r $t1ar($a)
311 lappend ans $r $a $t1rx($r)
313 maketest 4.7 {SELECT a, rowid, z FROM t1 ORDER BY +rowid} $ans
314 maketest 4.8 {SELECT a, rowid, z FROM t1 ORDER BY rowid} $ans
316 set ans {}
317 foreach a [reverse [sort $all_a]] {
318 set r $t1ar($a)
319 lappend ans $r $a $t1rx($r)
321 maketest 4.9 {SELECT a, rowid, z FROM t1 ORDER BY +rowid DESC} $ans
322 maketest 4.10 {SELECT a, rowid, z FROM t1 ORDER BY rowid DESC} $ans
324 set ans {}
325 foreach x [sort $all_x] {
326 set r $t1xr($x)
327 lappend ans $r $t1ra($r) $x
329 maketest 4.11 {SELECT a, rowid, z FROM t1 ORDER BY +z} $ans
330 maketest 4.12 {SELECT a, rowid, z FROM t1 ORDER BY z} $ans
332 set ans {}
333 foreach x [reverse [sort $all_x]] {
334 set r $t1xr($x)
335 lappend ans $r $t1ra($r) $x
337 maketest 4.13 {SELECT a, rowid, z FROM t1 ORDER BY +z DESC} $ans
338 maketest 4.14 {SELECT a, rowid, z FROM t1 ORDER BY z DESC} $ans
340 puts {finish_test}