blob: 44ee9e312c540cdf0a9d9b32ffed3f3f251d4ac6 [file] [log] [blame]
danbe7721d2016-02-04 17:31:03 +00001# 2016 February 4
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# The focus of the tests is the word-fuzzer virtual table. The tests
12# in this file are slower than those in fuzzer1.test. So this file does
13# not run as part of veryquick.test etc.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19ifcapable !vtab {
20 finish_test
21 return
22}
23
24set ::testprefix fuzzer2
25load_static_extension db fuzzer
26
27#-------------------------------------------------------------------------
28# This test uses a fuzzer table with many rules. There is one rule to
29# map each possible two character string, where characters are lower-case
30# letters used in the English language, to all other possible two character
31# strings. In total, (26^4)-(26^2) mappings (the subtracted term represents
32# the no-op mappings discarded automatically by the fuzzer).
33#
34#
35do_execsql_test 1.1.1 {
36 DROP TABLE IF EXISTS x1;
37 DROP TABLE IF EXISTS x1_rules;
38 CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost);
39}
40puts "This test is slow - perhaps around 7 seconds on an average pc"
41do_test 1.1.2 {
42 set LETTERS {a b c d e f g h i j k l m n o p q r s t u v w x y z}
43 set cost 1
44 db transaction {
45 foreach c1 $LETTERS {
46 foreach c2 $LETTERS {
47 foreach c3 $LETTERS {
48 foreach c4 $LETTERS {
49 db eval {INSERT INTO x1_rules VALUES(0, $c1||$c2, $c3||$c4, $cost)}
50 set cost [expr ($cost%1000) + 1]
51 }
52 }
53 }
54 }
55 db eval {UPDATE x1_rules SET cost = 20 WHERE cost<20 AND cFrom!='xx'}
56 }
57} {}
58
59do_execsql_test 1.2 {
60 SELECT count(*) FROM x1_rules WHERE cTo!=cFrom;
61} [expr 26*26*26*26 - 26*26]
62
63do_execsql_test 1.2.1 {
64 CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules);
65 SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10;
66} {xx hw hx hy hz ia ib ic id ie}
67do_execsql_test 1.2.2 {
68 SELECT cTo FROM x1_rules WHERE cFrom='xx'
69 ORDER BY cost asc, rowid asc LIMIT 9;
70} {hw hx hy hz ia ib ic id ie}
71
72finish_test