blob: 0c0b902688639b0d8b8acaa18e78abd5f8d69207 [file] [log] [blame]
drh8d2cb142000-05-30 03:28:35 +00001# Copyright (c) 1999, 2000 D. Richard Hipp
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this library; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA 02111-1307, USA.
17#
18# Author contact information:
19# drh@hwaci.com
20# http://www.hwaci.com/drh/
21#
22#***********************************************************************
23# This file implements regression tests for SQLite library. The
24# focus of this file is testing expressions.
25#
drhec86adb2000-05-31 18:33:09 +000026# $Id: expr.test,v 1.3 2000/05/31 18:33:10 drh Exp $
drh8d2cb142000-05-30 03:28:35 +000027
28set testdir [file dirname $argv0]
29source $testdir/tester.tcl
30
31# Create a table to work with.
32#
33execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
34execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')}
35proc test_expr {name settings expr result} {
36 do_test $name [format {
37 execsql {UPDATE test1 SET %s}
38 execsql {SELECT %s FROM test1}
39 } $settings $expr] $result
40}
41
42test_expr expr-1.1 {i1=10, i2=20} {i1+i2} 30
43test_expr expr-1.2 {i1=10, i2=20} {i1-i2} -10
44test_expr expr-1.3 {i1=10, i2=20} {i1*i2} 200
45test_expr expr-1.4 {i1=10, i2=20} {i1/i2} 0.5
46test_expr expr-1.5 {i1=10, i2=20} {i2/i1} 2
47test_expr expr-1.6 {i1=10, i2=20} {i2<i1} 0
48test_expr expr-1.7 {i1=10, i2=20} {i2<=i1} 0
49test_expr expr-1.8 {i1=10, i2=20} {i2>i1} 1
50test_expr expr-1.9 {i1=10, i2=20} {i2>=i1} 1
51test_expr expr-1.10 {i1=10, i2=20} {i2!=i1} 1
52test_expr expr-1.11 {i1=10, i2=20} {i2=i1} 0
53test_expr expr-1.12 {i1=10, i2=20} {i2<>i1} 1
54test_expr expr-1.13 {i1=10, i2=20} {i2==i1} 0
55test_expr expr-1.14 {i1=20, i2=20} {i2<i1} 0
56test_expr expr-1.15 {i1=20, i2=20} {i2<=i1} 1
57test_expr expr-1.16 {i1=20, i2=20} {i2>i1} 0
58test_expr expr-1.17 {i1=20, i2=20} {i2>=i1} 1
59test_expr expr-1.18 {i1=20, i2=20} {i2!=i1} 0
60test_expr expr-1.19 {i1=20, i2=20} {i2=i1} 1
61test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0
62test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1
63test_expr expr-1.22 {i1=1, i2=2, r1=3.0} {i1+i2*r1} {7}
64test_expr expr-1.23 {i1=1, i2=2, r1=3.0} {(i1+i2)*r1} {9}
drh3aadb2e2000-05-31 17:59:25 +000065test_expr expr-1.24 {i1=1, i2=2} {min(i1,i2,i1+i2,i1-i2)} {-1}
66test_expr expr-1.25 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3}
drh8d2cb142000-05-30 03:28:35 +000067
68
drh3aadb2e2000-05-31 17:59:25 +000069test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57
70test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11
71test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782
72test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641
73test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90244
74test_expr expr-2.6 {r1=1.23, r2=2.34} {r2<r1} 0
75test_expr expr-2.7 {r1=1.23, r2=2.34} {r2<=r1} 0
76test_expr expr-2.8 {r1=1.23, r2=2.34} {r2>r1} 1
77test_expr expr-2.9 {r1=1.23, r2=2.34} {r2>=r1} 1
78test_expr expr-2.10 {r1=1.23, r2=2.34} {r2!=r1} 1
79test_expr expr-2.11 {r1=1.23, r2=2.34} {r2=r1} 0
80test_expr expr-2.12 {r1=1.23, r2=2.34} {r2<>r1} 1
81test_expr expr-2.13 {r1=1.23, r2=2.34} {r2==r1} 0
82test_expr expr-2.14 {r1=2.34, r2=2.34} {r2<r1} 0
83test_expr expr-2.15 {r1=2.34, r2=2.34} {r2<=r1} 1
84test_expr expr-2.16 {r1=2.34, r2=2.34} {r2>r1} 0
85test_expr expr-2.17 {r1=2.34, r2=2.34} {r2>=r1} 1
86test_expr expr-2.18 {r1=2.34, r2=2.34} {r2!=r1} 0
87test_expr expr-2.19 {r1=2.34, r2=2.34} {r2=r1} 1
88test_expr expr-2.20 {r1=2.34, r2=2.34} {r2<>r1} 0
89test_expr expr-2.21 {r1=2.34, r2=2.34} {r2==r1} 1
90test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11}
91test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57}
92
drhec86adb2000-05-31 18:33:09 +000093test_expr expr-3.1 {t1='abc', t2='xyz'} {t1<t2} 1
94test_expr expr-3.2 {t1='xyz', t2='abc'} {t1<t2} 0
95test_expr expr-3.3 {t1='abc', t2='abc'} {t1<t2} 0
96test_expr expr-3.4 {t1='abc', t2='xyz'} {t1<=t2} 1
97test_expr expr-3.5 {t1='xyz', t2='abc'} {t1<=t2} 0
98test_expr expr-3.6 {t1='abc', t2='abc'} {t1<=t2} 1
99test_expr expr-3.7 {t1='abc', t2='xyz'} {t1>t2} 0
100test_expr expr-3.8 {t1='xyz', t2='abc'} {t1>t2} 1
101test_expr expr-3.9 {t1='abc', t2='abc'} {t1>t2} 0
102test_expr expr-3.10 {t1='abc', t2='xyz'} {t1>=t2} 0
103test_expr expr-3.11 {t1='xyz', t2='abc'} {t1>=t2} 1
104test_expr expr-3.12 {t1='abc', t2='abc'} {t1>=t2} 1
105test_expr expr-3.13 {t1='abc', t2='xyz'} {t1=t2} 0
106test_expr expr-3.14 {t1='xyz', t2='abc'} {t1=t2} 0
107test_expr expr-3.15 {t1='abc', t2='abc'} {t1=t2} 1
108test_expr expr-3.16 {t1='abc', t2='xyz'} {t1==t2} 0
109test_expr expr-3.17 {t1='xyz', t2='abc'} {t1==t2} 0
110test_expr expr-3.18 {t1='abc', t2='abc'} {t1==t2} 1
111test_expr expr-3.19 {t1='abc', t2='xyz'} {t1<>t2} 1
112test_expr expr-3.20 {t1='xyz', t2='abc'} {t1<>t2} 1
113test_expr expr-3.21 {t1='abc', t2='abc'} {t1<>t2} 0
114test_expr expr-3.22 {t1='abc', t2='xyz'} {t1!=t2} 1
115test_expr expr-3.23 {t1='xyz', t2='abc'} {t1!=t2} 1
116test_expr expr-3.24 {t1='abc', t2='abc'} {t1!=t2} 0
117
118test_expr expr-4.1 {t1='abc', t2='Abc'} {t1<t2} 0
119test_expr expr-4.2 {t1='abc', t2='Abc'} {t1>t2} 1
120test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1<t2} 1
121test_expr expr-4.4 {t1='abc', t2='Bbc'} {t1>t2} 0
122
123test_expr expr-5.1 {t1='abc', t2='xyz'} {t1 LIKE t2} 0
124test_expr expr-5.2 {t1='abc', t2='ABC'} {t1 LIKE t2} 1
125test_expr expr-5.3 {t1='abc', t2='A_C'} {t1 LIKE t2} 1
126test_expr expr-5.4 {t1='abc', t2='abc_'} {t1 LIKE t2} 0
127test_expr expr-5.5 {t1='abc', t2='A%C'} {t1 LIKE t2} 1
128test_expr expr-5.6 {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} 1
129test_expr expr-5.7 {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0
130test_expr expr-5.8 {t1='abxyzzycx', t2='A%C'} {t1 LIKE t2} 0
131
drh8d2cb142000-05-30 03:28:35 +0000132finish_test