How to use Return method of got Package

Best Got code snippet using got.Return

shift_test.go

Source:shift_test.go Github

copy

Full Screen

1// Copyright 2016 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4package gc5import (6 "reflect"7 "testing"8)9// Tests shifts of zero.10//go:noinline11func ofz64l64(n uint64) int64 {12 var x int6413 return x << n14}15//go:noinline16func ofz64l32(n uint32) int64 {17 var x int6418 return x << n19}20//go:noinline21func ofz64l16(n uint16) int64 {22 var x int6423 return x << n24}25//go:noinline26func ofz64l8(n uint8) int64 {27 var x int6428 return x << n29}30//go:noinline31func ofz64r64(n uint64) int64 {32 var x int6433 return x >> n34}35//go:noinline36func ofz64r32(n uint32) int64 {37 var x int6438 return x >> n39}40//go:noinline41func ofz64r16(n uint16) int64 {42 var x int6443 return x >> n44}45//go:noinline46func ofz64r8(n uint8) int64 {47 var x int6448 return x >> n49}50//go:noinline51func ofz64ur64(n uint64) uint64 {52 var x uint6453 return x >> n54}55//go:noinline56func ofz64ur32(n uint32) uint64 {57 var x uint6458 return x >> n59}60//go:noinline61func ofz64ur16(n uint16) uint64 {62 var x uint6463 return x >> n64}65//go:noinline66func ofz64ur8(n uint8) uint64 {67 var x uint6468 return x >> n69}70//go:noinline71func ofz32l64(n uint64) int32 {72 var x int3273 return x << n74}75//go:noinline76func ofz32l32(n uint32) int32 {77 var x int3278 return x << n79}80//go:noinline81func ofz32l16(n uint16) int32 {82 var x int3283 return x << n84}85//go:noinline86func ofz32l8(n uint8) int32 {87 var x int3288 return x << n89}90//go:noinline91func ofz32r64(n uint64) int32 {92 var x int3293 return x >> n94}95//go:noinline96func ofz32r32(n uint32) int32 {97 var x int3298 return x >> n99}100//go:noinline101func ofz32r16(n uint16) int32 {102 var x int32103 return x >> n104}105//go:noinline106func ofz32r8(n uint8) int32 {107 var x int32108 return x >> n109}110//go:noinline111func ofz32ur64(n uint64) uint32 {112 var x uint32113 return x >> n114}115//go:noinline116func ofz32ur32(n uint32) uint32 {117 var x uint32118 return x >> n119}120//go:noinline121func ofz32ur16(n uint16) uint32 {122 var x uint32123 return x >> n124}125//go:noinline126func ofz32ur8(n uint8) uint32 {127 var x uint32128 return x >> n129}130//go:noinline131func ofz16l64(n uint64) int16 {132 var x int16133 return x << n134}135//go:noinline136func ofz16l32(n uint32) int16 {137 var x int16138 return x << n139}140//go:noinline141func ofz16l16(n uint16) int16 {142 var x int16143 return x << n144}145//go:noinline146func ofz16l8(n uint8) int16 {147 var x int16148 return x << n149}150//go:noinline151func ofz16r64(n uint64) int16 {152 var x int16153 return x >> n154}155//go:noinline156func ofz16r32(n uint32) int16 {157 var x int16158 return x >> n159}160//go:noinline161func ofz16r16(n uint16) int16 {162 var x int16163 return x >> n164}165//go:noinline166func ofz16r8(n uint8) int16 {167 var x int16168 return x >> n169}170//go:noinline171func ofz16ur64(n uint64) uint16 {172 var x uint16173 return x >> n174}175//go:noinline176func ofz16ur32(n uint32) uint16 {177 var x uint16178 return x >> n179}180//go:noinline181func ofz16ur16(n uint16) uint16 {182 var x uint16183 return x >> n184}185//go:noinline186func ofz16ur8(n uint8) uint16 {187 var x uint16188 return x >> n189}190//go:noinline191func ofz8l64(n uint64) int8 {192 var x int8193 return x << n194}195//go:noinline196func ofz8l32(n uint32) int8 {197 var x int8198 return x << n199}200//go:noinline201func ofz8l16(n uint16) int8 {202 var x int8203 return x << n204}205//go:noinline206func ofz8l8(n uint8) int8 {207 var x int8208 return x << n209}210//go:noinline211func ofz8r64(n uint64) int8 {212 var x int8213 return x >> n214}215//go:noinline216func ofz8r32(n uint32) int8 {217 var x int8218 return x >> n219}220//go:noinline221func ofz8r16(n uint16) int8 {222 var x int8223 return x >> n224}225//go:noinline226func ofz8r8(n uint8) int8 {227 var x int8228 return x >> n229}230//go:noinline231func ofz8ur64(n uint64) uint8 {232 var x uint8233 return x >> n234}235//go:noinline236func ofz8ur32(n uint32) uint8 {237 var x uint8238 return x >> n239}240//go:noinline241func ofz8ur16(n uint16) uint8 {242 var x uint8243 return x >> n244}245//go:noinline246func ofz8ur8(n uint8) uint8 {247 var x uint8248 return x >> n249}250func TestShiftOfZero(t *testing.T) {251 if got := ofz64l64(5); got != 0 {252 t.Errorf("0<<5 == %d, want 0", got)253 }254 if got := ofz64l32(5); got != 0 {255 t.Errorf("0<<5 == %d, want 0", got)256 }257 if got := ofz64l16(5); got != 0 {258 t.Errorf("0<<5 == %d, want 0", got)259 }260 if got := ofz64l8(5); got != 0 {261 t.Errorf("0<<5 == %d, want 0", got)262 }263 if got := ofz64r64(5); got != 0 {264 t.Errorf("0>>5 == %d, want 0", got)265 }266 if got := ofz64r32(5); got != 0 {267 t.Errorf("0>>5 == %d, want 0", got)268 }269 if got := ofz64r16(5); got != 0 {270 t.Errorf("0>>5 == %d, want 0", got)271 }272 if got := ofz64r8(5); got != 0 {273 t.Errorf("0>>5 == %d, want 0", got)274 }275 if got := ofz64ur64(5); got != 0 {276 t.Errorf("0>>>5 == %d, want 0", got)277 }278 if got := ofz64ur32(5); got != 0 {279 t.Errorf("0>>>5 == %d, want 0", got)280 }281 if got := ofz64ur16(5); got != 0 {282 t.Errorf("0>>>5 == %d, want 0", got)283 }284 if got := ofz64ur8(5); got != 0 {285 t.Errorf("0>>>5 == %d, want 0", got)286 }287 if got := ofz32l64(5); got != 0 {288 t.Errorf("0<<5 == %d, want 0", got)289 }290 if got := ofz32l32(5); got != 0 {291 t.Errorf("0<<5 == %d, want 0", got)292 }293 if got := ofz32l16(5); got != 0 {294 t.Errorf("0<<5 == %d, want 0", got)295 }296 if got := ofz32l8(5); got != 0 {297 t.Errorf("0<<5 == %d, want 0", got)298 }299 if got := ofz32r64(5); got != 0 {300 t.Errorf("0>>5 == %d, want 0", got)301 }302 if got := ofz32r32(5); got != 0 {303 t.Errorf("0>>5 == %d, want 0", got)304 }305 if got := ofz32r16(5); got != 0 {306 t.Errorf("0>>5 == %d, want 0", got)307 }308 if got := ofz32r8(5); got != 0 {309 t.Errorf("0>>5 == %d, want 0", got)310 }311 if got := ofz32ur64(5); got != 0 {312 t.Errorf("0>>>5 == %d, want 0", got)313 }314 if got := ofz32ur32(5); got != 0 {315 t.Errorf("0>>>5 == %d, want 0", got)316 }317 if got := ofz32ur16(5); got != 0 {318 t.Errorf("0>>>5 == %d, want 0", got)319 }320 if got := ofz32ur8(5); got != 0 {321 t.Errorf("0>>>5 == %d, want 0", got)322 }323 if got := ofz16l64(5); got != 0 {324 t.Errorf("0<<5 == %d, want 0", got)325 }326 if got := ofz16l32(5); got != 0 {327 t.Errorf("0<<5 == %d, want 0", got)328 }329 if got := ofz16l16(5); got != 0 {330 t.Errorf("0<<5 == %d, want 0", got)331 }332 if got := ofz16l8(5); got != 0 {333 t.Errorf("0<<5 == %d, want 0", got)334 }335 if got := ofz16r64(5); got != 0 {336 t.Errorf("0>>5 == %d, want 0", got)337 }338 if got := ofz16r32(5); got != 0 {339 t.Errorf("0>>5 == %d, want 0", got)340 }341 if got := ofz16r16(5); got != 0 {342 t.Errorf("0>>5 == %d, want 0", got)343 }344 if got := ofz16r8(5); got != 0 {345 t.Errorf("0>>5 == %d, want 0", got)346 }347 if got := ofz16ur64(5); got != 0 {348 t.Errorf("0>>>5 == %d, want 0", got)349 }350 if got := ofz16ur32(5); got != 0 {351 t.Errorf("0>>>5 == %d, want 0", got)352 }353 if got := ofz16ur16(5); got != 0 {354 t.Errorf("0>>>5 == %d, want 0", got)355 }356 if got := ofz16ur8(5); got != 0 {357 t.Errorf("0>>>5 == %d, want 0", got)358 }359 if got := ofz8l64(5); got != 0 {360 t.Errorf("0<<5 == %d, want 0", got)361 }362 if got := ofz8l32(5); got != 0 {363 t.Errorf("0<<5 == %d, want 0", got)364 }365 if got := ofz8l16(5); got != 0 {366 t.Errorf("0<<5 == %d, want 0", got)367 }368 if got := ofz8l8(5); got != 0 {369 t.Errorf("0<<5 == %d, want 0", got)370 }371 if got := ofz8r64(5); got != 0 {372 t.Errorf("0>>5 == %d, want 0", got)373 }374 if got := ofz8r32(5); got != 0 {375 t.Errorf("0>>5 == %d, want 0", got)376 }377 if got := ofz8r16(5); got != 0 {378 t.Errorf("0>>5 == %d, want 0", got)379 }380 if got := ofz8r8(5); got != 0 {381 t.Errorf("0>>5 == %d, want 0", got)382 }383 if got := ofz8ur64(5); got != 0 {384 t.Errorf("0>>>5 == %d, want 0", got)385 }386 if got := ofz8ur32(5); got != 0 {387 t.Errorf("0>>>5 == %d, want 0", got)388 }389 if got := ofz8ur16(5); got != 0 {390 t.Errorf("0>>>5 == %d, want 0", got)391 }392 if got := ofz8ur8(5); got != 0 {393 t.Errorf("0>>>5 == %d, want 0", got)394 }395}396//go:noinline397func byz64l(n int64) int64 {398 return n << 0399}400//go:noinline401func byz64r(n int64) int64 {402 return n >> 0403}404//go:noinline405func byz64ur(n uint64) uint64 {406 return n >> 0407}408//go:noinline409func byz32l(n int32) int32 {410 return n << 0411}412//go:noinline413func byz32r(n int32) int32 {414 return n >> 0415}416//go:noinline417func byz32ur(n uint32) uint32 {418 return n >> 0419}420//go:noinline421func byz16l(n int16) int16 {422 return n << 0423}424//go:noinline425func byz16r(n int16) int16 {426 return n >> 0427}428//go:noinline429func byz16ur(n uint16) uint16 {430 return n >> 0431}432//go:noinline433func byz8l(n int8) int8 {434 return n << 0435}436//go:noinline437func byz8r(n int8) int8 {438 return n >> 0439}440//go:noinline441func byz8ur(n uint8) uint8 {442 return n >> 0443}444func TestShiftByZero(t *testing.T) {445 {446 var n int64 = 0x5555555555555555447 if got := byz64l(n); got != n {448 t.Errorf("%x<<0 == %x, want %x", n, got, n)449 }450 if got := byz64r(n); got != n {451 t.Errorf("%x>>0 == %x, want %x", n, got, n)452 }453 }454 {455 var n uint64 = 0xaaaaaaaaaaaaaaaa456 if got := byz64ur(n); got != n {457 t.Errorf("%x>>>0 == %x, want %x", n, got, n)458 }459 }460 {461 var n int32 = 0x55555555462 if got := byz32l(n); got != n {463 t.Errorf("%x<<0 == %x, want %x", n, got, n)464 }465 if got := byz32r(n); got != n {466 t.Errorf("%x>>0 == %x, want %x", n, got, n)467 }468 }469 {470 var n uint32 = 0xaaaaaaaa471 if got := byz32ur(n); got != n {472 t.Errorf("%x>>>0 == %x, want %x", n, got, n)473 }474 }475 {476 var n int16 = 0x5555477 if got := byz16l(n); got != n {478 t.Errorf("%x<<0 == %x, want %x", n, got, n)479 }480 if got := byz16r(n); got != n {481 t.Errorf("%x>>0 == %x, want %x", n, got, n)482 }483 }484 {485 var n uint16 = 0xaaaa486 if got := byz16ur(n); got != n {487 t.Errorf("%x>>>0 == %x, want %x", n, got, n)488 }489 }490 {491 var n int8 = 0x55492 if got := byz8l(n); got != n {493 t.Errorf("%x<<0 == %x, want %x", n, got, n)494 }495 if got := byz8r(n); got != n {496 t.Errorf("%x>>0 == %x, want %x", n, got, n)497 }498 }499 {500 var n uint8 = 0x55501 if got := byz8ur(n); got != n {502 t.Errorf("%x>>>0 == %x, want %x", n, got, n)503 }504 }505}506//go:noinline507func two64l(x int64) int64 {508 return x << 1 << 1509}510//go:noinline511func two64r(x int64) int64 {512 return x >> 1 >> 1513}514//go:noinline515func two64ur(x uint64) uint64 {516 return x >> 1 >> 1517}518//go:noinline519func two32l(x int32) int32 {520 return x << 1 << 1521}522//go:noinline523func two32r(x int32) int32 {524 return x >> 1 >> 1525}526//go:noinline527func two32ur(x uint32) uint32 {528 return x >> 1 >> 1529}530//go:noinline531func two16l(x int16) int16 {532 return x << 1 << 1533}534//go:noinline535func two16r(x int16) int16 {536 return x >> 1 >> 1537}538//go:noinline539func two16ur(x uint16) uint16 {540 return x >> 1 >> 1541}542//go:noinline543func two8l(x int8) int8 {544 return x << 1 << 1545}546//go:noinline547func two8r(x int8) int8 {548 return x >> 1 >> 1549}550//go:noinline551func two8ur(x uint8) uint8 {552 return x >> 1 >> 1553}554func TestShiftCombine(t *testing.T) {555 if got, want := two64l(4), int64(16); want != got {556 t.Errorf("4<<1<<1 == %d, want %d", got, want)557 }558 if got, want := two64r(64), int64(16); want != got {559 t.Errorf("64>>1>>1 == %d, want %d", got, want)560 }561 if got, want := two64ur(64), uint64(16); want != got {562 t.Errorf("64>>1>>1 == %d, want %d", got, want)563 }564 if got, want := two32l(4), int32(16); want != got {565 t.Errorf("4<<1<<1 == %d, want %d", got, want)566 }567 if got, want := two32r(64), int32(16); want != got {568 t.Errorf("64>>1>>1 == %d, want %d", got, want)569 }570 if got, want := two32ur(64), uint32(16); want != got {571 t.Errorf("64>>1>>1 == %d, want %d", got, want)572 }573 if got, want := two16l(4), int16(16); want != got {574 t.Errorf("4<<1<<1 == %d, want %d", got, want)575 }576 if got, want := two16r(64), int16(16); want != got {577 t.Errorf("64>>1>>1 == %d, want %d", got, want)578 }579 if got, want := two16ur(64), uint16(16); want != got {580 t.Errorf("64>>1>>1 == %d, want %d", got, want)581 }582 if got, want := two8l(4), int8(16); want != got {583 t.Errorf("4<<1<<1 == %d, want %d", got, want)584 }585 if got, want := two8r(64), int8(16); want != got {586 t.Errorf("64>>1>>1 == %d, want %d", got, want)587 }588 if got, want := two8ur(64), uint8(16); want != got {589 t.Errorf("64>>1>>1 == %d, want %d", got, want)590 }591}592//go:noinline593func three64l(x int64) int64 {594 return x << 3 >> 1 << 2595}596//go:noinline597func three64ul(x uint64) uint64 {598 return x << 3 >> 1 << 2599}600//go:noinline601func three64r(x int64) int64 {602 return x >> 3 << 1 >> 2603}604//go:noinline605func three64ur(x uint64) uint64 {606 return x >> 3 << 1 >> 2607}608//go:noinline609func three32l(x int32) int32 {610 return x << 3 >> 1 << 2611}612//go:noinline613func three32ul(x uint32) uint32 {614 return x << 3 >> 1 << 2615}616//go:noinline617func three32r(x int32) int32 {618 return x >> 3 << 1 >> 2619}620//go:noinline621func three32ur(x uint32) uint32 {622 return x >> 3 << 1 >> 2623}624//go:noinline625func three16l(x int16) int16 {626 return x << 3 >> 1 << 2627}628//go:noinline629func three16ul(x uint16) uint16 {630 return x << 3 >> 1 << 2631}632//go:noinline633func three16r(x int16) int16 {634 return x >> 3 << 1 >> 2635}636//go:noinline637func three16ur(x uint16) uint16 {638 return x >> 3 << 1 >> 2639}640//go:noinline641func three8l(x int8) int8 {642 return x << 3 >> 1 << 2643}644//go:noinline645func three8ul(x uint8) uint8 {646 return x << 3 >> 1 << 2647}648//go:noinline649func three8r(x int8) int8 {650 return x >> 3 << 1 >> 2651}652//go:noinline653func three8ur(x uint8) uint8 {654 return x >> 3 << 1 >> 2655}656func TestShiftCombine3(t *testing.T) {657 if got, want := three64l(4), int64(64); want != got {658 t.Errorf("4<<1<<1 == %d, want %d", got, want)659 }660 if got, want := three64ul(4), uint64(64); want != got {661 t.Errorf("4<<1<<1 == %d, want %d", got, want)662 }663 if got, want := three64r(64), int64(4); want != got {664 t.Errorf("64>>1>>1 == %d, want %d", got, want)665 }666 if got, want := three64ur(64), uint64(4); want != got {667 t.Errorf("64>>1>>1 == %d, want %d", got, want)668 }669 if got, want := three32l(4), int32(64); want != got {670 t.Errorf("4<<1<<1 == %d, want %d", got, want)671 }672 if got, want := three32ul(4), uint32(64); want != got {673 t.Errorf("4<<1<<1 == %d, want %d", got, want)674 }675 if got, want := three32r(64), int32(4); want != got {676 t.Errorf("64>>1>>1 == %d, want %d", got, want)677 }678 if got, want := three32ur(64), uint32(4); want != got {679 t.Errorf("64>>1>>1 == %d, want %d", got, want)680 }681 if got, want := three16l(4), int16(64); want != got {682 t.Errorf("4<<1<<1 == %d, want %d", got, want)683 }684 if got, want := three16ul(4), uint16(64); want != got {685 t.Errorf("4<<1<<1 == %d, want %d", got, want)686 }687 if got, want := three16r(64), int16(4); want != got {688 t.Errorf("64>>1>>1 == %d, want %d", got, want)689 }690 if got, want := three16ur(64), uint16(4); want != got {691 t.Errorf("64>>1>>1 == %d, want %d", got, want)692 }693 if got, want := three8l(4), int8(64); want != got {694 t.Errorf("4<<1<<1 == %d, want %d", got, want)695 }696 if got, want := three8ul(4), uint8(64); want != got {697 t.Errorf("4<<1<<1 == %d, want %d", got, want)698 }699 if got, want := three8r(64), int8(4); want != got {700 t.Errorf("64>>1>>1 == %d, want %d", got, want)701 }702 if got, want := three8ur(64), uint8(4); want != got {703 t.Errorf("64>>1>>1 == %d, want %d", got, want)704 }705}706var (707 one64 int64 = 1708 one64u uint64 = 1709 one32 int32 = 1710 one32u uint32 = 1711 one16 int16 = 1712 one16u uint16 = 1713 one8 int8 = 1714 one8u uint8 = 1715)716func TestShiftLargeCombine(t *testing.T) {717 var N uint64 = 0x8000000000000000718 if one64<<N<<N == 1 {719 t.Errorf("shift overflow mishandled")720 }721 if one64>>N>>N == 1 {722 t.Errorf("shift overflow mishandled")723 }724 if one64u>>N>>N == 1 {725 t.Errorf("shift overflow mishandled")726 }727 if one32<<N<<N == 1 {728 t.Errorf("shift overflow mishandled")729 }730 if one32>>N>>N == 1 {731 t.Errorf("shift overflow mishandled")732 }733 if one32u>>N>>N == 1 {734 t.Errorf("shift overflow mishandled")735 }736 if one16<<N<<N == 1 {737 t.Errorf("shift overflow mishandled")738 }739 if one16>>N>>N == 1 {740 t.Errorf("shift overflow mishandled")741 }742 if one16u>>N>>N == 1 {743 t.Errorf("shift overflow mishandled")744 }745 if one8<<N<<N == 1 {746 t.Errorf("shift overflow mishandled")747 }748 if one8>>N>>N == 1 {749 t.Errorf("shift overflow mishandled")750 }751 if one8u>>N>>N == 1 {752 t.Errorf("shift overflow mishandled")753 }754}755func TestShiftLargeCombine3(t *testing.T) {756 var N uint64 = 0x8000000000000001757 if one64<<N>>2<<N == 1 {758 t.Errorf("shift overflow mishandled")759 }760 if one64u<<N>>2<<N == 1 {761 t.Errorf("shift overflow mishandled")762 }763 if one64>>N<<2>>N == 1 {764 t.Errorf("shift overflow mishandled")765 }766 if one64u>>N<<2>>N == 1 {767 t.Errorf("shift overflow mishandled")768 }769 if one32<<N>>2<<N == 1 {770 t.Errorf("shift overflow mishandled")771 }772 if one32u<<N>>2<<N == 1 {773 t.Errorf("shift overflow mishandled")774 }775 if one32>>N<<2>>N == 1 {776 t.Errorf("shift overflow mishandled")777 }778 if one32u>>N<<2>>N == 1 {779 t.Errorf("shift overflow mishandled")780 }781 if one16<<N>>2<<N == 1 {782 t.Errorf("shift overflow mishandled")783 }784 if one16u<<N>>2<<N == 1 {785 t.Errorf("shift overflow mishandled")786 }787 if one16>>N<<2>>N == 1 {788 t.Errorf("shift overflow mishandled")789 }790 if one16u>>N<<2>>N == 1 {791 t.Errorf("shift overflow mishandled")792 }793 if one8<<N>>2<<N == 1 {794 t.Errorf("shift overflow mishandled")795 }796 if one8u<<N>>2<<N == 1 {797 t.Errorf("shift overflow mishandled")798 }799 if one8>>N<<2>>N == 1 {800 t.Errorf("shift overflow mishandled")801 }802 if one8u>>N<<2>>N == 1 {803 t.Errorf("shift overflow mishandled")804 }805}806func TestShiftGeneric(t *testing.T) {807 for _, test := range [...]struct {808 valueWidth int809 signed bool810 shiftWidth int811 left bool812 f interface{}813 }{814 {64, true, 64, true, func(n int64, s uint64) int64 { return n << s }},815 {64, true, 64, false, func(n int64, s uint64) int64 { return n >> s }},816 {64, false, 64, false, func(n uint64, s uint64) uint64 { return n >> s }},817 {64, true, 32, true, func(n int64, s uint32) int64 { return n << s }},818 {64, true, 32, false, func(n int64, s uint32) int64 { return n >> s }},819 {64, false, 32, false, func(n uint64, s uint32) uint64 { return n >> s }},820 {64, true, 16, true, func(n int64, s uint16) int64 { return n << s }},821 {64, true, 16, false, func(n int64, s uint16) int64 { return n >> s }},822 {64, false, 16, false, func(n uint64, s uint16) uint64 { return n >> s }},823 {64, true, 8, true, func(n int64, s uint8) int64 { return n << s }},824 {64, true, 8, false, func(n int64, s uint8) int64 { return n >> s }},825 {64, false, 8, false, func(n uint64, s uint8) uint64 { return n >> s }},826 {32, true, 64, true, func(n int32, s uint64) int32 { return n << s }},827 {32, true, 64, false, func(n int32, s uint64) int32 { return n >> s }},828 {32, false, 64, false, func(n uint32, s uint64) uint32 { return n >> s }},829 {32, true, 32, true, func(n int32, s uint32) int32 { return n << s }},830 {32, true, 32, false, func(n int32, s uint32) int32 { return n >> s }},831 {32, false, 32, false, func(n uint32, s uint32) uint32 { return n >> s }},832 {32, true, 16, true, func(n int32, s uint16) int32 { return n << s }},833 {32, true, 16, false, func(n int32, s uint16) int32 { return n >> s }},834 {32, false, 16, false, func(n uint32, s uint16) uint32 { return n >> s }},835 {32, true, 8, true, func(n int32, s uint8) int32 { return n << s }},836 {32, true, 8, false, func(n int32, s uint8) int32 { return n >> s }},837 {32, false, 8, false, func(n uint32, s uint8) uint32 { return n >> s }},838 {16, true, 64, true, func(n int16, s uint64) int16 { return n << s }},839 {16, true, 64, false, func(n int16, s uint64) int16 { return n >> s }},840 {16, false, 64, false, func(n uint16, s uint64) uint16 { return n >> s }},841 {16, true, 32, true, func(n int16, s uint32) int16 { return n << s }},842 {16, true, 32, false, func(n int16, s uint32) int16 { return n >> s }},843 {16, false, 32, false, func(n uint16, s uint32) uint16 { return n >> s }},844 {16, true, 16, true, func(n int16, s uint16) int16 { return n << s }},845 {16, true, 16, false, func(n int16, s uint16) int16 { return n >> s }},846 {16, false, 16, false, func(n uint16, s uint16) uint16 { return n >> s }},847 {16, true, 8, true, func(n int16, s uint8) int16 { return n << s }},848 {16, true, 8, false, func(n int16, s uint8) int16 { return n >> s }},849 {16, false, 8, false, func(n uint16, s uint8) uint16 { return n >> s }},850 {8, true, 64, true, func(n int8, s uint64) int8 { return n << s }},851 {8, true, 64, false, func(n int8, s uint64) int8 { return n >> s }},852 {8, false, 64, false, func(n uint8, s uint64) uint8 { return n >> s }},853 {8, true, 32, true, func(n int8, s uint32) int8 { return n << s }},854 {8, true, 32, false, func(n int8, s uint32) int8 { return n >> s }},855 {8, false, 32, false, func(n uint8, s uint32) uint8 { return n >> s }},856 {8, true, 16, true, func(n int8, s uint16) int8 { return n << s }},857 {8, true, 16, false, func(n int8, s uint16) int8 { return n >> s }},858 {8, false, 16, false, func(n uint8, s uint16) uint8 { return n >> s }},859 {8, true, 8, true, func(n int8, s uint8) int8 { return n << s }},860 {8, true, 8, false, func(n int8, s uint8) int8 { return n >> s }},861 {8, false, 8, false, func(n uint8, s uint8) uint8 { return n >> s }},862 } {863 fv := reflect.ValueOf(test.f)864 var args [2]reflect.Value865 for i := 0; i < test.valueWidth; i++ {866 // Build value to be shifted.867 var n int64 = 1868 for j := 0; j < i; j++ {869 n <<= 1870 }871 args[0] = reflect.ValueOf(n).Convert(fv.Type().In(0))872 for s := 0; s <= test.shiftWidth; s++ {873 args[1] = reflect.ValueOf(s).Convert(fv.Type().In(1))874 // Compute desired result. We're testing variable shifts875 // assuming constant shifts are correct.876 r := n877 var op string878 switch {879 case test.left:880 op = "<<"881 for j := 0; j < s; j++ {882 r <<= 1883 }884 switch test.valueWidth {885 case 32:886 r = int64(int32(r))887 case 16:888 r = int64(int16(r))889 case 8:890 r = int64(int8(r))891 }892 case test.signed:893 op = ">>"894 switch test.valueWidth {895 case 32:896 r = int64(int32(r))897 case 16:898 r = int64(int16(r))899 case 8:900 r = int64(int8(r))901 }902 for j := 0; j < s; j++ {903 r >>= 1904 }905 default:906 op = ">>>"907 for j := 0; j < s; j++ {908 r = int64(uint64(r) >> 1)909 }910 }911 // Call function.912 res := fv.Call(args[:])[0].Convert(reflect.ValueOf(r).Type())913 if res.Int() != r {914 t.Errorf("%s%dx%d(%x,%x)=%x, want %x", op, test.valueWidth, test.shiftWidth, n, s, res.Int(), r)915 }916 }917 }918 }919}...

