How to use Prev method of lib Package

Best K6 code snippet using lib.Prev

forkdb.go

Source:forkdb.go Github

copy

Full Screen

...28type ForkDB struct {29 // links contain block_id -> previous_block_id30 links map[string]string31 linksLock sync.Mutex32 // nums contain block_id -> block_num. For blocks that were not EXPLICITLY added through AddLink (as the first BlockRef) or added through InitLIB(), the number will not be set. A missing reference means this is a block ID pointing to a non-LIB, yet Root block that we have obtains only through it being referenced as a PreviousID in an AddBlock call.33 nums map[string]uint6434 // objects contain objects of whatever nature you want to associate with blocks (lists of transaction IDs, Block, etc..35 objects map[string]interface{}36 libRef bstream.BlockRef37 logger *zap.Logger38}39func NewForkDB(opts ...ForkDBOption) *ForkDB {40 db := &ForkDB{41 links: make(map[string]string),42 nums: make(map[string]uint64),43 objects: make(map[string]interface{}),44 libRef: bstream.BlockRefEmpty,45 logger: zlog,46 }47 for _, opt := range opts {48 opt(db)49 }50 return db51}52func (f *ForkDB) InitLIB(ref bstream.BlockRef) {53 f.libRef = ref54 f.nums[ref.ID()] = ref.Num()55}56func (f *ForkDB) HasLIB() bool {57 if f.libRef == nil {58 return false59 }60 return !bstream.EqualsBlockRefs(f.libRef, bstream.BlockRefEmpty)61}62func (f *ForkDB) SetLogger(logger *zap.Logger) {63 f.logger = logger64}65// TrySetLIB will move the lib if crawling from the given blockID up to the dposlibNum66// succeeds, giving us effectively the dposLIBID. It will perform the set LIB and set67// the new headBlockID68// unknown behaviour if it was already set ... maybe it explodes69func (f *ForkDB) TrySetLIB(headRef bstream.BlockRef, previousRefID string, libNum uint64) {70 if headRef.Num() == bstream.GetProtocolFirstStreamableBlock {71 f.libRef = headRef72 f.logger.Debug("TrySetLIB received first streamable block of chain, assuming it's the new LIB", zap.Stringer("lib", f.libRef))73 return74 }75 libRef := f.BlockInCurrentChain(headRef, libNum)76 if libRef.ID() == "" {77 f.logger.Debug("missing links to back fill cache to LIB num", zap.String("head_id", headRef.ID()), zap.Uint64("head_num", headRef.Num()), zap.Uint64("previous_ref_num", headRef.Num()), zap.Uint64("lib_num", libNum), zap.Uint64("get_protocol_first_block", bstream.GetProtocolFirstStreamableBlock))78 return79 }80 _ = f.MoveLIB(libRef)81}82//Set a new lib without cleaning up blocks older then new lib (NO MOVE)83func (f *ForkDB) SetLIB(headRef bstream.BlockRef, previousRefID string, libNum uint64) {84 if headRef.Num() == bstream.GetProtocolFirstStreamableBlock {85 f.libRef = headRef86 f.logger.Debug("SetLIB received first streamable block of chain, assuming it's the new LIB", zap.Stringer("lib", f.libRef))87 return88 }89 libRef := f.BlockInCurrentChain(headRef, libNum)90 if libRef.ID() == "" {91 f.logger.Debug("missing links to back fill cache to LIB num", zap.String("head_id", headRef.ID()), zap.Uint64("head_num", headRef.Num()), zap.Uint64("previous_ref_num", headRef.Num()), zap.Uint64("lib_num", libNum), zap.Uint64("get_protocol_first_block", bstream.GetProtocolFirstStreamableBlock))92 return93 }94 f.libRef = libRef95}96// Get the last irreversible block ID97func (f *ForkDB) LIBID() string {98 return f.libRef.ID()99}100// Get the last irreversible block num101func (f *ForkDB) LIBNum() uint64 {102 return f.libRef.Num()103}104func (f *ForkDB) IsBehindLIB(blockNum uint64) bool {105 return blockNum <= f.LIBNum()106}107// ChainSwitchSegments returns the list of block IDs that should be108// `undo`ne (in reverse chain order) and the list of blocks that109// should be `redo`ne (in chain order) for `blockID` (linking to110// `previousID`) to become the longest chain.111//112// This assumes you are querying for something that *is* the longest113// chain (or the to-become longest chain).114func (f *ForkDB) ChainSwitchSegments(oldHeadBlockID, newHeadsPreviousID string) (undo []string, redo []string) {115 cur := oldHeadBlockID116 var undoChain []string117 seen := make(map[string]struct{})118 f.linksLock.Lock()119 for {120 undoChain = append(undoChain, cur)121 seen[cur] = struct{}{}122 prev := f.links[cur]123 if prev == "" {124 break125 }126 cur = prev127 }128 f.linksLock.Unlock()129 cur = newHeadsPreviousID130 var redoChain []string131 var junctionBlock string132 for {133 if _, found := seen[cur]; found {134 junctionBlock = cur135 break136 }137 redoChain = append(redoChain, cur)138 prev := f.links[cur]139 if prev == "" {140 // couldn't reach a common point, probably unlinked141 return nil, nil142 }143 cur = prev144 }145 var truncatedUndo []string146 for _, blk := range undoChain {147 if blk == junctionBlock {148 break149 }150 truncatedUndo = append(truncatedUndo, blk)151 }152 // WARN: what happens if `junctionBlock` isn't found?153 // This should not happen if we DO have links up until LIB.154 l := len(redoChain)155 var reversedRedo []string156 for i := 0; i < l; i++ {157 reversedRedo = append(reversedRedo, redoChain[l-i-1])158 }159 return truncatedUndo, reversedRedo160}161func (f *ForkDB) Exists(blockID string) bool {162 f.linksLock.Lock()163 defer f.linksLock.Unlock()164 return f.links[blockID] != ""165}166func (f *ForkDB) AddLink(blockRef bstream.BlockRef, previousRefID string, obj interface{}) (exists bool) {167 f.linksLock.Lock()168 defer f.linksLock.Unlock()169 blockID := blockRef.ID()170 if blockID == previousRefID || blockID == "" {171 return false172 }173 if f.links[blockID] != "" {174 return true175 }176 f.links[blockID] = previousRefID177 f.nums[blockID] = blockRef.Num()178 // MEANS f.nums will NOT provide the blockNumber associated with a block that was179 // not EXPLICITLY added as a blockRef (not a previous reference)180 //f.nums[previousID] = previousRef.Num()181 if obj != nil {182 f.objects[blockID] = obj183 }184 return false185}186// BlockInCurrentChain finds the block_id at height `blockNum` under187// the requested `startAtBlockID` base block. Passing the head block id188// as `startAtBlockID` will tell you if the block num is part of the longest189// chain.190func (f *ForkDB) BlockInCurrentChain(startAtBlock bstream.BlockRef, blockNum uint64) bstream.BlockRef {191 f.linksLock.Lock()192 defer f.linksLock.Unlock()193 if startAtBlock.Num() == blockNum {194 return startAtBlock195 }196 cur := startAtBlock.ID()197 for {198 prev := f.links[cur]199 prevNum, found := f.nums[prev]200 if !found {201 // This means it is a ROOT block, or you're in the middle of a HOLE202 zlog.Debug("found root or hole. did not reach requested block", zap.Uint64("requested_block_num", blockNum), zap.String("missing_id", prev))203 return bstream.BlockRefEmpty204 }205 if prevNum == blockNum {206 return bstream.NewBlockRef(prev, prevNum)207 } else if prevNum < blockNum {208 // in case blockNum is 500 and the prev is 499, whereas previous check had prev == 501209 // meaning there would be a hole in contiguity of the block numbers210 // on chains where this is possible.211 return bstream.NewBlockRef(cur, blockNum)212 }213 cur = prev214 }215}216// ReversibleSegment returns the blocks between the previous217// irreversible Block ID and the given block ID. The LIB is218// excluded and the given block ID is included in the results.219//220// Do not call this function is the .HasLIB() is false, as the result221// would make no sense.222//223// WARN: if the segment is broken by some unlinkable blocks, the224// return value is `nil`.225func (f *ForkDB) ReversibleSegment(startBlock bstream.BlockRef) (blocks []*Block, reachLIB bool) {226 f.linksLock.Lock()227 defer f.linksLock.Unlock()228 var reversedBlocks []*Block229 curID := startBlock.ID()230 curNum := startBlock.Num()231 // Those are for debugging purposes, they are the value of `curID` and `curNum`232 // just before those are switched to a previous parent link,233 prevID := ""234 prevNum := uint64(0)235 seenIDs := make(map[string]bool)236 for {237 if curNum > bstream.GetProtocolFirstStreamableBlock && curNum < f.LIBNum() {238 f.logger.Debug("forkdb linking past known irreversible block",239 zap.Stringer("lib", f.libRef),240 zap.Stringer("start_block", startBlock),241 zap.Stringer("current_block", bstream.NewBlockRef(curID, curNum)),242 zap.Stringer("previous_block", bstream.NewBlockRef(prevID, prevNum)),243 )244 return245 }246 if curID == f.libRef.ID() {247 reachLIB = true248 break249 }250 prev, found := f.links[curID]251 if !found {252 if f.HasLIB() {253 // This was Debug before but when serving Firehose request and there is a hole in one254 // of the merged blocks, it means you see almost nothing since normal logging is at Info.255 // This force usage of debug log to see something. Switched to be a warning since an unlinkable256 // block is not something that should happen, specially between `startBlock` and `LIB`, which is257 // the case here.258 //259 // If you came here to switch to Debug because it's too verbose, we should think about a way to260 // reduce the occurrence, at least logging once at Warn/Info and the rest in Debug.261 f.logger.Warn("forkdb unlinkable block, unable to reach last irrerversible block by following parent links",262 zap.Stringer("lib", f.libRef),263 zap.Stringer("start_block", startBlock),264 zap.String("missing_block_id", curID),265 zap.Stringer("missing_parent_of_block", bstream.NewBlockRef(prevID, prevNum)),266 )267 return nil, false // when LIB is set we need to reach it268 }269 break //reach the root of the chain. This should be the LIB, but we don't know yet.270 }271 reversedBlocks = append(reversedBlocks, &Block{272 BlockID: curID,273 BlockNum: curNum,274 Object: f.objects[curID],275 })276 seenIDs[prevID] = true277 prevID = curID278 prevNum = curNum279 curID = prev280 curNum = f.nums[prev]281 if seenIDs[curID] {282 zlog.Error("loop detected in reversible segment", zap.String("cur_id", curID), zap.Uint64("cur_num", curNum))283 return nil, false284 }285 }286 // Reverse sort `blocks`287 blocks = make([]*Block, len(reversedBlocks))288 j := 0289 for i := len(reversedBlocks); i != 0; i-- {290 blocks[j] = reversedBlocks[i-1]291 j++292 }293 return294}295func (f *ForkDB) stalledInSegment(blocks []*Block) (out []*Block) {296 if f.libRef.ID() == "" || len(blocks) == 0 {297 return298 }299 excludeBlocks := make(map[string]bool)300 for _, blk := range blocks {301 excludeBlocks[blk.BlockID] = true302 }303 start := blocks[0].BlockNum304 end := blocks[len(blocks)-1].BlockNum305 f.linksLock.Lock()306 for blkID, prevID := range f.links {307 linkBlkNum := f.nums[blkID]308 if !excludeBlocks[blkID] && linkBlkNum >= start && linkBlkNum <= end {309 out = append(out, &Block{310 BlockID: blkID,311 BlockNum: linkBlkNum,312 PreviousBlockID: prevID,313 Object: f.objects[blkID],314 })315 }316 }317 f.linksLock.Unlock()318 sort.Slice(out, func(i, j int) bool {319 return out[i].BlockID < out[j].BlockID320 })321 return out322}323// HasNewIrreversibleSegment returns segments upon passing the324// newDposLIBID that are irreversible and stale. If there was no new325// segment, `hasNew` will be false. WARN: this method can only be326// called when `HasLIB()` is true. Otherwise, it panics.327func (f *ForkDB) HasNewIrreversibleSegment(newLIB bstream.BlockRef) (hasNew bool, irreversibleSegment, staleBlocks []*Block) {328 if !f.HasLIB() {329 panic("the LIB ID is not defined and should have been")330 }331 newLIBID := newLIB.ID()332 if f.libRef.ID() == newLIBID {333 return false, nil, nil334 }335 irreversibleSegment, _ = f.ReversibleSegment(newLIB)336 if len(irreversibleSegment) == 0 {337 return false, nil, nil338 }339 staleBlocks = f.stalledInSegment(irreversibleSegment)340 return true, irreversibleSegment, staleBlocks341}342func (f *ForkDB) DeleteLink(id string) {343 f.linksLock.Lock()344 defer f.linksLock.Unlock()345 delete(f.links, id)346 delete(f.objects, id)347 delete(f.nums, id)348}349func (f *ForkDB) MoveLIB(blockRef bstream.BlockRef) (purgedBlocks []*Block) {350 f.linksLock.Lock()351 defer f.linksLock.Unlock()352 newLib := blockRef.Num()353 newLinks := make(map[string]string)354 newNums := make(map[string]uint64)355 for blk, prev := range f.links {356 blkNum := f.nums[blk]357 if blkNum >= newLib {358 newLinks[blk] = prev359 newNums[blk] = blkNum360 } else {361 purgedBlocks = append(purgedBlocks, &Block{362 BlockID: blk,363 BlockNum: blkNum,364 Object: f.objects[blk],365 PreviousBlockID: prev,366 })367 delete(f.objects, blk)368 }369 }370 f.links = newLinks371 f.nums = newNums372 f.libRef = blockRef373 return374}375// CloneLinks retrieves a snapshot of the links in the ForkDB. Used376// only in ForkViewerin `eosws`.377func (f *ForkDB) ClonedLinks() (out map[string]string, nums map[string]uint64) {378 f.linksLock.Lock()379 defer f.linksLock.Unlock()380 out = make(map[string]string)381 nums = make(map[string]uint64)382 for k, v := range f.links {383 out[k] = v384 nums[k] = f.nums[k]385 }386 return387}388func (f *ForkDB) BlockForID(blockID string) *Block {389 f.linksLock.Lock()390 defer f.linksLock.Unlock()391 if previous, ok := f.links[blockID]; ok {392 return &Block{393 BlockID: blockID,394 BlockNum: f.nums[blockID],395 PreviousBlockID: previous,396 Object: f.objects[blockID],397 }398 }399 return nil400}401func (f *ForkDB) IterateLinks(callback func(blockID, previousBlockID string, object interface{}) (getNext bool)) {402 f.linksLock.Lock()403 defer f.linksLock.Unlock()404 for id, prevID := range f.links {405 if !callback(id, prevID, f.objects[id]) {406 break407 }408 }409}...

Full Screen

Full Screen

algorithm_test.go

Source:algorithm_test.go Github

copy

Full Screen

1package tests2import (3 "fmt"4 "io/ioutil"5 "log"6 "math/rand"7 "os"8 "reflect"9 "testing"10 "time"11 algo "github.com/cem-okulmus/BalancedGo/algorithms"12 "github.com/cem-okulmus/BalancedGo/lib"13)14func solve(solver algo.Algorithm, graph lib.Graph, hinget *lib.Hingetree) lib.Decomp {15 var output lib.Decomp16 if hinget != nil {17 output = hinget.DecompHinge(solver, graph)18 } else {19 output = solver.FindDecomp()20 }21 return output22}23type solverDecomp struct {24 solver algo.Algorithm25 decomp lib.Decomp26}27func logActive(b bool) {28 if b {29 log.SetOutput(os.Stderr)30 log.SetFlags(0)31 } else {32 log.SetOutput(ioutil.Discard)33 }34}35func TestAlgo(t *testing.T) {36 // logActive(false)37 s := rand.NewSource(time.Now().UnixNano())38 r := rand.New(s)39 graphInitial, encoding := getRandomGraph(10)40 // graph := lib.GetGraphPACE(graphFirst.ToPACE())41 var graph lib.Graph42 graph = graphInitial43 width := r.Intn(6) + 144 BalFactor := 245 heuristicRand := r.Intn(4)46 // Preprocessing on graph47 order1 := lib.GetDegreeOrder(graph.Edges)48 order2 := lib.GetMaxSepOrder(graph.Edges)49 order3 := lib.GetMSCOrder(graph.Edges)50 order4 := lib.GetEdgeDegreeOrder(graph.Edges)51 switch heuristicRand {52 case 1:53 graph.Edges = order154 break55 case 2:56 graph.Edges = order257 break58 case 3:59 graph.Edges = order360 break61 case 4:62 graph.Edges = order463 break64 }65 var removalMap map[int][]int66 var ops []lib.GYÖReduct67 graph, removalMap, _ = graph.TypeCollapse()68 graph, ops = graph.GYÖReduct()69 hinget := lib.GetHingeTree(graph)70 var algoTestsHD []algo.Algorithm71 var algoTestsGHD []algo.Algorithm72 balDet := &algo.BalSepHybrid{73 K: width,74 Graph: graph,75 BalFactor: BalFactor,76 Depth: 1,77 }78 algoTestsGHD = append(algoTestsGHD, balDet)79 seqBalDet := &algo.BalSepHybridSeq{80 K: width,81 Graph: graph,82 BalFactor: BalFactor,83 Depth: 1,84 }85 algoTestsGHD = append(algoTestsGHD, seqBalDet)86 det := &algo.DetKDecomp{87 K: width,88 Graph: graph,89 BalFactor: BalFactor,90 SubEdge: false,91 }92 algoTestsHD = append(algoTestsHD, det)93 localBIP := &algo.DetKDecomp{94 K: width,95 Graph: graph,96 BalFactor: BalFactor,97 SubEdge: true,98 }99 algoTestsGHD = append(algoTestsGHD, localBIP)100 global := &algo.BalSepGlobal{101 K: width,102 Graph: graph,103 BalFactor: BalFactor,104 }105 algoTestsGHD = append(algoTestsGHD, global)106 local := &algo.BalSepLocal{107 K: width,108 Graph: graph,109 BalFactor: BalFactor,110 }111 algoTestsGHD = append(algoTestsGHD, local)112 // test out all algorithms113 first := true114 prevAnswer := false115 prevAlgo := ""116 var out lib.Decomp117 prevDecomp := lib.Decomp{}118 for _, algorithm := range algoTestsHD {119 algorithm.SetGenerator(lib.ParallelSearchGen{})120 out = solve(algorithm, graph, &hinget)121 if !reflect.DeepEqual(out, lib.Decomp{}) || (len(ops) > 0 && graph.Edges.Len() == 0) {122 var result bool123 out.Root, result = out.Root.RestoreGYÖ(ops)124 if !result {125 fmt.Println("Partial decomp:", out.Root)126 log.Panicln("GYÖ reduction failed")127 }128 out.Root, result = out.Root.RestoreTypes(removalMap)129 if !result {130 fmt.Println("Partial decomp:", out.Root)131 log.Panicln("Type Collapse reduction failed")132 }133 }134 if !reflect.DeepEqual(out, lib.Decomp{}) {135 out.Graph = graphInitial136 }137 answer := out.Correct(graphInitial)138 if answer {139 if out.CheckWidth() > width {140 t.Errorf("Out decomp of higher width than required: %v, width %v", out, width)141 }142 }143 if !first && answer != prevAnswer {144 fmt.Println("GraphInitial ", graphInitial.ToHyberBenchFormat())145 fmt.Println("Graph ", graph)146 fmt.Println("Width: ", width)147 fmt.Println("Current algo ", algorithm.Name(), "answer: ", answer, " and decomp: ", out)148 fmt.Println("Current algo ", prevAlgo, "answer: ", prevAnswer, " and decomp: ", prevDecomp)149 t.Errorf("Found disagreement among the algorithms: %v %v", algorithm.Name(), prevAlgo)150 }151 prevAnswer = answer152 prevAlgo = algorithm.Name()153 prevDecomp = out154 first = false155 }156 first = true157 prevAnswer = false158 prevAlgo = ""159 prevDecomp = lib.Decomp{}160 for _, algorithm := range algoTestsGHD {161 algorithm.SetGenerator(lib.ParallelSearchGen{})162 out = solve(algorithm, graph, &hinget)163 if !reflect.DeepEqual(out, lib.Decomp{}) || (len(ops) > 0 && graph.Edges.Len() == 0) {164 var result bool165 out.Root, result = out.Root.RestoreGYÖ(ops)166 if !result {167 fmt.Println("Partial decomp:", out.Root)168 log.Panicln("GYÖ reduction failed")169 }170 out.Root, result = out.Root.RestoreTypes(removalMap)171 if !result {172 fmt.Println("Partial decomp:", out.Root)173 log.Panicln("Type Collapse reduction failed")174 }175 }176 if !reflect.DeepEqual(out, lib.Decomp{}) {177 out.Graph = graphInitial178 }179 answer := out.Correct(graphInitial)180 if answer {181 if out.CheckWidth() > width {182 t.Errorf("Out decomp of higher width than required: %v, width %v", out, width)183 }184 }185 if !first && answer != prevAnswer {186 fmt.Println("GraphInitial ", graphInitial.ToHyberBenchFormat())187 fmt.Println("Graph ", graph)188 fmt.Println("Width: ", width)189 fmt.Println("Current algo ", algorithm.Name(), "answer: ", answer, " and decomp: ", out)190 fmt.Println("Current algo ", prevAlgo, "answer: ", prevAnswer, " and decomp: ", prevDecomp)191 t.Errorf("Found disagreement among the algorithms: %v %v", algorithm.Name(), prevAlgo)192 }193 prevAnswer = answer194 prevAlgo = algorithm.Name()195 prevDecomp = out196 first = false197 }198 //produce a GML199 gml := out.ToGML()200 if !reflect.DeepEqual(out, lib.Decomp{}) {201 lib.GetDecompGML(gml, graphInitial, encoding)202 }203}...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "fmt"4 "github.com/beckbria/advent-of-code/2020/lib"5)6// https://adventofcode.com/2020/day/#7// The game of life simulator we all expected8func main() {9 lines := lib.ReadFileLines("2020/11/input.txt")10 sw := lib.NewStopwatch()11 fmt.Println("Step 1:")12 g := newGame(lines)13 fmt.Println(step1(g))14 fmt.Println(sw.Elapsed())15 sw.Reset()16 fmt.Println("Step 2:")17 g = newGame(lines)18 fmt.Println(step2(g))19 fmt.Println(sw.Elapsed())20}21const (22 empty = rune('L')23 occupied = rune('#')24 floor = rune('.')25)26type game struct {27 grid [][]rune28}29// Advance and return the layout30func (g *game) advance1() *game {31 prev := g.clone()32 for ridx, r := range prev.grid {33 for idx, was := range r {34 o := prev.adjacent(ridx, idx)35 if was == empty && o == 0 {36 g.grid[ridx][idx] = occupied37 } else if was == occupied && o > 3 {38 g.grid[ridx][idx] = empty39 }40 }41 }42 return prev43}44// Advance and return the layout45func (g *game) advance2() *game {46 prev := g.clone()47 for ridx, r := range prev.grid {48 for idx, was := range r {49 o := prev.sightlines(ridx, idx)50 if was == empty && o == 0 {51 g.grid[ridx][idx] = occupied52 } else if was == occupied && o > 4 {53 g.grid[ridx][idx] = empty54 }55 }56 }57 return prev58}59// adjacent returns the number of adjacent occupied seats60func (g *game) adjacent(row, col int) int {61 o := 062 for r := row - 1; r <= row+1; r++ {63 if r < 0 || r >= len(g.grid) {64 continue65 }66 for c := col - 1; c <= col+1; c++ {67 if c < 0 || c >= len(g.grid[0]) || (r == row && c == col) {68 continue69 }70 if g.grid[r][c] == occupied {71 o++72 }73 }74 }75 return o76}77var directions = []lib.Point{78 lib.Point{X: -1, Y: -1},79 lib.Point{X: -1, Y: 0},80 lib.Point{X: -1, Y: 1},81 lib.Point{X: 0, Y: -1},82 lib.Point{X: 0, Y: 1},83 lib.Point{X: 1, Y: -1},84 lib.Point{X: 1, Y: 0},85 lib.Point{X: 1, Y: 1},86}87func (g *game) sightlines(row, col int) int {88 o := 089OUTER:90 for _, d := range directions {91 dx, dy := int(d.X), int(d.Y)92 for x, y := col+dx, row+dy; y >= 0 && y < len(g.grid) && x >= 0 && x < len(g.grid[0]); x, y = x+dx, y+dy {93 seen := g.grid[y][x]94 if seen == empty {95 continue OUTER96 } else if seen == occupied {97 o++98 continue OUTER99 }100 }101 }102 return o103}104func (g *game) equals(g2 *game) bool {105 if len(g.grid) != len(g2.grid) {106 return false107 }108 for ridx := range g.grid {109 if len(g.grid[ridx]) != len(g2.grid[ridx]) {110 return false111 }112 for idx, c := range g.grid[ridx] {113 if c != g2.grid[ridx][idx] {114 return false115 }116 }117 }118 return true119}120func (g *game) occupied() int {121 o := 0122 for _, r := range g.grid {123 for _, s := range r {124 if s == occupied {125 o++126 }127 }128 }129 return o130}131func (g *game) clone() *game {132 g2 := game{}133 g2.grid = make([][]rune, len(g.grid))134 for ridx, r := range g.grid {135 g2.grid[ridx] = make([]rune, len(r))136 copy(g2.grid[ridx], r)137 }138 return &g2139}140func (g *game) print() {141 for _, r := range g.grid {142 for _, c := range r {143 fmt.Print(string(c))144 }145 fmt.Print("\n")146 }147}148func newGame(rows []string) *game {149 g := game{}150 g.grid = make([][]rune, len(rows))151 for ridx, r := range rows {152 g.grid[ridx] = make([]rune, len(r))153 for idx, c := range []rune(r) {154 g.grid[ridx][idx] = c155 }156 }157 return &g158}159func step1(g *game) int {160 for {161 prev := g.advance1()162 if prev.equals(g) {163 return g.occupied()164 }165 }166}167func step2(g *game) int {168 for {169 prev := g.advance2()170 if prev.equals(g) {171 return g.occupied()172 }173 }174}...

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1func main() {2 lib.Prev()3}4func main() {5 lib.Next()6}7func main() {8 lib.Next()9}10func main() {11 lib.Prev()12}13func main() {14 lib.Prev()15}16func main() {17 lib.Next()18}19func main() {20 lib.Next()21}22func main() {23 lib.Prev()24}25func main() {26 lib.Prev()27}28func main() {29 lib.Next()30}31func main() {32 lib.Next()33}34func main() {35 lib.Prev()36}37func main() {38 lib.Prev()39}40func main() {41 lib.Next()42}43func main() {44 lib.Next()45}46func main() {47 lib.Prev()48}49func main() {50 lib.Prev()51}

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1lib.Prev(1)2lib.Next(1)3lib.Next(1)4lib.Prev(1)5lib.Prev(1)6lib.Next(1)7lib.Next(1)8lib.Prev(1)9lib.Prev(1)10lib.Next(1)11lib.Next(1)12lib.Prev(1)13lib.Prev(1)14lib.Next(1)15lib.Next(1)16lib.Prev(1)17lib.Prev(1)18lib.Next(1)19lib.Next(1)20lib.Prev(1)21lib.Prev(1)22lib.Next(1)23lib.Next(

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, 世界")4 lib.Prev()5}6import "fmt"7func Prev() {8 fmt.Println("Hello, lib")9}10I am able to import the lib class in main function. But I am not able to use the Prev method of lib class. What am I doing wrong here?11import (12func main() {13 fmt.Println("Hello, 世界")14 lib.Prev()15}16import "fmt"17func Prev() {18 fmt.Println("Hello, lib")19}20I am able to import the lib class in main function. But I am not able to use the Prev method of lib class. What am I doing wrong here?

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(lib.Prev(1))4}5func Prev(i int) int {6}7import "testing"8func TestPrev(t *testing.T) {9 if Prev(1) != 0 {10 t.Error("Prev(1) should be 0")11 }12}13import "testing"14func BenchmarkPrev(b *testing.B) {15 for i := 0; i < b.N; i++ {16 Prev(1)17 }18}19import "fmt"20func ExamplePrev() {21 fmt.Println(Prev(1))22}23func Test(t *testing.T, m *testing.M) {24}25func Benchmark(b *testing.B, m *testing.M) {26}27The testing package has other functions that are used to write tests and benchmarks. Some of the important ones are as follows:28func TestMain(m *testing.M) int: This function is used to setup the test environment. It is called before any other tests are run. It takes one argument:

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1import "lib"2func main() {3 lib.A{}.Prev()4}5type A struct {6}7func (a A) Prev() {8}9type B struct {10}11func (b B) Prev() {12}13import "lib"14func main() {15 lib.B{}.Prev()16}17type A struct {18}19func (a A) Prev() {20}21type B struct {22}23func (b B) Prev() {24}25import "lib"26func main() {27 lib.B{}.Prev()28}29type A struct {30}31func (a A) Prev() {32}33type B struct {34}35func (b B) Prev() {36}

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 golenv.LoadEnv()4}5import (6func main() {7 golenv.LoadEnv()8}9import (10func main() {11 golenv.LoadEnv()12}13import (14func main() {15 golenv.LoadEnv()16}17import (18func main() {19 golenv.LoadEnv()20}21import (22func main() {23 golenv.LoadEnv()24}25import (26func main() {27 golenv.LoadEnv()28}

Full Screen

Full Screen

Prev

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(lib.Prev(10))4}5func Prev(i int) int {6}7import (8func main() {9 fmt.Println(lib.Next(10))10}11func Next(i int) int {12}13import (14func main() {15 fmt.Println(lib.Prev(10))16 fmt.Println(lib.Next(10))17}18func Prev(i int) int {19}20func Next(i int) int {21}22import (23func main() {24 fmt.Println(lib.Prev(10))25 fmt.Println(lib.Next(10))26}27func Prev(i int) int {28}29func Next(i int) int {30}31import (32func main() {33 fmt.Println(lib.Prev(10))34 fmt.Println(lib.Next(10))35}36func Prev(i int) int {37}38func Next(i int) int {39}40import (41func main() {42 fmt.Println(lib.Prev(10))43 fmt.Println(lib.Next(10))44}45func Prev(i int) int {46}47func Next(i int) int {48}49import (50func main()

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.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful