Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/ext/fts5/test/fts5hash.test

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # 2015 April 21
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 #
12 # The tests in this file are focused on the code in fts5_hash.c.
13 #
14
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5hash
17
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
19 ifcapable !fts5 {
20 finish_test
21 return
22 }
23
24 #-------------------------------------------------------------------------
25 # Return a list of tokens (a vocabulary) that all share the same hash
26 # key value. This can be used to test hash collisions.
27 #
28 proc build_vocab1 {args} {
29
30 set O(-nslot) 1024
31 set O(-nword) 20
32 set O(-hash) 88
33 set O(-prefix) ""
34
35 if {[llength $args] % 2} { error "bad args" }
36 array set O2 $args
37 foreach {k v} $args {
38 if {[info exists O($k)]==0} { error "bad option: $k" }
39 set O($k) $v
40 }
41
42 set L [list]
43 while {[llength $L] < $O(-nword)} {
44 set t "$O(-prefix)[random_token]"
45 set h [sqlite3_fts5_token_hash $O(-nslot) $t]
46 if {$O(-hash)==$h} { lappend L $t }
47 }
48 return $L
49 }
50
51 proc random_token {} {
52 set map [list 0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j]
53 set iVal [expr int(rand() * 2000000)]
54 return [string map $map $iVal]
55 }
56
57 proc random_doc {vocab nWord} {
58 set doc ""
59 set nVocab [llength $vocab]
60 for {set i 0} {$i<$nWord} {incr i} {
61 set j [expr {int(rand() * $nVocab)}]
62 lappend doc [lindex $vocab $j]
63 }
64 return $doc
65 }
66
67 set vocab [build_vocab1]
68 db func r random_doc
69
70 do_execsql_test 1.0 {
71 CREATE VIRTUAL TABLE eee USING fts5(e, ee);
72 BEGIN;
73 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100)
74 INSERT INTO eee SELECT r($vocab, 5), r($vocab, 7) FROM ii;
75 INSERT INTO eee(eee) VALUES('integrity-check');
76 COMMIT;
77 INSERT INTO eee(eee) VALUES('integrity-check');
78 }
79
80 set hash [sqlite3_fts5_token_hash 1024 xyz]
81 set vocab [build_vocab1 -prefix xyz -hash $hash]
82 lappend vocab xyz
83
84 do_execsql_test 1.1 {
85 CREATE VIRTUAL TABLE vocab USING fts5vocab(eee, 'row');
86 BEGIN;
87 }
88 do_test 1.2 {
89 for {set i 1} {$i <= 100} {incr i} {
90 execsql { INSERT INTO eee VALUES( r($vocab, 5), r($vocab, 7) ) }
91 }
92 } {}
93
94 do_test 1.2 {
95 db eval { SELECT term, doc FROM vocab } {
96 set nRow [db one {SELECT count(*) FROM eee WHERE eee MATCH $term}]
97 if {$nRow != $doc} {
98 error "term=$term fts5vocab=$doc cnt=$nRow"
99 }
100 }
101 set {} {}
102 } {}
103
104 do_execsql_test 1.3 {
105 COMMIT;
106 INSERT INTO eee(eee) VALUES('integrity-check');
107 }
108
109 finish_test
110
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698