How to use EqualInt method of test Package

Best Go-testdeep code snippet using test.EqualInt

unit_test.go

Source:unit_test.go Github

copy

Full Screen

...11 v2 := "There!"12 t1 := t0.Set(k1, v1)13 t2 := t1.Set(k2, v2)14 t3 := t2.Del(k1)15 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")16 assert.EqualInt(t, 1, t1.Depth(), "t1.Depth()")17 assert.EqualInt(t, 2, t2.Len(), "t2.Len()")18 assert.EqualInt(t, 4, t2.Depth(), "t2.Depth()")19 assert.EqualInt(t, 1, t3.Len(), "t3.Len()")20 assert.EqualInt(t, 1, t3.Depth(), "t3.Depth()")21 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")22 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")23 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")24 assert.Equal(t, v2, t3.Get(k2), "t3.Get(k2)")25}26func TestGetDeep(t *testing.T) {27 t0 := Map.WithHasher(Bole32)28 k1 := "He1lo"29 v1 := "World!"30 k2 := "He2lo"31 v2 := "There!"32 t1 := t0.Set(k1, v1)33 t2 := t1.Set(k2, v2)34 r2 := t2.Get(k2)35 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")36 assert.EqualInt(t, 2, t2.Len(), "t2.Len()")37 assert.EqualInt(t, 4, t2.Depth(), "t2.Depth()")38 assert.Equal(t, v2, r2, "t2.Get(k2)")39}40func TestPutDeep(t *testing.T) {41 t0 := Map.WithHasher(Bole32)42 k1 := "He1lo"43 v1 := "World!"44 k2 := "He2lo"45 v2 := "There!"46 t1 := t0.Set(k1, v1)47 t2 := t1.Set(k2, v2)48 t3 := t1.Set(k1, v2)49 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")50 assert.EqualInt(t, 1, t1.Depth(), "t1.Depth()")51 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")52 assert.EqualInt(t, 2, t2.Len(), "t2.Len()")53 assert.EqualInt(t, 4, t2.Depth(), "t2.Depth()")54 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")55 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")56 assert.EqualInt(t, 1, t3.Len(), "t3.Len()")57 assert.EqualInt(t, 1, t3.Depth(), "t3.Depth()")58 assert.Equal(t, v2, t3.Get(k1), "t3.Get(k1)")59}60func TestDelCollision(t *testing.T) {61 t0 := Map.WithHasher(Bole32)62 k1 := "Hello1"63 v1 := "World!"64 k2 := "Hello2"65 v2 := "There!"66 k3 := "Hello3"67 v3 := "Gophers!"68 t1 := t0.Set(k1, v1)69 t2 := t1.Set(k2, v2)70 t3 := t2.Del(k2)71 t4 := t2.Del(k1)72 t5 := t2.Set(k3, v3)73 t6 := t5.Del(k2)74 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")75 assert.EqualInt(t, 2, t2.Len(), "t2.Len()")76 assert.EqualInt(t, 8, t2.Depth(), "t2.Depth()")77 assert.Equal(t, true, t2.Has(k1), "t2.Has(k1)")78 assert.Equal(t, true, t2.Has(k2), "t2.Has(k2)")79 assert.EqualInt(t, 1, t3.Depth(), "t3.Depth()")80 assert.Equal(t, true, t3.Has(k1), "t3.Has(k1)")81 assert.Equal(t, false, t3.Has(k2), "t3.Has(k2)")82 assert.EqualInt(t, 1, t4.Depth(), "t4.Depth()")83 assert.Equal(t, false, t4.Has(k1), "t4.Has(k1)")84 assert.Equal(t, true, t4.Has(k2), "t4.Has(k2)")85 assert.EqualInt(t, 8, t5.Depth(), "t5.Depth()")86 assert.Equal(t, v1, t5.Get(k1), "t5.Get(k1)")87 assert.Equal(t, v2, t5.Get(k2), "t5.Get(k2)")88 assert.Equal(t, v3, t5.Get(k3), "t5.Get(k3)")89 assert.EqualInt(t, 2, t6.Len(), "t6.Len()")90 assert.EqualInt(t, 8, t6.Depth(), "t6.Depth()")91 assert.Equal(t, v1, t6.Get(k1), "t6.Get(k1)")92 assert.Equal(t, false, t6.Has(k2), "t6.Has(k2)")93 assert.Equal(t, v3, t6.Get(k3), "t6.Get(k3)")94}95func TestGetCollision(t *testing.T) {96 t0 := Map.WithHasher(Bole32)97 k1 := "Hello1"98 v1 := "World!"99 k2 := "Hello2"100 v2 := "There!"101 t1 := t0.Set(k1, v1)102 t2 := t1.Set(k2, v2)103 r2 := t2.Get(k2)104 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")105 assert.EqualInt(t, 2, t2.Len(), "t2.Len()")106 assert.EqualInt(t, 8, t2.Depth(), "t2.Depth()")107 assert.Equal(t, v2, r2, "t2.Get(k2)")108}109func TestPutCollision(t *testing.T) {110 t0 := Map.WithHasher(Bole32)111 k1 := "Hello1"112 v1 := "World!"113 k2 := "Hello2"114 v2 := "There!"115 k3 := "Hela"116 v3 := "All!"117 k4 := "Hella"118 v4 := "Strange!"119 t1 := t0.Set(k1, v1)120 t2 := t1.Set(k2, v2)121 t3 := t2.Set(k3, v3)122 t4 := t3.Set(k4, v4)123 t5 := t4.Set(k1, v2)124 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")125 assert.EqualInt(t, 1, t1.Depth(), "t1.Depth()")126 assert.EqualInt(t, 2, t2.Len(), "t2.Len()")127 assert.EqualInt(t, 8, t2.Depth(), "t2.Depth()")128 assert.EqualInt(t, 3, t3.Len(), "t3.Len()")129 assert.EqualInt(t, 8, t3.Depth(), "t3.Depth()")130 assert.EqualInt(t, 4, t4.Len(), "t4.Len()")131 assert.EqualInt(t, 8, t4.Depth(), "t4.Depth()")132 assert.EqualInt(t, 4, t5.Len(), "t5.Len()")133 assert.EqualInt(t, 8, t5.Depth(), "t5.Depth()")134 assert.Equal(t, v2, t5.Get(k1), "t5.Get(k1)")135 assert.Equal(t, v2, t5.Get(k2), "t5.Get(k2)")136 assert.Equal(t, v3, t5.Get(k3), "t5.Get(k3)")137 assert.Equal(t, v4, t5.Get(k4), "t5.Get(k4)")138}139func TestRange(t *testing.T) {140 t0 := Map.WithHasher(Bole32)141 k1 := "Hello"142 v1 := "World!"143 k2 := "He11o"144 v2 := "There!"145 t1 := t0.Set(k1, v1)146 t2 := t1.Set(k2, v2)147 c1 := 0148 t1.Range(func(key, value Any) bool {149 c1 += 1150 return key != k2151 })152 c2 := 0153 t2.Range(func(key, value Any) bool {154 c2 += 1155 return key != k1156 })157 assert.EqualInt(t, 1, c1, "t1.Range()")158 assert.EqualInt(t, 2, c2, "t2.Range()")159}160func TestSet(t *testing.T) {161 s0 := Map162 k1 := "first"163 k2 := "second"164 k3 := "third"165 k4 := "fourth"166 s1 := s0.Put(k1)167 s2 := s1.Put(k2)168 s3 := s2.Put(k3)169 x0 := Map.WithHasher(Bole32)170 x1 := x0.Put(k1)171 x2 := x1.Put(k2)172 x3 := x2.Put(k3)173 assert.Equal(t, true, s3.Has(k1), "s3.Has(k1)")174 assert.Equal(t, true, s3.Has(k2), "s3.Has(k2)")175 assert.Equal(t, true, s3.Has(k3), "s3.Has(k3)")176 assert.Equal(t, k3, s3.Get(k3), "s3.Get(k3)")177 assert.Equal(t, false, s3.Has(k4), "s3.Has(k4)")178 assert.Equal(t, true, x3.Has(k1), "x3.Has(k1)")179 assert.Equal(t, true, x3.Has(k2), "x3.Has(k2)")180 assert.Equal(t, true, x3.Has(k3), "x3.Has(k3)")181 assert.Equal(t, k3, x3.Get(k3), "x3.Get(k3)")182 assert.Equal(t, false, x3.Has(k4), "x3.Has(k4)")183}184func TestUnhashableKey(t *testing.T) {185 defer func() {186 assert.Equal(t, UnhashableKeyType, recover(), "err == UnhashableKeyType")187 }()188 assert.Equal(t, "Unhashable Key Type", UnhashableKeyType.Error(), "err == UnhashableKeyType")189 Map.Set(struct{ id int }{123}, 456)190 assert.Equal(t, false, true, "Unreachable")191}192func TestPutGetDelInt(t *testing.T) {193 t0 := Map194 k1 := uint(120120)195 v1 := "value1"196 k2 := int(120120)197 v2 := "value2"198 t1 := t0.Set(k1, v1)199 t2 := t1.Set(k2, v2)200 t3 := t2.Del(k1)201 count := 0202 t2.Range(func(key, value Any) bool {203 count++204 return true205 })206 assert.Equal(t, count, 2, "t2.Range()")207 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")208 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")209 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")210 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")211 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")212 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")213 val, ok := t3.Lookup(k2)214 assert.Equal(t, true, ok, "_, ok := t3.Lookup(k2)")215 assert.Equal(t, v2, val, "val, _ := t3.Lookup(k2)")216}217func TestPutGetDelUint64(t *testing.T) {218 t0 := Map219 k1 := uint64(120120)220 v1 := "value1"221 k2 := uint64(240240)222 v2 := "value2"223 t1 := t0.Set(k1, v1)224 t2 := t1.Set(k2, v2)225 t3 := t2.Del(k1)226 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")227 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")228 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")229 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")230 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")231 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")232}233func TestPutGetDelInt64(t *testing.T) {234 t0 := Map235 k1 := int64(120120)236 v1 := "value1"237 k2 := int64(-120120)238 v2 := "value2"239 t1 := t0.Set(k1, v1)240 t2 := t1.Set(k2, v2)241 t3 := t2.Del(k1)242 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")243 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")244 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")245 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")246 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")247 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")248}249func TestPutGetDelUint32(t *testing.T) {250 t0 := Map251 k1 := uint32(120)252 v1 := "value1"253 k2 := uint32(240)254 v2 := "value2"255 t1 := t0.Set(k1, v1)256 t2 := t1.Set(k2, v2)257 t3 := t2.Del(k1)258 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")259 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")260 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")261 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")262 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")263 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")264}265func TestPutGetDelInt32(t *testing.T) {266 t0 := Map267 k1 := int32(120)268 v1 := "value1"269 k2 := int32(-120)270 v2 := "value2"271 t1 := t0.Set(k1, v1)272 t2 := t1.Set(k2, v2)273 t3 := t2.Del(k1)274 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")275 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")276 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")277 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")278 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")279 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")280}281func TestPutGetDelUint16(t *testing.T) {282 t0 := Map283 k1 := uint16(120)284 v1 := "value1"285 k2 := uint16(240)286 v2 := "value2"287 t1 := t0.Set(k1, v1)288 t2 := t1.Set(k2, v2)289 t3 := t2.Del(k1)290 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")291 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")292 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")293 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")294 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")295 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")296}297func TestPutGetDelInt16(t *testing.T) {298 t0 := Map299 k1 := int16(120)300 v1 := "value1"301 k2 := int16(-120)302 v2 := "value2"303 t1 := t0.Set(k1, v1)304 t2 := t1.Set(k2, v2)305 t3 := t2.Del(k1)306 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")307 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")308 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")309 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")310 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")311 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")312}313func TestPutGetDelUint8(t *testing.T) {314 t0 := Map315 k1 := uint8(120)316 v1 := "value1"317 k2 := uint8(240)318 v2 := "value2"319 t1 := t0.Set(k1, v1)320 t2 := t1.Set(k2, v2)321 t3 := t2.Del(k1)322 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")323 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")324 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")325 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")326 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")327 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")328}329func TestPutGetDelInt8(t *testing.T) {330 t0 := Map331 k1 := int8(120)332 v1 := "value1"333 k2 := int8(-120)334 v2 := "value2"335 t1 := t0.Set(k1, v1)336 t2 := t1.Set(k2, v2)337 t3 := t2.Del(k1)338 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")339 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")340 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")341 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")342 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")343 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")344}345func TestPutGetDelString(t *testing.T) {346 t0 := Map347 k1 := "First Key"348 v1 := "value1"349 k2 := "Second Key"350 v2 := "value2"351 t1 := t0.Set(k1, v1)352 t2 := t1.Set(k2, v2)353 t3 := t2.Del(k1)354 assert.Equal(t, v1, t1.Get(k1), "t1.Get(k1)")355 assert.Equal(t, nil, t1.Get(k2), "t1.Get(k2)")356 assert.Equal(t, v1, t2.Get(k1), "t2.Get(k1)")357 assert.Equal(t, v2, t2.Get(k2), "t2.Get(k2)")358 assert.Equal(t, false, t3.Has(k1), "t3.Has(k1)")359 assert.Equal(t, true, t3.Has(k2), "t3.Has(k2)")360}361func TestPutGetDel(t *testing.T) {362 t0 := Map.WithHasher(Bole32)363 key := "hello"364 val := "world"365 t1 := t0.Set(key, val)366 assert.EqualInt(t, 0, t0.Len(), "t0.Len()")367 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")368 got, ok := t1.Lookup(key)369 assert.Equal(t, true, ok, "_,ok := t1.Lookup(%q); ok", key)370 assert.Equal(t, val, got, "v,_ := t1.Lookup(%q); v", key)371 t2 := t1.Del(key)372 assert.EqualInt(t, 0, t0.Len(), "t0.Len()")373 assert.EqualInt(t, 1, t1.Len(), "t1.Len()")374 assert.EqualInt(t, 0, t2.Len(), "t2.Len()")375 assert.Equal(t, true, t1.Get(key) != nil, "t1.Get(%q) != nil", key)376 assert.Equal(t, true, t2.Get(key) == nil, "t2.Get(%q) == nil", key)377}378func TestStringer(t *testing.T) {379 m := Map.Set("Hello", "World!")380 x := Map.WithHasher(Bole32).Set("Hello", "World!").Set("Hi", "There!")381 assert.EqualString(t, `{Hello:World!}`, m.String(), "m.String()")382 assert.EqualString(t, `{Hello:World!, Hi:There!}`, x.String(), "x.String()")383}384func TestPresent(t *testing.T) {385 tests := []struct{ exp, got bool }{386 /*0*/387 {exp: true, got: present(0b0001, bitpos(0, 0))},388 {exp: true, got: present(0b0010, bitpos(1, 0))},389 {exp: true, got: present(0b0100, bitpos(2, 0))},390 {exp: true, got: present(0b1000, bitpos(3, 0))},391 {exp: false, got: present(0b0010, bitpos(0, 0))},392 /*5*/393 {exp: false, got: present(0b0100, bitpos(0, 0))},394 {exp: true, got: present(0b0100, bitpos(2, 0))},395 {exp: false, got: present(0b0100, bitpos(3, 0))},396 {exp: true, got: present(0b1100, bitpos(3, 0))},397 {exp: false, got: present(0b10100, bitpos(3, 0))},398 /*10*/399 {exp: true, got: present(0b11100, bitpos(4, 0))},400 {exp: true, got: present(0b111100, bitpos(4, 0))},401 {exp: true, got: present(0b111100, bitpos(5, 0))},402 {exp: true, got: present(0b100100, bitpos(2, 0))},403 {exp: true, got: present(0b100100, bitpos(5, 0))},404 /*15*/405 {exp: false, got: present(0b1001010, bitpos(0, 0))},406 {exp: true, got: present(0b1001010, bitpos(1, 0))},407 {exp: false, got: present(0b1001010, bitpos(2, 0))},408 {exp: true, got: present(0b1001010, bitpos(3, 0))},409 {exp: false, got: present(0b1001010, bitpos(4, 0))},410 /*20*/411 {exp: false, got: present(0b1001010, bitpos(5, 0))},412 {exp: true, got: present(0b1001010, bitpos(6, 0))},413 {exp: false, got: present(0b1001010, bitpos(7, 0))},414 {exp: false, got: present(0b1001010, bitpos(7, 0))},415 {exp: false, got: present(0b1001010, bitpos(240, 0))},416 }417 for i, test := range tests {418 assert.Equal(t, test.exp, test.got, "test #%d", i)419 }420}421func TestIndex(t *testing.T) {422 tests := []struct{ exp, got int }{423 /*0*/424 {exp: 0, got: index(0b0000, bitpos(0, 0))},425 {exp: 0, got: index(0b0000, bitpos(1, 0))},426 {exp: 0, got: index(0b0001, bitpos(0, 0))},427 {exp: 1, got: index(0b0001, bitpos(1, 0))},428 {exp: 1, got: index(0b0001, bitpos(2, 0))},429 /*5*/430 {exp: 0, got: index(0b0100, bitpos(0, 0))},431 {exp: 0, got: index(0b0100, bitpos(1, 0))},432 {exp: 0, got: index(0b0100, bitpos(2, 0))},433 {exp: 1, got: index(0b0100, bitpos(3, 0))},434 {exp: 1, got: index(0b0100, bitpos(4, 0))},435 /*10*/436 {exp: 3, got: index(0b011110, bitpos(4, 0))},437 {exp: 4, got: index(0b011110, bitpos(5, 0))},438 {exp: 4, got: index(0b011110, bitpos(6, 0))},439 {exp: 4, got: index(0b011110, bitpos(7, 0))},440 {exp: 4, got: index(0b011110, bitpos(31, 0))},441 /*15*/442 {exp: 0, got: index(0b1001010, bitpos(0, 0))},443 {exp: 0, got: index(0b1001010, bitpos(1, 0))},444 {exp: 1, got: index(0b1001010, bitpos(2, 0))},445 {exp: 1, got: index(0b1001010, bitpos(3, 0))},446 {exp: 2, got: index(0b1001010, bitpos(4, 0))},447 /*20*/448 {exp: 2, got: index(0b1001010, bitpos(5, 0))},449 {exp: 2, got: index(0b1001010, bitpos(6, 0))},450 {exp: 3, got: index(0b1001010, bitpos(7, 0))},451 {exp: 3, got: index(0b1001010, bitpos(9, 0))},452 {exp: 3, got: index(0b1001010, bitpos(240, 0))},453 }454 for i, test := range tests {455 assert.EqualInt(t, test.exp, test.got, "test #%d", i)456 }457}458func TestSize(t *testing.T) {459 const arch = int(2 - uint64(^uint(0))>>63)460 assert.EqualInt(t, 32/arch, int(unsafe.Sizeof(amt{})), "unsafe.Sizeof(amt{})")461 assert.EqualInt(t, 40/arch, int(unsafe.Sizeof(entry{})), "unsafe.Sizeof(entry{})")462 assert.EqualInt(t, 32/arch, int(unsafe.Sizeof(Hamt{})), "unsafe.Sizeof(Hamt{})")463 assert.EqualInt(t, 40/arch, int(unsafe.Sizeof(HamtX{})), "unsafe.Sizeof(HamtX{})")464 t0 := &amt{}465 t1 := t0.set(0, 0, "Hello", "World!")466 assert.EqualInt(t, 8/arch, int(unsafe.Sizeof(t1.entries[0])), "unsafe.Sizeof(t1.entries[0])")467 assert.EqualInt(t, 32/arch, t0.size(), "t0.size()")468 assert.EqualInt(t, (32+8+40)/arch, t1.size(), "t1.size()")469 assert.EqualInt(t, 1, t1.len(), "t1.Len()")470 assert.EqualInt(t, 1, t1.depth(), "t1.Depth()")471 m0 := Map.WithHasher(Bole32)472 m1 := m0.Set("Hello", "World!")473 m2 := m1.Set("He11o", "There!")474 assert.EqualInt(t, (8+32)/arch, m0.Size(), "m0.Size()")475 assert.EqualInt(t, 1, m1.Len(), "m1.Len()")476 assert.EqualInt(t, 1, m1.Depth(), "m1.Depth()")477 assert.EqualInt(t, (8+(32+8+40))/arch, m1.Size(), "m1.Size()")478 assert.EqualInt(t, 2, m2.Len(), "m2.Len()")479 assert.EqualInt(t, 4, m2.Depth(), "m2.Depth()")480 assert.EqualInt(t, (8+(32+8+40)+(32+8+40)+(32+8+40)+(32+2*(8+40)))/arch, m2.Size(), "m2.Size()")481}482func TestBole32(t *testing.T) {483 h := func(h uint32, k Any) uint32 {484 return h485 }486 tests := []struct{ exp, got uint32 }{487 {exp: 0, got: h(Bole32(string([]byte{})))},488 {exp: 0, got: h(Bole32(string([]byte{0})))},489 {exp: 256, got: h(Bole32(string([]byte{0, 1})))},490 {exp: 1, got: h(Bole32(string([]byte{0x01, 0x00})))},491 {exp: 0x4321, got: h(Bole32(string([]byte{0x21, 0x43})))},492 {exp: 0x654321, got: h(Bole32(string([]byte{0x21, 0x43, 0x65})))},493 {exp: 0x87654321, got: h(Bole32(string([]byte{0x21, 0x43, 0x65, 0x87})))},494 {exp: 0x87654321, got: h(Bole32(string([]byte{0x21, 0x43, 0x65, 0x87, 0x09})))},495 }496 for i, test := range tests {497 assert.Equal(t, test.exp, test.got, "test #%d", i)498 }499 hash, _ := Bole32([]byte{1, 2, 3})500 assert.EqualInt(t, 0, int(hash), "hash, _ := Bole32(); hash")501}502// Bole32 returns the head of a string as a uint32 in Little Endian Byte503// Order.504func Bole32(key Any) (uint32, Any) {505 switch k := key.(type) {506 case string:507 switch len(k) {508 case 0:509 return 0, key510 case 1:511 return uint32(k[0]), key512 case 2:513 return uint32(k[0]) | uint32(k[1])<<8, key514 case 3:515 return uint32(k[0]) | uint32(k[1])<<8 | uint32(k[2])<<16, key516 default:517 return uint32(k[0]) | uint32(k[1])<<8 | uint32(k[2])<<16 | uint32(k[3])<<24, key518 }519 default:520 return 0, key521 }522}523var assert = struct {524 Equal func(t *testing.T, exp, got interface{}, msg string, info ...interface{})525 EqualInt func(t *testing.T, exp, got int, msg string, info ...interface{})526 EqualString func(t *testing.T, exp, got string, msg string, info ...interface{})527}{528 Equal: func(t *testing.T, exp, got interface{}, msg string, info ...interface{}) {529 t.Helper()530 if exp != got {531 t.Errorf(msg+" expected %#v got %#v", append(append(info, exp), got)...)532 }533 },534 EqualInt: func(t *testing.T, exp, got int, msg string, info ...interface{}) {535 t.Helper()536 if exp != got {537 t.Errorf(msg+" expected %d got %d", append(append(info, exp), got)...)538 }539 },540 EqualString: func(t *testing.T, exp, got string, msg string, info ...interface{}) {541 t.Helper()542 if exp != got {543 t.Errorf(msg+" expected %#q got %#q", append(append(info, exp), got)...)544 }545 },546}...

Full Screen

Full Screen

redis_cmds_test.go

Source:redis_cmds_test.go Github

copy

Full Screen

1package redis2import (3 "fmt"4 "testing"5 "github.com/gomodule/redigo/redis"6)7func TestKeyMethod(t *testing.T) {8 fmt.Println("==============test key method==============")9 cli := getCli()10 //key11 _, err := cli.Del("foo", "foo1", "foo2")12 equalError(nil, err, "del failed")13 val_i, err := cli.Expire("foo", 10)14 equalInt(0, val_i, "expire failed")15 equalError(nil, err, "expire failed")16 val_b, err := cli.Exists("foo")17 equalBool(false, val_b, "exists failed")18 equalError(nil, err, "exists failed")19 _, err = cli.RandomKey()20 equalError(nil, err, "randomkey failed")21 ttl, err := cli.TTL("foo")22 equalError(nil, err, "ttl failed")23 fmt.Println("ttl:", ttl)24 cli.Close()25}26func TestStringMethod(t *testing.T) {27 fmt.Println("==============test string method==============")28 cli := getCli()29 cli.Del("foo")30 cli.Del("foo2")31 //string32 val_i, err := cli.Append("foo", "bar")33 fmt.Printf("append:%d", val_i)34 equalInt(val_i, 3, "append failed")35 equalError(nil, err, "append failed")36 val_s, err := cli.Get("foo")37 equalString(val_s, "bar", "get failed")38 equalError(nil, err, "get failed")39 val_s, err = cli.GetRaw("fdjlafjka")40 equalString(val_s, "", "getraw failed")41 equalError(err, redis.ErrNil, "getraw failed")42 val_s, err = cli.GetSet("foo", "bar")43 equalString(val_s, "bar", "getset failed")44 equalError(nil, err, "getset failed")45 val_i, err = cli.IncrBy("foo", 10)46 equalInt(0, val_i, "incrby failed")47 notEqualError(nil, err, "incrby failed")48 val_ss, err := cli.MGet("foo", "foo2")49 equalString(val_ss[0], "bar", "mget failed")50 equalString(val_ss[1], "", "mget failed")51 equalError(nil, err, "mget failed")52 val_s, err = cli.MSet("foo1", "bar1", "foo2", "bar2")53 equalString(val_s, "OK", "mset failed")54 equalError(nil, err, "mset failed")55 val_s, err = cli.Set("foo1", "bar1", 0)56 equalString(val_s, "OK", "set failed")57 equalError(nil, err, "set failed")58 val_i, err = cli.SetNx("foo1", "bar2")59 equalInt(0, val_i, "setnx failed")60 equalError(nil, err, "setnx failed")61 val_s, _ = cli.Get("foo1")62 equalString(val_s, "bar1", "setnx failed")63 val_s, err = cli.MSet("foo1", "bar1", "foo2", "bar2")64 equalString(val_s, "OK", "setex failed")65 equalError(nil, err, "setex failed")66 val_i, err = cli.StrLen("foo")67 equalInt(val_i, 3, "strlen failed")68 equalError(nil, err, "strlen failed")69 cli.Close()70}71func TestBitMethod(t *testing.T) {72 fmt.Println("==============test bit method==============")73 cli := getCli()74 //bit75 cli.Set("mykey", "foobar", 0)76 val_i, err := cli.BitCount("mykey")77 equalInt(val_i, 26, "bitcount failed")78 equalError(nil, err, "bitcount failed")79 val_i, err = cli.BitCountWithPos("mykey", 1, 1)80 equalInt(val_i, 6, "bitcount failed")81 equalError(nil, err, "bitcount failed")82 val_i, err = cli.BitCount("mykeyNoExist")83 equalInt(val_i, 0, "bitcount failed")84 equalError(nil, err, "bitcount failed")85 cli.Del("mykey")86 cli.Set("mykey1", "foobar", 0)87 cli.Set("mykey2", "abcdef", 0)88 val_i, err = cli.BitOp("AND", "mydest", "mykey1", "mykey2")89 equalInt(val_i, 6, "bitop failed")90 equalError(nil, err, "bitop failed")91 val_s, err := cli.Get("mydest")92 equalString(val_s, "`bc`ab", "bitop failed")93 equalError(nil, err, "bitop failed")94 cli.Del("mydest", "mykey1", "mykey2")95 cli.Set("mykey", "\xff\xf0\x00", 0)96 val_i, err = cli.BitPos("mykey", 0)97 equalInt(val_i, 12, "bitpos failed")98 equalError(nil, err, "bitpos failed")99 cli.Set("mykey", "\x00\x00\x00", 0)100 val_i, err = cli.BitPos("mykey", 1)101 equalInt(val_i, -1, "bitpos failed")102 equalError(nil, err, "bitpos failed")103 cli.Set("mykey", "\x00\xff\xf0", 0)104 val_i, err = cli.BitPosWithPos("mykey", 1, 0, -1)105 equalInt(val_i, 8, "bitpos failed")106 equalError(nil, err, "bitpos failed")107 val_i, err = cli.BitPosWithPos("mykey", 1, 2, -1)108 equalInt(val_i, 16, "bitpos failed")109 equalError(nil, err, "bitpos failed")110 cli.Del("mykey")111 val_i, err = cli.SetBit("mykey", 7, 1)112 equalInt(val_i, 0, "setbit failed")113 equalError(nil, err, "setbit failed")114 val_i, err = cli.GetBit("mykey", 0)115 equalInt(val_i, 0, "getbit failed")116 equalError(nil, err, "getbit failed")117 val_i, err = cli.GetBit("mykey", 7)118 equalInt(val_i, 1, "getbit failed")119 equalError(nil, err, "getbit failed")120 val_i, err = cli.GetBit("mykey", 100)121 equalInt(val_i, 0, "getbit failed")122 equalError(nil, err, "getbit failed")123 cli.Del("mykey")124 cli.Close()125}126func TestHashMethod(t *testing.T) {127 fmt.Println("==============test hash method==============")128 cli := getCli()129 //hash130 _, err := cli.Del("hfoo", "hfoo1", "hfoo2")131 _, err = cli.HDel("hfoo", "hfoo1", "hfoo2")132 equalError(nil, err, "hdel failed")133 val_b, err := cli.HExists("hfoo", "bar")134 equalBool(false, val_b, "hexists failed")135 equalError(nil, err, "hexists failed")136 val_s, err := cli.HGet("hfoo", "bar")137 equalString(val_s, "", "hget failed")138 equalError(nil, err, "hget failed")139 val_mss, err := cli.HGetAll("hfoo")140 equalInt(0, len(val_mss), "hgetall failed")141 equalError(nil, err, "hgetall failed")142 val_i, err := cli.HIncr("hfoo", "ibar")143 equalInt(val_i, 1, "hincr failed")144 equalError(nil, err, "hincr failed")145 val_i, err = cli.HIncrBy("hfoo", "ibar", 2)146 equalInt(val_i, 3, "hincrby failed")147 equalError(nil, err, "hincrby failed")148 cli.HDel("hfoo", "ibar")149 val_ss, err := cli.HKeys("hfoo")150 equalInt(0, len(val_ss), "hkeys failed")151 equalError(nil, err, "hkeys failed")152 val_i, err = cli.HLen("hfoo")153 equalInt(0, val_i, "hlen failed")154 equalError(nil, err, "hlen failed")155 val_ss, err = cli.HMGet("hfoo", "bar", "bar1")156 equalString(val_ss[0], "", "hmget failed")157 equalString(val_ss[1], "", "hmget failed")158 equalError(nil, err, "hmget failed")159 val_s, err = cli.HMSet("hfoo", "bar", "0", "bar1", "1")160 equalString(val_s, "OK", "hmset failed")161 equalError(nil, err, "hmset failed")162 val_i, err = cli.HSet("hfoo", "bar2", "2")163 equalInt(val_i, 1, "hset failed")164 equalError(nil, err, "hset failed")165 val_ss, err = cli.HVals("hfoo")166 equalString(val_ss[0], "0", "hvals failed")167 equalString(val_ss[1], "1", "hvals failed")168 equalString(val_ss[2], "2", "hvals failed")169 equalError(nil, err, "hvals failed")170 cli.Close()171}172func TestListMethod(t *testing.T) {173 fmt.Println("==============test list method==============")174 cli := getCli()175 //list176 _, err := cli.Del("hfoo")177 _, err = cli.LIndex("hfoo", 0)178 equalError(nil, err, "lindex failed")179 val_i, err := cli.LInsert("hfoo", "BEFORE", "bar", "bar0")180 equalError(nil, err, "linsert failed")181 val_i, err = cli.LLen("hfoo")182 equalInt(0, val_i, "llen failed")183 equalError(nil, err, "llen failed")184 val_s, err := cli.LPop("hfoo")185 equalError(nil, err, "lindex failed")186 val_i, err = cli.LPush("hfoo", "bar", "bar1")187 equalInt(val_i, 2, "lpush failed")188 equalError(nil, err, "lpush failed")189 val_ss, err := cli.LRange("hfoo", 0, -1)190 equalString(val_ss[0], "bar1", "lrange failed")191 equalString(val_ss[1], "bar", "lrange failed")192 equalError(nil, err, "lrange failed")193 val_i, err = cli.LRem("hfoo", 0, "bar1")194 equalInt(val_i, 1, "lrem failed")195 equalError(nil, err, "lrem failed")196 val_s, err = cli.LSet("hfoo", 0, "barbar")197 equalString(val_s, "OK", "lset failed")198 equalError(nil, err, "lset failed")199 val_s, err = cli.LTrim("hfoo", 1, -1)200 equalString(val_s, "OK", "ltrim failed")201 equalError(nil, err, "ltrim failed")202 val_s, err = cli.RPop("hfoo")203 equalString(val_s, "", "rpop failed")204 equalError(nil, err, "rpop failed")205 val_i, err = cli.RPush("hfoo", "bar")206 equalInt(val_i, 1, "rpush failed")207 equalError(nil, err, "rpush failed")208 cli.Close()209}210func TestSetMethod(t *testing.T) {211 fmt.Println("==============test set method==============")212 cli := getCli()213 //set214 _, err := cli.Del("sfoo", "sfoo1")215 val_i, err := cli.SAdd("sfoo", "bar", "bar1")216 equalInt(val_i, 2, "sadd failed")217 equalError(nil, err, "sadd failed")218 _, _ = cli.SAdd("sfoo1", "bar2", "bar1")219 val_i, err = cli.SCard("sfoo")220 equalInt(val_i, 2, "scard failed")221 equalError(nil, err, "scard failed")222 val_ss, err := cli.SDiff("sfoo", "sfoo1")223 equalInt(len(val_ss), 1, "sdiff failed")224 equalError(nil, err, "sdiff failed")225 val_ss, err = cli.SInter("sfoo", "sfoo1")226 equalInt(len(val_ss), 1, "sinter failed")227 equalError(nil, err, "sinter failed")228 val_b, err := cli.SIsMember("sfoo", "bar")229 equalBool(true, val_b, "sismember failed")230 equalError(nil, err, "sismember failed")231 val_ss, err = cli.SMembers("sfoo")232 equalInt(len(val_ss), 2, "smembers failed")233 equalError(nil, err, "smembers failed")234 _, err = cli.SPop("sfoo")235 equalError(nil, err, "spop failed")236 _, err = cli.SRandMember("sfoo")237 equalError(nil, err, "srandmember failed")238 val_i, err = cli.SRem("sfoo1", "bar1", "bar2")239 equalInt(val_i, 2, "srem failed")240 equalError(nil, err, "srem failed")241 val_ss, err = cli.SUnion("sfoo", "sfoo1")242 equalInt(len(val_ss), 1, "sunion failed")243 equalError(nil, err, "sunion failed")244 cli.Close()245}246func TestZsetMethod(t *testing.T) {247 fmt.Println("==============test zset method==============")248 cli := getCli()249 //zset250 _, err := cli.Del("zfoo")251 val_i, err := cli.ZAdd("zfoo", 1, "bar1")252 equalInt(val_i, 1, "zadd failed")253 equalError(nil, err, "zadd failed")254 val_i, err = cli.ZMAdd("zfoo", &ScorePair{"bar2", 2}, &ScorePair{"bar3", 3})255 equalInt(val_i, 2, "zmadd failed")256 equalError(nil, err, "zmadd failed")257 val_i, err = cli.ZCard("zfoo")258 equalInt(val_i, 3, "zcard failed")259 equalError(nil, err, "zcard failed")260 val_i, err = cli.ZCount("zfoo", "-inf", "+inf")261 equalInt(val_i, 3, "zcount failed")262 equalError(nil, err, "zcount failed")263 val_i, err = cli.ZIncrBy("zfoo", 10, "bar1")264 equalInt(val_i, 11, "zincrby failed")265 equalError(nil, err, "zincrby failed")266 val_ss, err := cli.ZRange("zfoo", 0, -1)267 equalInt(len(val_ss), 3, "zrange failed")268 equalError(nil, err, "zrange failed")269 val_sps, err := cli.ZRangeWithScores("zfoo", 0, -1)270 equalInt(len(val_sps), 3, "zrangewithscores failed")271 equalError(nil, err, "zrangewithscores failed")272 val_i, err = cli.ZRank("zfoo", "bar1")273 equalInt(val_i, 2, "zrank failed")274 equalError(nil, err, "zrank failed")275 val_i, err = cli.ZRem("zfoo", "bar1", "bar2")276 equalInt(val_i, 2, "zrem failed")277 equalError(nil, err, "zrem failed")278 _, _ = cli.ZMAdd("zfoo", &ScorePair{"bar2", 2}, &ScorePair{"bar3", 3})279 val_i, err = cli.ZRemRangeByRank("zfoo", 0, -1)280 equalInt(val_i, 2, "zremrangebyrank failed")281 equalError(nil, err, "zremrangebyrank failed")282 _, _ = cli.ZMAdd("zfoo", &ScorePair{"bar2", 2}, &ScorePair{"bar3", 3})283 val_ss, err = cli.ZRevRange("zfoo", 0, -1)284 equalInt(len(val_ss), 2, "zrevrange failed")285 equalError(nil, err, "zrevrange failed")286 val_sps, err = cli.ZRevRangeWithScores("zfoo", 0, -1)287 equalInt(len(val_sps), 2, "zrevrangewithscores failed")288 equalError(nil, err, "zrevrangewithscores failed")289 val_i, err = cli.ZRevRank("zfoo", "bar3")290 equalInt(val_i, 0, "zrevrank failed")291 equalError(nil, err, "zrevrank failed")292 val_i, err = cli.ZScore("zfoo", "bar3")293 equalInt(val_i, 3, "zscore failed")294 equalError(nil, err, "zscore failed")295 cli.Set("foo", "bar", 0)296 script := cli.Script(1, "return redis.call('get', KEYS[1])")297 err = cli.LoadScript(script)298 equalError(nil, err, "loadscript failed")299 val_inter, err := cli.Eval(script, "foo")300 equalString(string(val_inter.([]byte)), "bar", "eval failed")301 equalError(nil, err, "eval failed")302 cli.Del("foo")303 pipe, err := cli.PipeLine(false)304 equalError(nil, err, "pipe line failed")305 err = cli.PipeSend(pipe, "set", "foo", "bar")306 equalError(nil, err, "pipe send failed")307 err = cli.PipeSend(pipe, "get", "foo")308 equalError(nil, err, "pipe send failed")309 val_inter, err = cli.PipeExec(pipe)310 equalString(val_inter.([]interface{})[0].(string), "OK", "pipe exec failed")311 equalString(string(val_inter.([]interface{})[1].([]byte)), "bar", "pipe exec failed")312 equalError(nil, err, "pipe exec failed")313 err = cli.PipeClose(pipe)314 equalError(nil, err, "pipe close failed")315 cli.Del("foo")316 cli.Close()317}...

Full Screen

Full Screen

trie_test.go

Source:trie_test.go Github

copy

Full Screen

...15 EqualEmit(t, emits[2], 11, 13, "残酒")16 EqualEmit(t, emits[3], 16, 19, "卷帘人")17 EqualEmit(t, emits[4], 27, 29, "知否")18 EqualEmit(t, emits[5], 30, 32, "知否")19 EqualInt(t, 6, len(emits))20}21func TestFindFirst(t *testing.T) {22 text := "昨夜雨疏风骤,浓睡不消残酒。试问卷帘人,却道海棠依旧。知否,知否?应是绿肥红瘦。"23 trie := New("雨疏", "风骤", "残酒", "卷帘人", "知否")24 emit := trie.FindFirst(text, false)25 t.Log(emit)26 EqualEmit(t, emit, 2, 4, "雨疏")27}28func TestFindAllIgnoreCase(t *testing.T) {29 text := "Poetry is what gets lost in translation."30 trie := New("poetry", "TRANSLATION")31 emits := trie.FindAll(text, true)32 t.Log(emits)33 EqualEmit(t, emits[0], 0, 6, "poetry")34 EqualEmit(t, emits[1], 28, 39, "TRANSLATION")35 EqualInt(t, 2, len(emits))36}37func TestFindFirstIgnoreCase(t *testing.T) {38 text := "Poetry is what gets lost in translation."39 trie := New("poetry", "TRANSLATION")40 emit := trie.FindFirst(text, true)41 t.Log(emit)42 EqualEmit(t, emit, 0, 6, "poetry")43}44func TestIgnoreCase(t *testing.T) {45 text := "TurninG OnCe AgAiN BÖRKÜ"46 trie := New("turning", "once", "again", "börkü")47 emits := trie.FindAll(text, true)48 t.Log(emits)49 EqualEmit(t, emits[0], 0, 7, "turning")50 EqualEmit(t, emits[1], 8, 12, "once")51 EqualEmit(t, emits[2], 13, 18, "again")52 EqualEmit(t, emits[3], 19, 24, "börkü")53 EqualInt(t, 4, len(emits))54}55func TestTokenize(t *testing.T) {56 text := "常记溪亭日暮,沉醉不知归路。兴尽晚回舟,误入藕花深处。争渡,争渡,惊起一滩鸥鹭。"57 trie := New("溪亭", "归路", "藕花", "争渡")58 emits := trie.FindAll(text, false)59 tokens := Tokenize(emits, text)60 t.Log(len(emits), emits)61 t.Log(len(tokens), tokens)62 EqualToken(t, tokens[0], -1, -1, "常记")63 EqualToken(t, tokens[1], 2, 4, "溪亭")64 EqualToken(t, tokens[2], -1, -1, "日暮,沉醉不知")65 EqualToken(t, tokens[3], 11, 13, "归路")66 EqualToken(t, tokens[4], -1, -1, "。兴尽晚回舟,误入")67 EqualToken(t, tokens[5], 22, 24, "藕花")68 EqualToken(t, tokens[6], -1, -1, "深处。")69 EqualToken(t, tokens[7], 27, 29, "争渡")70 EqualToken(t, tokens[8], -1, -1, ",")71 EqualToken(t, tokens[9], 30, 32, "争渡")72 EqualToken(t, tokens[10], -1, -1, ",惊起一滩鸥鹭。")73 EqualInt(t, 5, len(emits))74 EqualInt(t, 11, len(tokens))75}76func TestReplace(t *testing.T) {77 text := "我正在参加砍价,砍到0元就可以免费拿啦。亲~帮我砍一刀呗,咱们一起免费领好货。"78 trie := New("0元", "砍一刀", "免费拿", "免费领")79 emits := trie.FindAll(text, false)80 r1 := Replace(emits, text, "*")81 r2 := Replace(emits, text, "@#$%^&*")82 t.Log(emits)83 t.Log(r1)84 t.Log(r2)85 EqualString(t, "我正在参加砍价,砍到**就可以***啦。亲~帮我***呗,咱们一起***好货。", r1)86 EqualString(t, "我正在参加砍价,砍到%^就可以#$%啦。亲~帮我%^&呗,咱们一起&*@好货。", r2)87 EqualInt(t, 4, len(emits))88}89func TestOverlaps(t *testing.T) {90 text := "a123,456b"91 trie := New("123", "12", "23", "45", "56")92 emits := trie.FindAll(text, false)93 t.Log(emits)94 removed := RemoveOverlaps(emits)95 t.Log(emits)96 t.Log(removed)97 EqualEmit(t, removed[0], 1, 4, "123")98 EqualEmit(t, removed[1], 5, 7, "45")99 EqualInt(t, 5, len(emits))100 EqualInt(t, 2, len(removed))101}102func TestContains(t *testing.T) {103 text := "a123,456b"104 trie := New("123", "12", "23", "45", "56")105 emits := trie.FindAll(text, false)106 t.Log(emits)107 removed := RemoveContains(emits)108 t.Log(emits)109 t.Log(removed)110 EqualEmit(t, removed[0], 1, 4, "123")111 EqualEmit(t, removed[1], 5, 7, "45")112 EqualEmit(t, removed[2], 6, 8, "56")113 EqualInt(t, 5, len(emits))114 EqualInt(t, 3, len(removed))115}116func TestDuplicate(t *testing.T) {117 text := "123456"118 trie := New("123", "123", "456", "456")119 emits := trie.FindAll(text, false)120 t.Log(emits)121 EqualEmit(t, emits[0], 0, 3, "123")122 EqualEmit(t, emits[1], 3, 6, "456")123 EqualInt(t, 2, len(emits))124}125func TestAddKeywords(t *testing.T) {126 text := "ushers"127 trie1 := New("he", "she", "his", "hers")128 trie2 := New().AddKeywords("he", "she", "his", "hers")129 trie3 := New().AddKeywords("he").AddKeywords("she").AddKeywords("his").AddKeywords("hers")130 emits1 := trie1.FindAll(text, false)131 emits2 := trie2.FindAll(text, false)132 emits3 := trie3.FindAll(text, false)133 t.Log(emits1)134 t.Log(emits2)135 t.Log(emits3)136 EqualEmits(t, emits1, emits2)137 EqualEmits(t, emits1, emits3)138 EqualEmits(t, emits2, emits3)139}140func TestEmoji(t *testing.T) {141 t.Log("utf8.RuneCountInString(\"🐼\") >>", utf8.RuneCountInString("🐼"))142 t.Log("len(\"🐼\") >>", len("🐼"))143 EqualInt(t, 1, utf8.RuneCountInString("🐼"))144 EqualInt(t, 4, len("🐼"))145 text := "I love 🐼 very much."146 trie := New("🐼", "🐻")147 emits := trie.FindAll(text, false)148 t.Log(emits)149 EqualEmit(t, emits[0], 7, 8, "🐼")150 EqualInt(t, 1, len(emits))151}152func TestFile(t *testing.T) {153 keywords, err := readFile("keywords.txt")154 if err != nil {155 t.Error(err)156 return157 }158 text := "请在这里输入关键词"159 trie := New(keywords...)160 emits := trie.FindAll(text, false)161 t.Log(emits)162}163func readFile(filename string) ([]string, error) {164 f, err := os.Open(filename)165 if err != nil {166 return nil, err167 }168 lines := make([]string, 0, 15000)169 s := bufio.NewScanner(f)170 for s.Scan() {171 lines = append(lines, s.Text())172 }173 err = s.Err()174 if err != nil {175 return nil, err176 }177 err = f.Close()178 if err != nil {179 return nil, err180 }181 return lines, nil182}183func EqualInt(t *testing.T, expected int, actual int) {184 if expected != actual {185 t.Error(expected, actual)186 }187}188func EqualString(t *testing.T, expected string, actual string) {189 if expected != actual {190 t.Error(expected, actual)191 }192}193func EqualEmit(t *testing.T, emit *Emit, begin int, end int, kw string) {194 if emit.Begin != begin || emit.End != end || emit.Keyword != kw {195 t.Error(emit)196 }197}...

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Print("Enter first number: ")4 fmt.Scan(&x)5 fmt.Print("Enter second number: ")6 fmt.Scan(&y)7 if test.EqualInt(x, y) {8 fmt.Println("Numbers are equal")9 } else {10 fmt.Println("Numbers are not equal")11 }12}

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1func main() {2 if test.EqualInt(a, b) {3 fmt.Println("Equal")4 } else {5 fmt.Println("Not equal")6 }7}8 /usr/local/go/src/test (from $GOROOT)9 /home/gopher/go/src/test (from $GOPATH)10func EqualInt(a, b int) bool {11 if a == b {12 } else {13 }14}15import "testing"16func TestEqualInt(t *testing.T) {17 if EqualInt(a, b) {18 t.Error("EqualInt failed. Expected", a, "to be equal to", b)19 }20}21 /usr/local/go/src/test (from $GOROOT)22 /home/gopher/go/src/test (from $GOPATH)

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1func TestEqualInt(t *testing.T) {2 if !test.EqualInt(1, 1) {3 t.Error("1 is not equal to 1")4 }5}6func TestEqualInt(t *testing.T) {7 if !test.EqualInt(1, 1) {8 t.Error("1 is not equal to 1")9 }10}11func TestEqualInt(t *testing.T) {12 if !test.EqualInt(1, 1) {13 t.Error("1 is not equal to 1")14 }15}16func TestEqualInt(t *testing.T) {17 if !test.EqualInt(1, 1) {18 t.Error("1 is not equal to 1")19 }20}21func TestEqualInt(t *testing.T) {22 if !test.EqualInt(1, 1) {23 t.Error("1 is not equal to 1")24 }25}26func TestEqualInt(t *testing.T) {27 if !test.EqualInt(1, 1) {28 t.Error("1 is not equal to 1")29 }30}31func TestEqualInt(t *testing.T) {32 if !test.EqualInt(1, 1) {33 t.Error("1 is not equal to 1")34 }35}36func TestEqualInt(t *testing.T) {37 if !test.EqualInt(1, 1) {38 t.Error("1 is not equal to 1")39 }40}41func TestEqualInt(t *testing.T) {42 if !test.EqualInt(1, 1) {43 t.Error("1 is not equal to 1")44 }45}

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 t := test{1}4 if t.EqualInt(1) {5 fmt.Println("Equal")6 } else {7 fmt.Println("Not equal")8 }9}10func (receiver) function_name(parameters) return_type {11}12import "fmt"13type test struct {14}15func (t test) EqualInt(num int) bool {16}17func main() {18 t := test{1}19 if t.EqualInt(1) {20 fmt.Println("Equal")21 } else {22 fmt.Println("Not equal")23 }24}25import "fmt"26type test struct {27}28func (t test) EqualInt(num int) bool {29}30func (t test) EqualInt(num int, num2 int) bool {31}32func main() {33 t := test{1}34 if t.EqualInt(1) {35 fmt.Println("Equal")36 } else {37 fmt.Println("Not equal")38 }39 if t.EqualInt(1, 1) {40 fmt.Println("Equal")41 } else {42 fmt.Println("Not equal")43 }44}

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1import "testing"2func TestEqualInt(t *testing.T) {3 if x != y {4 t.Errorf("x and y are not equal")5 }6}

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 test.EqualInt(1, 1)5}6import (7func TestEqualInt(t *testing.T) {8 test.EqualInt(1, 1)9}10import (11func TestEqualInt(t *testing.T) {12 test.EqualInt(1, 1)13}

Full Screen

Full Screen

EqualInt

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Testing EqualInt method")4 fmt.Println("EqualInt(1,1) = ", Testing.EqualInt(1,1))5 fmt.Println("EqualInt(1,2) = ", Testing.EqualInt(1,2))6}7EqualInt(1,1) = true8EqualInt(1,2) = false9EqualInt(1,1) = true10EqualInt(1,2) = false11--- PASS: TestEqualInt (0.00s)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful