blob: 6fb32b6d376cf4dd3bb585b68842b326bfdcb2ec [file] [log] [blame]
dan85127522012-07-13 19:26:34 +00001# 2012 July 12
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
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15set testprefix spellfix
16
dan81f07402012-08-07 14:18:18 +000017ifcapable !vtab { finish_test ; return }
18
dan85127522012-07-13 19:26:34 +000019register_spellfix_module db
20
21set vocab {
22rabbi rabbit rabbits rabble rabid rabies raccoon raccoons race raced racer
23racers races racetrack racial racially racing rack racked racket racketeer
24racketeering racketeers rackets racking racks radar radars radial radially
25radian radiance radiant radiantly radiate radiated radiates radiating radiation
26radiations radiator radiators radical radically radicals radices radii radio
27radioactive radioastronomy radioed radiography radioing radiology radios radish
28radishes radium radius radix radon raft rafter rafters rafts rag rage raged
29rages ragged raggedly raggedness raging rags ragweed raid raided raider raiders
30raiding raids rail railed railer railers railing railroad railroaded railroader
31railroaders railroading railroads rails railway railways raiment rain rainbow
32raincoat raincoats raindrop raindrops rained rainfall rainier rainiest raining
33rains rainstorm rainy raise raised raiser raisers raises raisin raising rake
34raked rakes raking rallied rallies rally rallying ram ramble rambler rambles
35rambling ramblings ramification ramifications ramp rampage rampant rampart
36ramps ramrod rams ran ranch ranched rancher ranchers ranches ranching rancid
37random randomization randomize randomized randomizes randomly randomness randy
38rang range ranged rangeland ranger rangers ranges ranging rangy rank ranked
39ranker rankers rankest ranking rankings rankle rankly rankness ranks ransack
40ransacked ransacking ransacks ransom ransomer ransoming ransoms rant ranted
41ranter ranters ranting rants rap rapacious rape raped raper rapes rapid
42rapidity rapidly rapids rapier raping rapport rapprochement raps rapt raptly
43rapture raptures rapturous rare rarely rareness rarer rarest rarity rascal
44rascally rascals rash rasher rashly rashness rasp raspberry rasped rasping
45rasps raster rat rate rated rater raters rates rather ratification ratified
46ratifies ratify ratifying rating ratings ratio ration rational rationale
47rationales rationalities rationality rationalization rationalizations
48rationalize rationalized rationalizes rationalizing rationally rationals
49rationing rations ratios rats rattle rattled rattler rattlers rattles
50rattlesnake rattlesnakes rattling raucous ravage ravaged ravager ravagers
51ravages ravaging rave raved raven ravening ravenous ravenously ravens raves
52ravine ravines raving ravings raw rawer rawest rawly rawness ray rays raze
53razor razors re reabbreviate reabbreviated reabbreviates reabbreviating reach
54reachability reachable reachably reached reacher reaches reaching reacquired
55react reacted reacting reaction reactionaries reactionary reactions reactivate
56reactivated reactivates reactivating reactivation reactive reactively
57reactivity reactor reactors reacts read readability readable reader readers
58readied readier readies readiest readily readiness reading readings readjusted
59readout readouts reads ready readying real realest realign realigned realigning
60realigns realism realist realistic realistically realists realities reality
61}
62
63do_test 1.1 {
64 execsql { CREATE VIRTUAL TABLE t1 USING spellfix1 }
65 foreach word $vocab {
66 execsql { INSERT INTO t1(word) VALUES($word) }
67 }
68} {}
69
70foreach {tn word res} {
drhe0d058c2012-08-31 14:55:05 +000071 1 raxpi* {rasping 5 rasped 5 ragweed 5 raspberry 6 rasp 4}
drh342ced42012-08-15 16:43:07 +000072 2 ril* {rail 4 railed 4 railer 4 railers 4 railing 4}
73 3 rilis* {realism 6 realist 6 realistic 6 realistically 6 realists 6}
74 4 reail* {real 3 realest 3 realign 3 realigned 3 realigning 3}
75 5 ras* {rascal 3 rascally 3 rascals 3 rash 3 rasher 3}
dan85127522012-07-13 19:26:34 +000076 6 realistss* {realists 8 realigns 8 realistic 9 realistically 9 realest 7}
77 7 realistss {realists 8 realist 7 realigns 8 realistic 9 realest 7}
78 8 rllation* {realities 9 reality 7 rallied 7 railed 4}
drh342ced42012-08-15 16:43:07 +000079 9 renstom* {rainstorm 8 ransom 6 ransomer 6 ransoming 6 ransoms 6}
dan85127522012-07-13 19:26:34 +000080} {
81 do_execsql_test 1.2.$tn {
drh342ced42012-08-15 16:43:07 +000082 SELECT word, matchlen FROM t1 WHERE word MATCH $word
83 ORDER BY score, word LIMIT 5
dan85127522012-07-13 19:26:34 +000084 } $res
85}
86
87
88do_execsql_test 2.1 {
89 CREATE VIRTUAL TABLE t2 USING spellfix1;
90 INSERT INTO t2 (word, soundslike) VALUES('school', 'skuul');
91 INSERT INTO t2 (word, soundslike) VALUES('psalm', 'sarm');
92 SELECT word, matchlen FROM t2 WHERE word MATCH 'sar*' LIMIT 5;
93} {psalm 4}
94
95do_execsql_test 2.2 {
96 SELECT word, matchlen FROM t2 WHERE word MATCH 'skol*' LIMIT 5;
97} {school 6}
98
99set vocab {
100kangaroo kanji kappa karate keel keeled keeling keels keen keener keenest
101keenly keenness keep keeper keepers keeping keeps ken kennel kennels kept
102kerchief kerchiefs kern kernel kernels kerosene ketchup kettle
103kettles key keyboard keyboards keyed keyhole keying keynote keypad keypads keys
104keystroke keystrokes keyword keywords kick kicked kicker kickers kicking
105kickoff kicks kid kidded kiddie kidding kidnap kidnapper kidnappers kidnapping
106kidnappings kidnaps kidney kidneys kids kill killed killer killers killing
107killingly killings killjoy kills kilobit kilobits kiloblock kilobyte kilobytes
108kilogram kilograms kilohertz kilohm kilojoule kilometer kilometers kiloton
109kilovolt kilowatt kiloword kimono kin kind kinder kindergarten kindest
110kindhearted kindle kindled kindles kindling kindly kindness kindred kinds
111kinetic king kingdom kingdoms kingly kingpin kings kink kinky kinship kinsman
112kiosk kiss kissed kisser kissers kisses kissing kit kitchen kitchenette
113kitchens kite kited kites kiting kits kitten kittenish kittens kitty klaxon
114kludge kludges klystron knack knapsack knapsacks knave knaves knead kneads knee
115kneecap kneed kneeing kneel kneeled kneeling kneels knees knell knells knelt
116knew knife knifed knifes knifing knight knighted knighthood knighting knightly
117knights knit knits knives knob knobs knock knockdown knocked knocker knockers
118knocking knockout knocks knoll knolls knot knots knotted knotting know knowable
119knower knowhow knowing knowingly knowledge knowledgeable known knows knuckle
120knuckled knuckles koala kosher kudo
121}
122
123do_execsql_test 3.1 {
124 CREATE TABLE costs(iLang, cFrom, cTo, iCost);
125 INSERT INTO costs VALUES(0, 'a', 'e', 1);
126 INSERT INTO costs VALUES(0, 'e', 'i', 1);
127 INSERT INTO costs VALUES(0, 'i', 'o', 1);
128 INSERT INTO costs VALUES(0, 'o', 'u', 1);
129 INSERT INTO costs VALUES(0, 'u', 'a', 1);
130 CREATE VIRTUAL TABLE t3 USING spellfix1(edit_cost_table=costs);
131}
132
133do_test 3.2 {
134 foreach w $vocab {
135 execsql { INSERT INTO t3(word) VALUES($w) }
136 }
137} {}
138
dan85127522012-07-13 19:26:34 +0000139foreach {tn word res} {
drhc16eb692012-08-14 17:29:27 +0000140 1 kos* {kosher 3 kiosk 4 kudo 2 kiss 3 kissed 3}
141 2 kellj* {killjoy 5 kill 4 killed 4 killer 4 killers 4}
dan85127522012-07-13 19:26:34 +0000142 3 kellj {kill 4 kills 5 killjoy 7 keel 4 killed 6}
143} {
drh5cee8a72013-02-19 11:51:27 +0000144 do_execsql_test 3.2.$tn {
drhc16eb692012-08-14 17:29:27 +0000145 SELECT word, matchlen FROM t3 WHERE word MATCH $word
146 ORDER BY score, word LIMIT 5
dan85127522012-07-13 19:26:34 +0000147 } $res
drh5cee8a72013-02-19 11:51:27 +0000148}
149
150do_execsql_test 4.0 {
151 INSERT INTO t3(command) VALUES('edit_cost_table=NULL');
152}
153foreach {tn word res} {
154 1 kosher {kosher 0 kisser 51 kissers 76 kissed 126 kisses 126}
155 2 kellj {keels 60 killjoy 68 kills 80 keel 120 kill 125}
156 3 kashar {kosher 80 kisser 91 kissers 116 kissed 166 kisses 166}
157} {
158 do_execsql_test 4.1.$tn {
159 SELECT word, distance FROM t3 WHERE word MATCH $word
160 ORDER BY score, word LIMIT 5
161 } $res
162}
163do_execsql_test 5.0 {
164 CREATE TABLE costs2(iLang, cFrom, cTo, iCost);
165 INSERT INTO costs2 VALUES(0, 'a', 'o', 1);
166 INSERT INTO costs2 VALUES(0, 'e', 'o', 4);
167 INSERT INTO costs2 VALUES(0, 'i', 'o', 8);
168 INSERT INTO costs2 VALUES(0, 'u', 'o', 16);
169 INSERT INTO t3(command) VALUES('edit_cost_table="costs2"');
170}
171
172foreach {tn word res} {
173 1 kasher {kosher 1}
174 2 kesher {kosher 4}
175 3 kisher {kosher 8}
176 4 kosher {kosher 0}
177 5 kusher {kosher 16}
178} {
179 do_execsql_test 5.1.$tn {
180 SELECT word, distance FROM t3 WHERE word MATCH $word
181 ORDER BY score, word LIMIT 1
182 } $res
183}
184
185
dan85127522012-07-13 19:26:34 +0000186
187finish_test