add facility for testing random codec failures
[sqlcipher.git] / test / round1.test
blobba2c79eabac6081b6aff8cb76ed5c3f8677810fc
1 # 2019-05-24
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 # Test cases for rounding behavior of floating point values.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix round1
18 expr srand(0)
19 unset -nocomplain iTest
20 for {set iTest 1} {$iTest<=50000} {incr iTest} {
21    set x1 [expr int(rand()*100000)]
22    set x2 [expr int(rand()*100000)+1000*int(rand()*10000)]
23    set n [expr int(rand()*8)+1]
24    set x3 [string range [format %09d $x2] [expr {9-$n}] end]
25    set r $x1.$x3
26    set ans [string trimright $r 0]
27    if {[string match *. $ans]} {set ans ${ans}0}
28    do_test $iTest/$n/${r}4=>$ans {
29      set x [db one "SELECT round(${r}4,$n)"]
30    } $ans
31    set x4 [string range [format %09d [expr {$x2+1}]] [expr {9-$n}] end]
32    if {[string trim $x3 9]==""} {incr x1}
33    set r2 $x1.$x4
34    set ans [string trimright $r2 0]
35    if {[string match *. $ans]} {set ans ${ans}0}
36    do_test $iTest/$n/${r}5=>$ans {
37      set x [db one "SELECT round(${r}5,$n)"]
38    } $ans
41 finish_test