How to use EXPECT method of overlap Package

Best Mock code snippet using overlap.EXPECT

collision_test.go

Source:collision_test.go Github

copy

Full Screen

1package coord2import (3	"github.com/ghthor/filu/sim/stime"4	"github.com/ghthor/gospec"5	. "github.com/ghthor/gospec"6)7func overlapPeakAndDecrease(c gospec.Context, collision PathCollision) float64 {8	start, end := collision.Start(), collision.End()9	// Going to fix this requirement when I implement floating point time10	// The collision needs > 3 steps and 2 of them have to be after the peak11	// This is the easiest way to enforce this12	c.Assume(collision.A.Duration, Satisfies, collision.A.Duration > 1)13	c.Assume(collision.B.Duration, Satisfies, collision.B.Duration > 1)14	overlap := collision.OverlapAt(start)15	c.Expect(overlap, Equals, 0.0)16	prevOverlap := overlap17	peak := overlap18	t := start + 119	for ; t < end; t++ {20		overlap = collision.OverlapAt(t)21		if overlap <= prevOverlap || t == end-1 {22			peak = prevOverlap23			prevOverlap = overlap24			break25		}26		c.Expect(overlap, Satisfies, overlap > prevOverlap)27		prevOverlap = overlap28	}29	c.Expect(peak, Satisfies, peak > collision.OverlapAt(start))30	for ; t <= end; t++ {31		overlap = collision.OverlapAt(t)32		c.Expect(overlap, Satisfies, overlap <= peak)33		c.Expect(overlap, Satisfies, overlap <= prevOverlap)34		prevOverlap = overlap35	}36	overlap = collision.OverlapAt(end)37	c.Expect(overlap, Equals, 0.0)38	return peak39}40func overlapPeakLevelThenDecrease(c gospec.Context, collision PathCollision) {41	start, end := collision.Start(), collision.End()42	// Going to fix this requirement when I implement floating point time43	// The collision needs > 3 steps and 2 of them have to be after the peak44	// This is the easiest way to enforce this45	c.Assume(collision.A.Duration, Satisfies, collision.A.Duration > 1)46	c.Assume(collision.B.Duration, Satisfies, collision.B.Duration > 1)47	overlap := collision.OverlapAt(start)48	c.Expect(overlap, Equals, 0.0)49	prevOverlap := overlap50	peak := overlap51	t := start + 152	for ; t < end; t++ {53		overlap = collision.OverlapAt(t)54		if overlap <= prevOverlap || t == end-1 {55			peak = prevOverlap56			prevOverlap = overlap57			break58		}59		c.Expect(overlap, Satisfies, overlap > prevOverlap)60		prevOverlap = overlap61	}62	c.Expect(peak, Satisfies, peak > collision.OverlapAt(start))63	for ; t <= collision.A.Span.End; t++ {64		overlap = collision.OverlapAt(t)65		c.Expect(overlap, IsWithin(0.0000000000000001), peak)66		prevOverlap = overlap67	}68	for ; t <= end; t++ {69		overlap = collision.OverlapAt(t)70		c.Expect(overlap, Satisfies, overlap < peak)71		c.Expect(overlap, Satisfies, overlap < prevOverlap)72		prevOverlap = overlap73	}74	overlap = collision.OverlapAt(end)75	c.Expect(overlap, Equals, 0.0)76}77func overlapGrowsTo1(c gospec.Context, collision PathCollision) {78	start, end := collision.Start(), collision.End()79	overlap := collision.OverlapAt(start)80	c.Expect(overlap, Equals, 0.0)81	prevOverlap := overlap82	t := start + 183	for ; t < end; t++ {84		overlap = collision.OverlapAt(t)85		c.Expect(overlap, Satisfies, overlap > prevOverlap)86		prevOverlap = overlap87	}88	overlap = collision.OverlapAt(end)89	c.Expect(overlap, Equals, 1.0)90}91func overlapShrinksTo0(c gospec.Context, collision PathCollision) {92	start, end := collision.Start(), collision.End()93	overlap := collision.OverlapAt(start)94	c.Expect(overlap, Equals, 1.0)95	prevOverlap := overlap96	t := start + 197	for ; t < end; t++ {98		overlap = collision.OverlapAt(t)99		c.Expect(overlap, Satisfies, overlap < prevOverlap)100		prevOverlap = overlap101	}102	overlap = collision.OverlapAt(end)103	c.Expect(overlap, Equals, 0.0)104}105func DescribePathCollision(c gospec.Context) {106	var pathA, pathB PathAction107	var collision PathCollision108	c.Specify("when path A is following into path B's position from the side", func() {109		pathA.Span = stime.NewSpan(15, 35)110		pathB.Span = stime.NewSpan(10, 30)111		pathA.Orig = Cell{0, 1}112		pathA.Dest = Cell{0, 0}113		pathB.Orig = pathA.Dest114		pathB.Dest = Cell{1, 0}115		collision = NewPathCollision(pathA, pathB)116		c.Assume(collision.Type(), Equals, CT_A_INTO_B_FROM_SIDE)117		c.Assume(collision.A, Equals, pathA)118		c.Assume(collision.B, Equals, pathB)119		collision = NewPathCollision(pathB, pathA)120		c.Assume(collision.Type(), Equals, CT_A_INTO_B_FROM_SIDE)121		c.Assume(collision.A, Equals, pathA)122		c.Assume(collision.B, Equals, pathB)123		c.Specify("the collision will begin when", func() {124			specs := [...]struct {125				A, B        stime.Span126				description string127			}{{128				stime.NewSpan(15, 35),129				stime.NewSpan(10, 30),130				"when path A starts if path A starts after path B",131			}, {132				stime.NewSpan(10, 30),133				stime.NewSpan(15, 35),134				"when path A starts if path A starts before path B",135			}, {136				stime.NewSpan(10, 30),137				stime.NewSpan(10, 30),138				"when path A and path B start at the same time",139			}}140			for _, spec := range specs {141				c.Specify(spec.description, func() {142					pathA.Span = spec.A143					pathB.Span = spec.B144					c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathA.Span.Start)145					c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathA.Span.Start)146				})147			}148		})149		c.Specify("the collision will end when", func() {150			specs := [...]struct {151				A, B        stime.Span152				description string153			}{{154				stime.NewSpan(15, 35),155				stime.NewSpan(10, 30),156				"when path B ends if path B ends before path A",157			}, {158				stime.NewSpan(10, 30),159				stime.NewSpan(15, 35),160				"when path B ends if path B ends after path A",161			}, {162				stime.NewSpan(10, 30),163				stime.NewSpan(10, 30),164				"when path A and path B end at the same time",165			}}166			for _, spec := range specs {167				c.Specify(spec.description, func() {168					pathA.Span = spec.A169					pathB.Span = spec.B170					c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathB.Span.End)171					c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathB.Span.End)172				})173			}174		})175		specs := [...]struct {176			A, B        stime.Span177			description string178		}{{179			stime.NewSpan(15, 35),180			stime.NewSpan(10, 30),181			"when path B ends before path A",182		}, {183			stime.NewSpan(10, 30),184			stime.NewSpan(15, 35),185			"when path B ends after path A",186		}, {187			stime.NewSpan(10, 30),188			stime.NewSpan(10, 30),189			"when path A and path B end at the same time",190		}}191		for _, spec := range specs {192			c.Specify(spec.description+" the overlap will grow to a peak and decrease till path B ends", func() {193				pathA.Span = spec.A194				pathB.Span = spec.B195				overlapPeakAndDecrease(c, NewPathCollision(pathA, pathB))196				overlapPeakAndDecrease(c, NewPathCollision(pathB, pathA))197			})198		}199		c.Specify("when B starts as A ends the peak will be 1.0", func() {200			pathA.Span = stime.NewSpan(10, 30)201			pathB.Span = stime.NewSpan(30, 40)202			peak := overlapPeakAndDecrease(c, NewPathCollision(pathA, pathB))203			c.Expect(peak, Equals, 1.0)204			peak = overlapPeakAndDecrease(c, NewPathCollision(pathB, pathA))205			c.Expect(peak, Equals, 1.0)206		})207	})208	c.Specify("when path A is following into path B's position in the same direction", func() {209		pathA.Span = stime.NewSpan(5, 25)210		pathB.Span = stime.NewSpan(10, 30)211		pathA.Orig = Cell{-1, 0}212		pathA.Dest = Cell{0, 0}213		pathB.Orig = pathA.Dest214		pathB.Dest = Cell{1, 0}215		collision = NewPathCollision(pathA, pathB)216		c.Assume(collision.Type(), Equals, CT_A_INTO_B)217		c.Assume(collision.A, Equals, pathA)218		c.Assume(collision.B, Equals, pathB)219		collision = NewPathCollision(pathB, pathA)220		c.Assume(collision.Type(), Equals, CT_A_INTO_B)221		c.Assume(collision.A, Equals, pathA)222		c.Assume(collision.B, Equals, pathB)223		c.Specify("will not collide if path A doesn't end before path B", func() {224			pathA.Span.End = pathB.Span.End225			expectations := func() {226				collision = NewPathCollision(pathA, pathB)227				c.Expect(collision.Type(), Equals, CT_NONE)228				collision = NewPathCollision(pathB, pathA)229				c.Expect(collision.Type(), Equals, CT_NONE)230			}231			c.Specify("and starts at the same time as path B", func() {232				pathA.Span.Start = pathB.Span.Start233				expectations()234			})235			c.Specify("and starts after path B", func() {236				pathA.Span.Start = pathB.Span.Start + 1237				expectations()238			})239		})240		c.Specify("the collision will begin when", func() {241			c.Specify("path A starts if path A starts before path B", func() {242				pathA.Span.Start = pathB.Span.Start - 1243				collision = NewPathCollision(pathA, pathB)244				c.Expect(collision.Start(), Equals, pathA.Span.Start)245				c.Specify("and ends when path B completes", func() {246					c.Expect(collision.End(), Equals, pathB.Span.End)247				})248			})249			c.Specify("they both start if they both start at the same time", func() {250				pathA.Span = stime.NewSpan(10, 20)251				pathB.Span = stime.NewSpan(10, 21)252				collision = NewPathCollision(pathA, pathB)253				c.Expect(collision.Start(), Equals, pathA.Span.Start)254				c.Expect(collision.Start(), Equals, pathB.Span.Start)255				c.Specify("and ends when path B completes", func() {256					c.Expect(collision.End(), Equals, pathB.Span.End)257				})258			})259			c.Specify("path A catchs path B if path B starts before path A", func() {260				for i := stime.Time(0); i <= 5*10; i += 5 {261					pathA.Span = stime.NewSpan(2+i, 12+i)262					pathB.Span = stime.NewSpan(0+i, 20+i)263					collision = NewPathCollision(pathA, pathB)264					c.Expect(collision.Start(), Equals, stime.Time(4+i))265				}266				pathA.Span = stime.NewSpan(3, 10)267				pathB.Span = stime.NewSpan(2, 13)268				collision = NewPathCollision(pathA, pathB)269				c.Expect(collision.Start(), Equals, stime.Time(4))270				c.Specify("and ends when path B completes", func() {271					c.Expect(collision.End(), Equals, pathB.Span.End)272				})273			})274		})275		specs := [...]struct {276			A, B        stime.Span277			description string278		}{{279			pathA.Span,280			pathB.Span,281			"when path A starts before path B",282		}, {283			stime.NewSpan(10, 30),284			stime.NewSpan(10, 40),285			"when path A and path B start together",286		}, {287			stime.NewSpan(10, 30),288			stime.NewSpan(5, 40),289			"when path A starts after path B",290		}}291		for _, spec := range specs {292			c.Specify(spec.description+" the overlap will grow to a peak and then decrease", func() {293				pathA.Span = spec.A294				pathB.Span = spec.B295				overlapPeakAndDecrease(c, NewPathCollision(pathA, pathB))296				overlapPeakAndDecrease(c, NewPathCollision(pathB, pathA))297			})298		}299		c.Specify("they have the same speed the overlap will grow to a peak and stay level until B completes", func() {300			pathA.Span = stime.NewSpan(10, 30)301			pathB.Span = stime.NewSpan(15, 35)302			overlapPeakLevelThenDecrease(c, NewPathCollision(pathA, pathB))303			overlapPeakLevelThenDecrease(c, NewPathCollision(pathB, pathA))304		})305	})306	c.Specify("when path A has the same destination as path B and the paths are opposing", func() {307		m, n, o := Cell{-1, 0}, Cell{0, 0}, Cell{1, 0}308		pathA = PathAction{stime.NewSpan(10, 30), m, n}309		pathB = PathAction{stime.NewSpan(10, 30), o, n}310		collision = NewPathCollision(pathA, pathB)311		c.Assume(collision.Type(), Equals, CT_HEAD_TO_HEAD)312		c.Assume(collision.A, Equals, pathA)313		c.Assume(collision.B, Equals, pathB)314		collision = NewPathCollision(pathB, pathA)315		c.Assume(collision.Type(), Equals, CT_HEAD_TO_HEAD)316		c.Assume(collision.A, Equals, pathB)317		c.Assume(collision.B, Equals, pathA)318		c.Specify("the collision begins when", func() {319			c.Specify("path A starts if path A starts when path B ends", func() {320				pathA.Span = stime.NewSpan(30, 50)321				pathB.Span = stime.NewSpan(10, 30)322				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathA.Span.Start)323				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathA.Span.Start)324			})325			c.Specify("path B starts if path B starts when path A ends", func() {326				pathA.Span = stime.NewSpan(10, 30)327				pathB.Span = stime.NewSpan(30, 50)328				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathB.Span.Start)329				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathB.Span.Start)330			})331		})332		c.Specify("the collision begins when path A meets path B", func() {333			pathA.Span = stime.NewSpan(0, 10)334			pathB.Span = stime.NewSpan(0, 10)335			c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, stime.Time(5))336			c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, stime.Time(5))337			pathA.Span = stime.NewSpan(2, 12)338			pathB.Span = stime.NewSpan(0, 10)339			c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, stime.Time(6))340			c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, stime.Time(6))341			pathA.Span = stime.NewSpan(3, 13)342			pathB.Span = stime.NewSpan(4, 14)343			// Float answer is 8.5344			c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, stime.Time(8))345			c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, stime.Time(8))346			pathA.Span = stime.NewSpan(3, 17)347			pathB.Span = stime.NewSpan(5, 11)348			// Float answer is 8 * 3/19349			c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, stime.Time(8))350			c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, stime.Time(8))351		})352		c.Specify("the collision ends when", func() {353			c.Specify("path A ends if it ends after Path B", func() {354				pathA.Span = stime.NewSpan(10, 30)355				pathB.Span = stime.NewSpan(5, 25)356				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathA.Span.End)357				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathA.Span.End)358			})359			c.Specify("path B ends if it ends after Path A", func() {360				pathA.Span = stime.NewSpan(5, 25)361				pathB.Span = stime.NewSpan(10, 30)362				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathB.Span.End)363				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathB.Span.End)364			})365		})366		specs := [...]struct {367			A, B        stime.Span368			description string369		}{{370			pathA.Span,371			pathB.Span,372			"and path A and B have the same time span",373		}, {374			stime.NewSpan(5, 25),375			stime.NewSpan(15, 35),376			"and path A starts and ends before path B",377		}, {378			stime.NewSpan(15, 35),379			stime.NewSpan(5, 25),380			"and path B starts and ends before path A",381		}, {382			stime.NewSpan(5, 35),383			stime.NewSpan(15, 25),384			"and path A starts before and ends after path B",385		}, {386			stime.NewSpan(15, 25),387			stime.NewSpan(5, 35),388			"and path B starts before and ends after path A",389		}, {390			stime.NewSpan(5, 25),391			stime.NewSpan(10, 25),392			"and path A starts before and ends with path B",393		}, {394			stime.NewSpan(10, 25),395			stime.NewSpan(5, 25),396			"and path B starts before and ends with path A",397		}, {398			stime.NewSpan(10, 25),399			stime.NewSpan(10, 30),400			"and path A starts with and ends before path B",401		}, {402			stime.NewSpan(10, 30),403			stime.NewSpan(10, 25),404			"and path B starts with and ends before path A",405		}}406		for _, spec := range specs {407			c.Specify(spec.description+" overlap will grow from 0.0 to 1.0", func() {408				pathA.Span = spec.A409				pathB.Span = spec.B410				overlapGrowsTo1(c, NewPathCollision(pathA, pathB))411				overlapGrowsTo1(c, NewPathCollision(pathB, pathA))412			})413		}414	})415	c.Specify("when path A has the same destination as path B and the paths are perpendicular", func() {416		// Side 1417		m, n, o := Cell{-1, 0}, Cell{0, 0}, Cell{0, 1}418		pathA = PathAction{stime.NewSpan(10, 30), m, n}419		pathB = PathAction{stime.NewSpan(10, 30), o, n}420		collision = NewPathCollision(pathA, pathB)421		c.Assume(collision.Type(), Equals, CT_FROM_SIDE)422		c.Assume(collision.A, Equals, pathA)423		c.Assume(collision.B, Equals, pathB)424		collision = NewPathCollision(pathB, pathA)425		c.Assume(collision.Type(), Equals, CT_FROM_SIDE)426		c.Assume(collision.A, Equals, pathB)427		c.Assume(collision.B, Equals, pathA)428		// Side 2429		m, n, o = Cell{-1, 0}, Cell{0, 0}, Cell{0, -1}430		pathA = PathAction{stime.NewSpan(10, 30), m, n}431		pathB = PathAction{stime.NewSpan(10, 30), o, n}432		collision = NewPathCollision(pathA, pathB)433		c.Assume(collision.Type(), Equals, CT_FROM_SIDE)434		c.Assume(collision.A, Equals, pathA)435		c.Assume(collision.B, Equals, pathB)436		collision = NewPathCollision(pathB, pathA)437		c.Assume(collision.Type(), Equals, CT_FROM_SIDE)438		c.Assume(collision.A, Equals, pathB)439		c.Assume(collision.B, Equals, pathA)440		c.Specify("the collision begins when", func() {441			c.Specify("path A starts if path B starts first", func() {442				pathA.Span = stime.NewSpan(10, 30)443				pathB.Span = stime.NewSpan(5, 25)444				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathA.Span.Start)445				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathA.Span.Start)446			})447			c.Specify("path B starts if path A starts first", func() {448				pathA.Span = stime.NewSpan(5, 25)449				pathB.Span = stime.NewSpan(10, 30)450				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathB.Span.Start)451				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathB.Span.Start)452			})453		})454		c.Specify("the collision ends when", func() {455			c.Specify("path A ends if it ends after Path B", func() {456				pathA.Span = stime.NewSpan(10, 30)457				pathB.Span = stime.NewSpan(5, 25)458				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathA.Span.End)459				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathA.Span.End)460			})461			c.Specify("path B ends if it ends after Path A", func() {462				pathA.Span = stime.NewSpan(5, 25)463				pathB.Span = stime.NewSpan(10, 30)464				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathB.Span.End)465				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathB.Span.End)466			})467		})468		specs := [...]struct {469			A, B        stime.Span470			description string471		}{{472			pathA.Span,473			pathB.Span,474			"and path A and B have the same time span",475		}, {476			stime.NewSpan(5, 25),477			stime.NewSpan(15, 35),478			"and path A starts and ends before path B",479		}, {480			stime.NewSpan(15, 35),481			stime.NewSpan(5, 25),482			"and path B starts and ends before path A",483		}, {484			stime.NewSpan(5, 35),485			stime.NewSpan(15, 25),486			"and path A starts before and ends after path B",487		}, {488			stime.NewSpan(15, 25),489			stime.NewSpan(5, 35),490			"and path B starts before and ends after path A",491		}, {492			stime.NewSpan(5, 25),493			stime.NewSpan(10, 25),494			"and path A starts before and ends with path B",495		}, {496			stime.NewSpan(10, 25),497			stime.NewSpan(5, 25),498			"and path B starts before and ends with path A",499		}, {500			stime.NewSpan(10, 25),501			stime.NewSpan(10, 30),502			"and path A starts with and ends before path B",503		}, {504			stime.NewSpan(10, 30),505			stime.NewSpan(10, 25),506			"and path B starts with and ends before path A",507		}}508		for _, spec := range specs {509			c.Specify(spec.description+" overlap will grow from 0.0 to 1.0", func() {510				pathA.Span = spec.A511				pathB.Span = spec.B512				overlapGrowsTo1(c, NewPathCollision(pathA, pathB))513				overlapGrowsTo1(c, NewPathCollision(pathB, pathA))514			})515		}516	})517	c.Specify("when path A and path B are inverses of each other", func() {518		a, b := Cell{0, 0}, Cell{1, 0}519		pathA = PathAction{Orig: a, Dest: b}520		pathB = PathAction{Orig: b, Dest: a}521		pathA.Span = stime.NewSpan(10, 30)522		pathB.Span = stime.NewSpan(10, 30)523		collision = NewPathCollision(pathA, pathB)524		c.Assume(collision.Type(), Equals, CT_SWAP)525		c.Assume(collision.A, Equals, pathA)526		c.Assume(collision.B, Equals, pathB)527		collision = NewPathCollision(pathB, pathA)528		c.Assume(collision.Type(), Equals, CT_SWAP)529		c.Assume(collision.A, Equals, pathB)530		c.Assume(collision.B, Equals, pathA)531		c.Specify("the collision begins when either start moving", func() {532			c.Specify("path A starts first", func() {533				pathB.Span.Start = pathA.Span.Start + 1534				collision = NewPathCollision(pathA, pathB)535				c.Expect(collision.Start(), Equals, pathA.Start())536				collision = NewPathCollision(pathB, pathA)537				c.Expect(collision.Start(), Equals, pathA.Start())538			})539			c.Specify("path B starts first", func() {540				pathA.Span.Start = pathB.Span.Start + 1541				collision = NewPathCollision(pathA, pathB)542				c.Expect(collision.Start(), Equals, pathB.Start())543				collision = NewPathCollision(pathB, pathA)544				c.Expect(collision.Start(), Equals, pathB.Start())545			})546		})547		c.Specify("the collision ends when the last one moving ends", func() {548			c.Specify("path A ends last", func() {549				pathA.Span.End = pathB.Span.End + 1550				collision = NewPathCollision(pathA, pathB)551				c.Expect(collision.End(), Equals, pathA.End())552				collision = NewPathCollision(pathB, pathA)553				c.Expect(collision.End(), Equals, pathA.End())554			})555			c.Specify("path B ends last", func() {556				pathB.Span.End = pathA.Span.End + 1557				collision = NewPathCollision(pathA, pathB)558				c.Expect(collision.End(), Equals, pathB.End())559				collision = NewPathCollision(pathB, pathA)560				c.Expect(collision.End(), Equals, pathB.End())561			})562		})563		specs := [...]struct {564			A, B        stime.Span565			description string566		}{{567			pathA.Span,568			pathB.Span,569			"and the time span's are equal",570		}, {571			stime.NewSpan(10, 90),572			stime.NewSpan(31, 69),573			"and one starts before and ends after the other",574		}, {575			stime.NewSpan(28, 30),576			stime.NewSpan(30, 32),577			"and one starts as the other ends",578		}, {579			stime.NewSpan(20, 30),580			stime.NewSpan(40, 50),581			"and one starts after the other ends",582		}}583		for _, spec := range specs {584			c.Specify(spec.description+" the overlap will grow to a peak and then decreases", func() {585				pathA.Span = spec.A586				pathB.Span = spec.B587				overlapPeakAndDecrease(c, NewPathCollision(pathA, pathB))588				overlapPeakAndDecrease(c, NewPathCollision(pathB, pathA))589			})590		}591	})592	c.Specify("when path A and path B have the same origin and their facings are inverse", func() {593		o := Cell{0, 0}594		pathA = PathAction{stime.NewSpan(10, 30), o, o.Neighbor(South)}595		pathB = PathAction{stime.NewSpan(10, 30), o, o.Neighbor(North)}596		c.Assume(NewPathCollision(pathA, pathB).Type(), Equals, CT_SAME_ORIG)597		c.Assume(NewPathCollision(pathB, pathA).Type(), Equals, CT_SAME_ORIG)598		c.Specify("the collision will begin when either path starts", func() {599			c.Specify("path A starts first", func() {600				pathA.Span = stime.NewSpan(5, 25)601				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathA.Span.Start)602				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathA.Span.Start)603			})604			c.Specify("path B starts first", func() {605				pathB.Span = stime.NewSpan(5, 25)606				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathB.Span.Start)607				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathB.Span.Start)608			})609		})610		c.Specify("the collision will end if one finishs as the other starts", func() {611			c.Specify("path A ends when path B starts", func() {612				pathA.Span = stime.NewSpan(10, 30)613				pathB.Span = stime.NewSpan(30, 40)614				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathA.Span.End)615				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathA.Span.End)616			})617			c.Specify("path B ends when path B starts", func() {618				pathA.Span = stime.NewSpan(30, 40)619				pathB.Span = stime.NewSpan(10, 30)620				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathB.Span.End)621				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathB.Span.End)622			})623		})624		c.Specify("the collision will end when the paths no longer overlap", func() {625			pathA.Span = stime.NewSpan(0, 10)626			pathB.Span = stime.NewSpan(0, 10)627			c.Expect(NewPathCollision(pathA, pathB).End(), Equals, stime.Time(5))628			c.Expect(NewPathCollision(pathB, pathA).End(), Equals, stime.Time(5))629			pathA.Span = stime.NewSpan(2, 12)630			pathB.Span = stime.NewSpan(0, 10)631			c.Expect(NewPathCollision(pathA, pathB).End(), Equals, stime.Time(6))632			c.Expect(NewPathCollision(pathB, pathA).End(), Equals, stime.Time(6))633			pathA.Span = stime.NewSpan(3, 13)634			pathB.Span = stime.NewSpan(4, 14)635			// Float answer is 8.5636			c.Expect(NewPathCollision(pathA, pathB).End(), Equals, stime.Time(9))637			c.Expect(NewPathCollision(pathB, pathA).End(), Equals, stime.Time(9))638			pathA.Span = stime.NewSpan(3, 17)639			pathB.Span = stime.NewSpan(5, 11)640			// Float answer is 8 * 3/19641			c.Expect(NewPathCollision(pathA, pathB).End(), Equals, stime.Time(9))642			c.Expect(NewPathCollision(pathB, pathA).End(), Equals, stime.Time(9))643		})644		specs := [...]struct {645			A, B        stime.Span646			description string647		}{{648			stime.NewSpan(10, 30),649			stime.NewSpan(10, 30),650			"when path A and B start and end at the same time",651		}, {652			stime.NewSpan(10, 30),653			stime.NewSpan(30, 50),654			"when path A ends as path B starts",655		}, {656			stime.NewSpan(10, 30),657			stime.NewSpan(20, 40),658			"when path A starts and ends before path B",659		}, {660			stime.NewSpan(10, 30),661			stime.NewSpan(20, 30),662			"when path A starts before and ends with path B",663		}, {664			stime.NewSpan(10, 30),665			stime.NewSpan(20, 25),666			"when path A starts before and ends after path B",667		}}668		for _, spec := range specs {669			c.Specify(spec.description+" the overlap will start at 1.0 and decrease to 0.0", func() {670				pathA.Span = spec.A671				pathB.Span = spec.B672				overlapShrinksTo0(c, NewPathCollision(pathA, pathB))673				overlapShrinksTo0(c, NewPathCollision(pathB, pathA))674			})675		}676	})677	c.Specify("when path A and path B share the same origin and destination", func() {678		o, d := Cell{0, 0}, Cell{1, 0}679		pathA = PathAction{stime.NewSpan(10, 30), o, d}680		pathB = PathAction{stime.NewSpan(10, 30), o, d}681		c.Assume(NewPathCollision(pathA, pathB).Type(), Equals, CT_SAME_ORIG_DEST)682		c.Assume(NewPathCollision(pathB, pathA).Type(), Equals, CT_SAME_ORIG_DEST)683		c.Specify("the collision begins when either path starts", func() {684			c.Specify("path A starts first", func() {685				pathA.Span = stime.NewSpan(5, 25)686				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathA.Span.Start)687				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathA.Span.Start)688			})689			c.Specify("path B starts first", func() {690				pathB.Span = stime.NewSpan(5, 25)691				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathB.Span.Start)692				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathB.Span.Start)693			})694		})695		c.Specify("the collision ends when both paths have completed", func() {696			c.Specify("path A finishes last", func() {697				pathA.Span = stime.NewSpan(15, 35)698				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathA.Span.End)699				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathA.Span.End)700			})701			c.Specify("path B finishes last", func() {702				pathB.Span = stime.NewSpan(15, 35)703				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathB.Span.End)704				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathB.Span.End)705			})706		})707		c.Specify("the overlap will decrease to a trough and the grow back to 1.0", func() {})708		c.Specify("the overlap will be 1.0 for the duration of the collision", func() {})709	})710	c.Specify("when path A and path B share the same origin and are perpendicular", func() {711		o := Cell{0, 0}712		pathA = PathAction{stime.NewSpan(10, 30), o, o.Neighbor(North)}713		pathB = PathAction{stime.NewSpan(10, 30), o, o.Neighbor(East)}714		c.Specify("a same origin collision is identified", func() {715			c.Expect(NewPathCollision(pathA, pathB).Type(), Equals, CT_SAME_ORIG_PERP)716			c.Expect(NewPathCollision(pathB, pathA).Type(), Equals, CT_SAME_ORIG_PERP)717			pathB = PathAction{stime.NewSpan(10, 30), o, o.Neighbor(West)}718			c.Expect(NewPathCollision(pathA, pathB).Type(), Equals, CT_SAME_ORIG_PERP)719			c.Expect(NewPathCollision(pathB, pathA).Type(), Equals, CT_SAME_ORIG_PERP)720		})721		c.Specify("the collision begins when either path starts first", func() {722			c.Specify("path A starts first", func() {723				pathA.Span = stime.NewSpan(5, 25)724				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathA.Span.Start)725				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathA.Span.Start)726			})727			c.Specify("path B starts first", func() {728				pathB.Span = stime.NewSpan(5, 25)729				c.Expect(NewPathCollision(pathA, pathB).Start(), Equals, pathB.Span.Start)730				c.Expect(NewPathCollision(pathB, pathA).Start(), Equals, pathB.Span.Start)731			})732		})733		c.Specify("the collision ends when the first one finishes", func() {734			c.Specify("path A finishes first", func() {735				pathA.Span = stime.NewSpan(5, 25)736				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathA.Span.End)737				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathA.Span.End)738			})739			c.Specify("path B finishes first", func() {740				pathB.Span = stime.NewSpan(5, 25)741				c.Expect(NewPathCollision(pathA, pathB).End(), Equals, pathB.Span.End)742				c.Expect(NewPathCollision(pathB, pathA).End(), Equals, pathB.Span.End)743			})744		})745		c.Specify("the overlap will start at 1.0 and decrease to 0.0", func() {746			overlapShrinksTo0(c, NewPathCollision(pathA, pathB))747			overlapShrinksTo0(c, NewPathCollision(pathB, pathA))748		})749	})750}751func DescribeCellCollision(c gospec.Context) {752	c.Specify("a cell-path collision can be calculated", func() {753		c.Specify("as not happening", func() {754			cell := Cell{0, 0}755			path := PathAction{756				Span: stime.NewSpan(10, 20),757				Orig: Cell{1, 1},758				Dest: Cell{1, 0},759			}760			collision := path.CollidesWith(cell)761			c.Expect(collision.Type(), Equals, CT_NONE)762		})763		c.Specify("if the path's origin is the cell", func() {764			cell := Cell{0, 0}765			path := PathAction{766				Span: stime.NewSpan(10, 20),767				Orig: cell,768				Dest: Cell{1, 0},769			}770			collision := path.CollidesWith(cell)771			c.Assume(collision.Type(), Equals, CT_CELL_ORIG)772			c.Assume(collision.(CellCollision).Cell, Equals, cell)773			c.Assume(collision.(CellCollision).Path, Equals, path)774			c.Specify("the overlap will begin at 1.0 and decrease to 0.0", func() {775				start, end := collision.Start(), collision.End()776				overlap := collision.OverlapAt(start)777				c.Expect(overlap, Equals, 1.0)778				prevOverlap := overlap779				for i := start + 1; i < end; i++ {780					overlap = collision.OverlapAt(i)781					c.Expect(overlap, Satisfies, overlap < prevOverlap)782					prevOverlap = overlap783				}784				c.Expect(collision.OverlapAt(end), Equals, 0.0)785			})786		})787		c.Specify("if the path's destination is the cell", func() {788			cell := Cell{0, 0}789			path := PathAction{790				Span: stime.NewSpan(10, 30),791				Orig: Cell{1, 0},792				Dest: cell,793			}794			collision := path.CollidesWith(cell)795			c.Assume(collision.Type(), Equals, CT_CELL_DEST)796			c.Assume(collision.(CellCollision).Cell, Equals, cell)797			c.Assume(collision.(CellCollision).Path, Equals, path)798			c.Specify("the overlap will begin at 0.0 and grow to 1.0", func() {799				start, end := collision.Start(), collision.End()800				overlap := collision.OverlapAt(start)801				c.Expect(overlap, Equals, 0.0)802				prevOverlap := overlap803				for i := start + 1; i < end; i++ {804					overlap = collision.OverlapAt(i)805					c.Expect(overlap, Satisfies, overlap > prevOverlap)806					prevOverlap = overlap807				}808				c.Expect(collision.OverlapAt(end), Equals, 1.0)809			})810		})811	})812}...

Full Screen

Full Screen

bbox_test.go

Source:bbox_test.go Github

copy

Full Screen

1package polygol2import (3	"testing"4)5func equalBbox(bb1, bb2 bbox) bool {6	return bb1.ll.x == bb2.ll.x &&7		bb1.ll.y == bb2.ll.y &&8		bb1.ur.x == bb2.ur.x &&9		bb1.ur.y == bb2.ur.y10}11func TestisInBbox(t *testing.T) {12	var b bbox13	// outside14	b = bbox{ll: point{x: 1, y: 2}, ur: point{x: 5, y: 6}}15	expect(t, !b.isInBbox(point{x: 0, y: 3}))16	expect(t, !b.isInBbox(point{x: 3, y: 30}))17	expect(t, !b.isInBbox(point{x: 3, y: -30}))18	expect(t, !b.isInBbox(point{x: 9, y: 3}))19	// inside20	b = bbox{ll: point{x: 1, y: 2}, ur: point{x: 5, y: 6}}21	expect(t, b.isInBbox(point{x: 1, y: 2}))22	expect(t, b.isInBbox(point{x: 5, y: 6}))23	expect(t, b.isInBbox(point{x: 1, y: 6}))24	expect(t, b.isInBbox(point{x: 5, y: 2}))25	expect(t, b.isInBbox(point{x: 3, y: 4}))26	// barely inside & outside27	b = bbox{ll: point{x: 1, y: 0.8}, ur: point{x: 1.2, y: 6}}28	expect(t, b.isInBbox(point{x: 1.2 - epsilon, y: 6}))29	expect(t, !b.isInBbox(point{x: 1.2 + epsilon, y: 6}))30	expect(t, b.isInBbox(point{x: 1, y: 0.8 + epsilon}))31	expect(t, !b.isInBbox(point{x: 1, y: 0.8 - epsilon}))32}33func TestBboxOverlap(t *testing.T) {34	var b1, b2 bbox35	b1 = bbox{ll: point{x: 4, y: 4}, ur: point{x: 6, y: 6}}36	// disjoint - none37	// above38	b2 = bbox{ll: point{x: 7, y: 7}, ur: point{x: 8, y: 8}}39	expect(t, b1.getBboxOverlap(b2) == nil)40	// left41	b2 = bbox{ll: point{x: 1, y: 5}, ur: point{x: 3, y: 8}}42	expect(t, b1.getBboxOverlap(b2) == nil)43	// down44	b2 = bbox{ll: point{x: 2, y: 2}, ur: point{x: 3, y: 3}}45	expect(t, b1.getBboxOverlap(b2) == nil)46	// right47	b2 = bbox{ll: point{x: 12, y: 1}, ur: point{x: 14, y: 9}}48	expect(t, b1.getBboxOverlap(b2) == nil)49	// touching - one point50	// upper right corner of 151	b2 = bbox{ll: point{x: 6, y: 6}, ur: point{x: 7, y: 8}}52	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 6, y: 6}, ur: point{x: 6, y: 6}}))53	// upper left corner of 154	b2 = bbox{ll: point{x: 3, y: 6}, ur: point{x: 4, y: 8}}55	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 6}, ur: point{x: 4, y: 6}}))56	// lower left corner of 157	b2 = bbox{ll: point{x: 0, y: 0}, ur: point{x: 4, y: 4}}58	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 4}, ur: point{x: 4, y: 4}}))59	// lower right corner of 160	b2 = bbox{ll: point{x: 6, y: 0}, ur: point{x: 12, y: 4}}61	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 6, y: 4}, ur: point{x: 6, y: 4}}))62	// overlapping - two points63	// full overlap64	// matching bboxes65	expect(t, equalBbox(*b1.getBboxOverlap(b1), b1))66	// one side & two corners matching67	b2 = bbox{ll: point{x: 4, y: 4}, ur: point{x: 5, y: 6}}68	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 4}, ur: point{x: 5, y: 6}}))69	// one corner matching, part of two sides70	b2 = bbox{ll: point{x: 5, y: 4}, ur: point{x: 6, y: 5}}71	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 5, y: 4}, ur: point{x: 6, y: 5}}))72	// part of a side matching, no corners73	b2 = bbox{ll: point{x: 4.5, y: 4.5}, ur: point{x: 5.5, y: 6}}74	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4.5, y: 4.5}, ur: point{x: 5.5, y: 6}}))75	// completely enclosed - no side or corner matching76	b2 = bbox{ll: point{x: 4.5, y: 5}, ur: point{x: 5.5, y: 5.5}}77	expect(t, equalBbox(*b1.getBboxOverlap(b2), b2))78	// partial overlap79	// full side overlap80	b2 = bbox{ll: point{x: 3, y: 4}, ur: point{x: 5, y: 6}}81	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 4}, ur: point{x: 5, y: 6}}))82	// partial side overlap83	b2 = bbox{ll: point{x: 5, y: 4.5}, ur: point{x: 7, y: 5.5}}84	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 5, y: 4.5}, ur: point{x: 6, y: 5.5}}))85	// corner overlap86	b2 = bbox{ll: point{x: 5, y: 5}, ur: point{x: 7, y: 7}}87	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 5, y: 5}, ur: point{x: 6, y: 6}}))88	// line bboxes89	// vertical line & normal90	// no overlap91	b2 = bbox{ll: point{x: 7, y: 3}, ur: point{x: 7, y: 6}}92	expect(t, b1.getBboxOverlap(b2) == nil)93	// point overlap94	b2 = bbox{ll: point{x: 6, y: 0}, ur: point{x: 6, y: 4}}95	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 6, y: 4}, ur: point{x: 6, y: 4}}))96	// line overlap97	b2 = bbox{ll: point{x: 5, y: 0}, ur: point{x: 5, y: 9}}98	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 5, y: 4}, ur: point{x: 5, y: 6}}))99	// horizontal line & normal100	// no overlap101	b2 = bbox{ll: point{x: 3, y: 7}, ur: point{x: 6, y: 7}}102	expect(t, b1.getBboxOverlap(b2) == nil)103	// point overlap104	b2 = bbox{ll: point{x: 1, y: 6}, ur: point{x: 4, y: 6}}105	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 6}, ur: point{x: 4, y: 6}}))106	// line overlap107	b2 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 6, y: 6}}108	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 6}, ur: point{x: 6, y: 6}}))109	// two vertical lines110	var v1, v2 bbox111	v1 = bbox{ll: point{x: 4, y: 4}, ur: point{x: 4, y: 6}}112	// no overlap113	v2 = bbox{ll: point{x: 4, y: 7}, ur: point{x: 4, y: 8}}114	expect(t, v1.getBboxOverlap(v2) == nil)115	// point overlap116	v2 = bbox{ll: point{x: 4, y: 3}, ur: point{x: 4, y: 4}}117	expect(t, equalBbox(*v1.getBboxOverlap(v2), bbox{ll: point{x: 4, y: 4}, ur: point{x: 4, y: 4}}))118	// line overlap119	v2 = bbox{ll: point{x: 4, y: 3}, ur: point{x: 4, y: 5}}120	expect(t, equalBbox(*v1.getBboxOverlap(v2), bbox{ll: point{x: 4, y: 4}, ur: point{x: 4, y: 5}}))121	// two horizontal lines122	var h1, h2 bbox123	h1 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 7, y: 6}}124	// no overlap125	h2 = bbox{ll: point{x: 4, y: 5}, ur: point{x: 7, y: 5}}126	expect(t, h1.getBboxOverlap(h2) == nil)127	// point overlap128	h2 = bbox{ll: point{x: 7, y: 6}, ur: point{x: 8, y: 6}}129	expect(t, equalBbox(*h1.getBboxOverlap(h2), bbox{ll: point{x: 7, y: 6}, ur: point{x: 7, y: 6}}))130	// line overlap131	h2 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 7, y: 6}}132	expect(t, equalBbox(*h1.getBboxOverlap(h2), bbox{ll: point{x: 4, y: 6}, ur: point{x: 7, y: 6}}))133	// horizontal & vertical lines134	// no overlap135	h1 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 8, y: 6}}136	v1 = bbox{ll: point{x: 5, y: 7}, ur: point{x: 5, y: 9}}137	expect(t, h1.getBboxOverlap(v1) == nil)138	// point overlap139	h1 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 8, y: 6}}140	v1 = bbox{ll: point{x: 5, y: 5}, ur: point{x: 5, y: 9}}141	expect(t, equalBbox(*h1.getBboxOverlap(v1), bbox{ll: point{x: 5, y: 6}, ur: point{x: 5, y: 6}}))142	// produced line box143	// horizontal144	b2 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 8, y: 8}}145	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 4, y: 6}, ur: point{x: 6, y: 6}}))146	// vertical147	b2 = bbox{ll: point{x: 6, y: 2}, ur: point{x: 8, y: 8}}148	expect(t, equalBbox(*b1.getBboxOverlap(b2), bbox{ll: point{x: 6, y: 4}, ur: point{x: 6, y: 6}}))149	// point bboxes150	var p bbox151	// point & normal152	// no overlap153	p = bbox{ll: point{x: 2, y: 2}, ur: point{x: 2, y: 2}}154	expect(t, b1.getBboxOverlap(p) == nil)155	// point overlap156	p = bbox{ll: point{x: 5, y: 5}, ur: point{x: 5, y: 5}}157	expect(t, equalBbox(*b1.getBboxOverlap(p), p))158	// point & line159	var l bbox160	// no overlap161	p = bbox{ll: point{x: 2, y: 2}, ur: point{x: 2, y: 2}}162	l = bbox{ll: point{x: 4, y: 6}, ur: point{x: 4, y: 8}}163	expect(t, l.getBboxOverlap(p) == nil)164	// point overlap165	p = bbox{ll: point{x: 5, y: 5}, ur: point{x: 5, y: 5}}166	l = bbox{ll: point{x: 4, y: 5}, ur: point{x: 6, y: 5}}167	expect(t, equalBbox(*l.getBboxOverlap(p), p))168	// point & point169	var p1, p2 bbox170	// no overlap171	p1 = bbox{ll: point{x: 2, y: 2}, ur: point{x: 2, y: 2}}172	p2 = bbox{ll: point{x: 4, y: 6}, ur: point{x: 4, y: 6}}173	expect(t, p1.getBboxOverlap(p2) == nil)174	// point overlap175	p = bbox{ll: point{x: 5, y: 5}, ur: point{x: 5, y: 5}}176	expect(t, equalBbox(*p.getBboxOverlap(p), p))177}...

Full Screen

Full Screen

modify_test.go

Source:modify_test.go Github

copy

Full Screen

1// Copyright 2018 Google Inc. All rights reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//     http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14package parser15import (16	"bytes"17	"testing"18)19func TestPatchList(t *testing.T) {20	expectOverlap := func(err error) {21		t.Helper()22		if _, ok := err.(PatchOverlapError); !ok {23			t.Error("missing PatchOverlapError")24		}25	}26	expectOk := func(err error) {27		t.Helper()28		if err != nil {29			t.Error(err)30		}31	}32	in := []byte("abcdefghijklmnopqrstuvwxyz")33	patchlist := PatchList{}34	expectOk(patchlist.Add(0, 3, "ABC"))35	expectOk(patchlist.Add(12, 15, "MNO"))36	expectOk(patchlist.Add(24, 26, "Z"))37	expectOk(patchlist.Add(15, 15, "_"))38	expectOverlap(patchlist.Add(0, 3, "x"))39	expectOverlap(patchlist.Add(12, 13, "x"))40	expectOverlap(patchlist.Add(13, 14, "x"))41	expectOverlap(patchlist.Add(14, 15, "x"))42	expectOverlap(patchlist.Add(11, 13, "x"))43	expectOverlap(patchlist.Add(12, 15, "x"))44	expectOverlap(patchlist.Add(11, 15, "x"))45	expectOverlap(patchlist.Add(15, 15, "x"))46	if t.Failed() {47		return48	}49	buf := new(bytes.Buffer)50	patchlist.Apply(bytes.NewReader(in), buf)51	expected := "ABCdefghijklMNO_pqrstuvwxZ"52	got := buf.String()53	if got != expected {54		t.Errorf("expected %q, got %q", expected, got)55	}56}...

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	rand.Seed(time.Now().UnixNano())4	for i := 0; i < 10; i++ {5		a = rand.Intn(10)6		b = rand.Intn(10)7		c = rand.Intn(10)8		d = rand.Intn(10)9		overlap = overlap(a, b, c, d)10		fmt.Println(a, b, c, d, overlap)11	}12}13import (14func TestOverlap(t *testing.T) {15	rand.Seed(time.Now().UnixNano())16	for i := 0; i < 10; i++ {17		a = rand.Intn(10)18		b = rand.Intn(10)19		c = rand.Intn(10)20		d = rand.Intn(10)21		t.Log(overlap(a, b, c, d))22	}23}24import (25func TestOverlap(t *testing.T) {26	rand.Seed(time.Now().UnixNano())27	for i := 0; i < 10; i++ {28		a = rand.Intn(10)29		b = rand.Intn(10)30		c = rand.Intn(10)31		d = rand.Intn(10)32		overlap = overlap(a, b, c, d)33		t.Log(a, b, c, d, overlap)34	}35}36import (37func TestOverlap(t *testing.T) {38	rand.Seed(time.Now().UnixNano())39	for i := 0; i < 10; i++ {40		a = rand.Intn(10)41		b = rand.Intn(10

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1using namespace std;2{3    int x,y;4    int a,b;5    void EXPECT();6    void EXPECT(int,int);7    void EXPECT(int,int,int,int);8    void EXPECT(int,int,int,int,int,int);9    void EXPECT(int,int,int,int,int,int,int,int);10    void EXPECT(int,int,int,int,int,int,int,int,int

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1using namespace std;2int main(int argc, char* argv[])3{4  vector<overlap> v;5  overlap o;6  ifstream infile;7  infile.open(argv[1]);8  string line;9  while(getline(infile,line))10  {11    stringstream ss(line);12    string name;13    int start;14    int end;15    ss >> name;16    ss >> start;17    ss >> end;18    overlap o(name,start,end);19    v.push_back(o);20  }21  infile.close();22  sort(v.begin(),v.end());23  cout << o.EXPECT(v) << endl;24  return 0;25}26using namespace std;27{28    overlap();29    overlap(string name, int start, int end);30    string getName() const;31    int getStart() const;32    int getEnd() const;33    void setName(string name);34    void setStart(int start);35    void setEnd(int end);36    bool operator<(const overlap& o) const;37    bool operator==(const overlap& o) const;38    double EXPECT(vector<overlap> v);39    string m_name;40    int m_start;41    int m_end;42};43using namespace std;44overlap::overlap()45{46  m_name = "";47  m_start = 0;48  m_end = 0;49}

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2type overlap struct {3}4func (o *overlap) EXPECT(str1 string, str2 string) bool {5	str1 = strings.ToLower(str1)6	str2 = strings.ToLower(str2)7	if len(str1) != len(str2) {8	}9	count := make(map[rune]int)10	for _, c := range str1 {11	}12	for _, c := range str2 {13	}14	for _, v := range count {15		if v != 0 {16		}17	}18}19func main() {20	overlap := new(overlap)21	fmt.Println(overlap.EXPECT("anagram", "nagaram"))22	fmt.Println(overlap.EXPECT("rat", "car"))23}

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 Mock automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful