github.com/vench/word_index@v0.3.1/index_test.go (about) 1 package word_index 2 3 import ( 4 "testing" 5 ) 6 7 var ( 8 documents = []string{ 9 `Sorry. We’re having trouble getting your pages back.`, 10 `Наши рестораны это необычный формат: открытая кухня, блюда со всего света, фермерские продукты, уют и дружеская атмосфера.`, 11 `If that address is correct, here are three other things you can try: Try again later. Check your network connection. If you are connected but behind a firewall, check that Firefox has permission to access the Web.`, 12 `Still not able to restore your session? Sometimes a tab is causing the issue. View previous tabs, remove the checkmark from the tabs you don’t need to recover, and then restore.`, 13 `We are having trouble restoring your last browsing session. Select Restore Session to try again.`, 14 `Docker supports multi-stage builds, meaning docker will build in one container and you can copy the build artifacts to final image.`, 15 `Нет подключения к Интернету`, 16 `В качестве исходных данных будет использована статистика из Яндекс.Метрики. DataLens автоматически создаст дашборд на основе счетчика Метрики с подборкой графиков, а вы сможете отредактировать его по своему усмотрению.`, 17 `Войти в личный кабинет ePayments`, 18 `В математическом анализе и информатике кривая Мортона, Z-последовательность,Z-порядок, кривая Лебега, порядок Мортона или код Мортона — это функция, которая отображает многомерные данные в одномерные, сохраняя локальность точек данных. Функция была введена в 1966 Гаем Макдональдом Мортоном[1].`, 19 `Our Dockerfile will have two section, first one where we build the binary and the second one which will be our final image. `, 20 `Мы рассмотрим вашу заявку и ответим вам в ближайшее время. Если заявка будет подтверждена, доступ к сервису появится автоматически.`, 21 `If you want to keep your array ordered, you have to shift all of the elements at the right of the deleting indexRegexp by one to the left. Hopefully, this can be done easily in Golang:`, 22 `Данный шаг доступен для пользователей, у которых есть права на какой-либо счетчик Метрики. Если у вас нет прав на счетчик, то откройте готовый дашборд Metriсa и перейдите к шагу 2.`, 23 `Удачное расположение с панорамой Казанского собора, вежливый и приветливый персонал, очень вкусная еда, быстрое обслуживание создали хорошее настроение и комфорт. `, 24 `Ресторан быстрого обслуживания Marketplace (бывшие «Фрикадельки») — это новая, современная интерпретация демократичного ресторана с открытой кухней, линией раздачи «Free flow» и отделом кулинарии.`, 25 `Marketplace – это демократичный ресторан с открытой кухней и живой атмосферой европейского рынка.`, 26 `Георгию Карамзину и Татьяне Самсоновой предъявлено обвинение как посредникам. Изначально и Гоголев, и Карамзин были арестованы, но накануне Якутский городской суд перевел последнего под домашний арест. Самсонова же под домашним арестом изначально.`, 27 `Гоголев — главный обвиняемый по этому делу. По данным следствия, девелопер передал ему взятку в виде прав на недвижимость в строящемся жилом доме на 1491 квадратный метр.`, 28 `Попробуйте сделать следующее: Проверьте сетевые кабели, модем и маршрутизатор. Подключитесь к сети Wi-Fi ещё раз.`, 29 `This is almost identical to the first Makefile we created for our consignment-service, however notice the service names and the ports have changed a little`, 30 `«В этой связи суд отказал в изменении меры пресечения на заключение под стражу, считая выявленные нарушения недостаточными для немедленного изменения меры пресечения», — рассказали в пресс-службе.`, 31 `You can also perform actions on individual containers. This example prints the logs of a container given its ID.`, 32 `Note: Don’t run this on a production server. Also, if you are using swarm services, the containers stop, but Docker creates new ones to keep the service running in its configured state.`, 33 `This first example shows how to run a container using the Docker API. On the command line, you would use the docker run command, but this is just as easy to do from your own apps too.`, 34 `Each of these examples show how to perform a given Docker operation using the Go and Python SDKs and the HTTP API using curl.`, 35 `Create container from the image and expose it by mentioning a port`, 36 `Please consider chucking me a couple of quid for my time and effort.`, 37 `Choosing Go is a wise decision that gives scalability and concurrency for your application and selecting a light weight image like alpine will make the push and pull of the image to registries faster, also small size base gives you minimal operating features to build functional container where you can add/install necessary dependencies in future`, 38 `“Golang” the language created by Google that provides impeccable performance over application that demands concurrency has grabbed a separate spot in the tech community, few well known Inc’s that adopted the language include Facebook, Netflix , Dropbox etc.`, 39 } 40 ) 41 42 // 43 func BenchmarkIndexBin(t *testing.B) { 44 ic := NewIndex() 45 bPlainText(t, ic) 46 } 47 48 // 49 func BenchmarkIndexInterpolation(t *testing.B) { 50 ic := &indexWord{data: []*indexItem{}, binSearch: false} 51 bPlainText(t, ic) 52 } 53 54 // 55 func BenchmarkIndexBinSync(t *testing.B) { 56 bi := NewIndexSync() 57 bPlainText(t, bi) 58 } 59 60 // 61 func bPlainText(t *testing.B, i Index) { 62 i.Add(documents...) 63 64 t.ResetTimer() 65 66 for j := 0; j < t.N; j++ { 67 for _, word := range []string{`from the image and expose it by`, `my time and effort`, `Нет подключения к Интернету`, `Choosing Go is a wise decision`} { 68 i.Find(word) 69 } 70 } 71 } 72 73 // 74 func TestIndexBinSync(t *testing.T) { 75 bi := NewIndexSync() 76 tIndexPlainText(t, bi) 77 78 bi = NewIndexSync() 79 tIndexMathText(t, bi) 80 } 81 82 // 83 func TestIndexBinSyncAtDocument(t *testing.T) { 84 bi := NewIndexSync() 85 tAtDocument(t, bi) 86 } 87 88 // 89 func TestIndexBin(t *testing.T) { 90 bi := NewIndex() 91 tIndexPlainText(t, bi) 92 93 bi = NewIndex() 94 tIndexMathText(t, bi) 95 } 96 97 // 98 func TestIndexBinAtDocument(t *testing.T) { 99 bi := NewIndex() 100 tAtDocument(t, bi) 101 } 102 103 // 104 func TestIndexInterpolationAtDocument(t *testing.T) { 105 bi := &indexWord{data: []*indexItem{}, binSearch: false} 106 tAtDocument(t, bi) 107 } 108 109 // 110 func TestIndexInterpolation(t *testing.T) { 111 bi := &indexWord{data: []*indexItem{}, binSearch: false} 112 tIndexPlainText(t, bi) 113 114 bi = &indexWord{data: []*indexItem{}, binSearch: false} 115 tIndexMathText(t, bi) 116 } 117 118 // 119 func tAtDocument(t *testing.T, bi Index) { 120 ss := []string{`first str`, ``, `third str`} 121 bi.Add(ss...) 122 123 for i, s := range ss { 124 str, ok := bi.DocumentAt(i) 125 if !ok { 126 t.Fatalf(`Index %d not extists`, i) 127 } 128 if str != s { 129 t.Fatalf(`String not equals: %s %s`, str, s) 130 } 131 } 132 133 _, ok := bi.DocumentAt(len(ss) + 1) 134 if ok { 135 t.Fatalf(`Index %d out of range`, len(ss)+1) 136 } 137 } 138 139 // 140 func tIndexMathText(t *testing.T, i Index) { 141 var ( 142 s1 = `Нет подключения к Интернету` 143 s2 = `Иванова нет на месте` 144 s3 = `Create container from the image and expose it by mentioning a port` 145 ) 146 i.Add( 147 s1, s2, s3, 148 ) 149 tFindNegative(t, i, `и`) 150 tFindNegative(t, i, `Интернет`) 151 tFindPositive(t, i, `Интернет(у)`) 152 tFindPositive(t, i, `Иванов(а|ой|ым)`) 153 tFindNegative(t, i, `contai`) 154 tFindPositive(t, i, `contai(ner)`) 155 tFindPositive(t, i, `contai*`) 156 tFindPositive(t, i, `contai(xxx|*)`) 157 tFindPositive(t, i, `c*`) 158 tFindNegative(t, i, `mentionin`) 159 tFindPositive(t, i, `mentioning*`) 160 tFindPositive(t, i, `m*`) 161 162 d, ok := i.DocumentAt(0) 163 if !ok { 164 t.Fatalf(`Document not found`) 165 } 166 if d != s1 { 167 t.Fatalf(`Error check: %s != %s`, d, s1) 168 } 169 d, ok = i.DocumentAt(1) 170 if !ok { 171 t.Fatalf(`Document not found`) 172 } 173 if d != s2 { 174 t.Fatalf(`Error check: %s != %s`, d, s2) 175 } 176 d, ok = i.DocumentAt(2) 177 if !ok { 178 t.Fatalf(`Document not found`) 179 } 180 if d != s3 { 181 t.Fatalf(`Error check: %s != %s`, d, s3) 182 } 183 184 if i.FindAt(1, `ment*`) == true { 185 t.Fatalf(`Error check`) 186 } 187 if i.FindAt(2, `ment*`) == false { 188 t.Fatalf(`Error check`) 189 } 190 if i.FindAt(2, `mentz*`) == true { 191 t.Fatalf(`Error check`) 192 } 193 } 194 195 // 196 func tIndexPlainText(t *testing.T, i Index) { 197 i.Add( 198 `Нет подключения к Интернету`, 199 `Create container from the image and expose it by mentioning a port`, 200 `Please consider chucking me a couple of quid for my time and effort.`, 201 `You can also perform actions on individual containers. This example prints the logs of a container given its ID.`, 202 ) 203 tFindPositive(t, i, `Нет`) 204 tFindPositive(t, i, `к`) 205 tFindPositive(t, i, `Create`) 206 tFindPositive(t, i, `individual`) 207 tFindPositive(t, i, `This`) 208 tFindPositive(t, i, `eXample`) 209 tFindPositive(t, i, `on`) 210 tFindNegative(t, i, `php`) 211 tFindNegative(t, i, `t`) 212 tFindNegative(t, i, `а`) 213 tFindNegative(t, i, `и`) 214 } 215 216 // 217 func tFindPositive(t *testing.T, i Index, word string) { 218 if i.Find(word) == -1 { 219 t.Fatalf(`Error not find word %s`, word) 220 } 221 } 222 223 // 224 func tFindNegative(t *testing.T, i Index, word string) { 225 if i.Find(word) >= 0 { 226 t.Fatalf(`Error wrong find word %s`, word) 227 } 228 }