xref: /sqlite-3.40.0/test/sort.test (revision 7c68d60b)
1# 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#   [email protected]
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 the CREATE TABLE statement.
25#
26# $Id: sort.test,v 1.1 2000/06/07 00:12:25 drh Exp $
27
28set testdir [file dirname $argv0]
29source $testdir/tester.tcl
30
31# Create a bunch of data to sort against
32#
33do_test sort-1.0 {
34  set fd [open data.txt w]
35  puts $fd "1\tone\t0\tI\t3.141592653"
36  puts $fd "2\ttwo\t1\tII\t2.15"
37  puts $fd "3\tthree\t1\tIII\t4221.0"
38  puts $fd "4\tfour\t2\tIV\t-0.0013442"
39  puts $fd "5\tfive\t2\tV\t-11"
40  puts $fd "6\tsix\t2\tVI\t0.123"
41  puts $fd "7\tseven\t2\tVII\t123.0"
42  puts $fd "8\teight\t3\tVIII\t-1.6"
43  close $fd
44  execsql {
45    CREATE TABLE t1(
46       n int,
47       v varchar(10),
48       log int,
49       roman varchar(10),
50       flt real
51    );
52    COPY t1 FROM 'data.txt'
53  }
54  file delete data.txt
55  execsql {SELECT count(*) FROM t1}
56} {8}
57
58do_test sort-1.1 {
59  execsql {SELECT n FROM t1 ORDER BY n}
60} {1 2 3 4 5 6 7 8}
61do_test sort-1.2 {
62  execsql {SELECT n FROM t1 ORDER BY n DESC}
63} {8 7 6 5 4 3 2 1}
64do_test sort-1.3a {
65  execsql {SELECT v FROM t1 ORDER BY v}
66} {eight five four one seven six three two}
67do_test sort-1.3b {
68  execsql {SELECT n FROM t1 ORDER BY v}
69} {8 5 4 1 7 6 3 2}
70do_test sort-1.4 {
71  execsql {SELECT n FROM t1 ORDER BY v DESC}
72} {2 3 6 7 1 4 5 8}
73do_test sort-1.5 {
74  execsql {SELECT flt FROM t1 ORDER BY flt}
75} {-11 -1.6 -0.0013442 0.123 2.15 3.141592653 123.0 4221.0}
76do_test sort-1.6 {
77  execsql {SELECT flt FROM t1 ORDER BY flt DESC}
78} {4221.0 123.0 3.141592653 2.15 0.123 -0.0013442 -1.6 -11}
79do_test sort-1.7 {
80  execsql {SELECT roman FROM t1 ORDER BY roman}
81} {I II III IV V VI VII VIII}
82do_test sort-1.8 {
83  execsql {SELECT n FROM t1 ORDER BY log, flt}
84} {1 2 3 5 4 6 7 8}
85do_test sort-1.9 {
86  execsql {SELECT n FROM t1 ORDER BY log, flt DESC}
87} {1 3 2 7 6 4 5 8}
88do_test sort-1.10 {
89  execsql {SELECT n FROM t1 ORDER BY log DESC, flt}
90} {8 5 4 6 7 2 3 1}
91do_test sort-1.11 {
92  execsql {SELECT n FROM t1 ORDER BY log DESC, flt DESC}
93} {8 7 6 4 5 3 2 1}
94
95finish_test
96