Full Screen

Full Screen

util.go

Source:util.go Github

copy

Full Screen

...20 "golang.org/x/tools/internal/span"21)22// DiffLinks takes the links we got and checks if they are located within the source or a Note.23// If the link is within a Note, the link is removed.24// Returns an diff comment if there are differences and empty string if no diffs.25func DiffLinks(mapper *protocol.ColumnMapper, wantLinks []Link, gotLinks []protocol.DocumentLink) string {26 var notePositions []token.Position27 links := make(map[span.Span]string, len(wantLinks))28 for _, link := range wantLinks {29 links[link.Src] = link.Target30 notePositions = append(notePositions, link.NotePosition)31 }32 for _, link := range gotLinks {33 spn, err := mapper.RangeSpan(link.Range)34 if err != nil {35 return fmt.Sprintf("%v", err)36 }37 linkInNote := false38 for _, notePosition := range notePositions {...

Full Screen

Full Screen

Return

Using AI Code Generation

copy

Full Screen

1import (2type Vertex struct {3}4func (v Vertex) Abs() float64 {5 return math.Sqrt(v.X*v.X + v.Y*v.Y)6}7func (v *Vertex) Scale(f float64) {8}9func (v *Vertex) Scale2(f float64) {10}11func (v *Vertex) Scale3(f float64) {12}13func main() {14 v := Vertex{3, 4}15 v.Scale(10)16 fmt.Println(v.Abs())17 v2 := &Vertex{3, 4}18 v2.Scale2(10)19 fmt.Println(v2.Abs())20 v3 := &Vertex{3, 4}21 v3.Scale3(10)22 fmt.Println(v3.Abs())23}

Full Screen

Full Screen

Return

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 http.HandleFunc("/", index)4 http.HandleFunc("/about", about)5 http.ListenAndServe(":8080", nil)6}7func index(w http.ResponseWriter, r *http.Request) {8 fmt.Fprint(w, "<h1>Welcome</h1>")9}10func about(w http.ResponseWriter, r *http.Request) {11 fmt.Fprint(w, "<h1>About</h1>")12}13import (14func main() {15 http.HandleFunc("/", index)16 http.HandleFunc("/about", about)17 http.ListenAndServe(":8080", nil)18}19func index(w http.ResponseWriter, r *http.Request) {20 http.ServeFile(w, r, "index.html")21}22func about(w http.ResponseWriter, r *http.Request) {23 http.ServeFile(w, r, "about.html")24}25import (26func index(w http.ResponseWriter, r *http.Request) {27 w.Header().Set("Content-Type", "text/html")28 fmt.Fprint(w, "<h1>Welcome</h1>")29}30func about(w http.ResponseWriter, r *http.Request) {31 w.Header().Set("Content-Type", "text/html")32 fmt.Fprint(w, "<h1>About</h1>")33}34func main() {35 http.HandleFunc("/", index)36 http.HandleFunc("/about", about)37 http.ListenAndServe(":8080", nil)38}39import (40func index(w http.ResponseWriter, r *http.Request) {41 w.Header().Set("Content-Type", "text/html")42 fmt.Fprint(w, "<h1>Welcome</h1>")43}44func about(w http.ResponseWriter, r *http.Request) {45 w.WriteHeader(http.StatusNotFound)46 fmt.Fprint(w, "<h1>Page not found</h1>")47}48func main() {49 http.HandleFunc("/", index)50 http.HandleFunc("/about", about)51 http.ListenAndServe(":8080", nil)52}53import (54func index(w http.ResponseWriter, r *http.Request) {

Full Screen

Full Screen

Return

Using AI Code Generation

copy

Full Screen

1import (2type Vertex struct {3}4func (v Vertex) Abs() float64 {5 return math.Sqrt(v.X*v.X + v.Y*v.Y)6}7func (v *Vertex) Scale(f float64) {8}9func (v *Vertex) Scale2(f float64) {10}11func (v *Vertex) Scale3(f float64) {12}13func (v *Vertex) Scale4(f float64) {14}15func (v *Vertex) Scale5(f float64) {16}17func (v *Vertex) Scale6(f float64) {18}19func (v *Vertex) Scale7(f float64) {20}21func (v *Vertex) Scale8(f float64) {22}23func (v *Vertex) Scale9(f float64) {24}25func (v *Vertex) Scale10(f float64) {26}27func main() {28 v := Vertex{3, 4}29 v.Scale(10)30 fmt.Println(v.Abs())31}

Full Screen

Full Screen

Return

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4 fmt.Println("Hello World")5 })6 http.ListenAndServe(":8080", nil)7}

Full Screen

Full Screen

Return

Using AI Code Generation

copy

Full Screen

1import (2type got struct {3}4func (g got) Return() string {5 return fmt.Sprint(g.name, g.age)6}7func main() {8 p1 := got{9 }10 p2 := got{11 }12 fmt.Println(p1.Return())13 fmt.Println(p2.Return())14}

Full Screen

Full Screen

Return

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter two numbers")4 fmt.Scanln(&x, &y)5 z := got.Return(x, y)6 fmt.Println("The sum is:", z)7}

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