Best Gauge code snippet using gauge.Filter
specItemFilter_test.go
Source:specItemFilter_test.go
...20func after() {21 os.Clearenv()22}23func (s *MySuite) TestToEvaluateTagExpressionWithTwoTags(c *C) {24 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag1 & tag3"}25 c.Assert(filter.filterTags([]string{"tag1", "tag2"}), Equals, false)26}27func (s *MySuite) TestToEvaluateTagExpressionWithComplexTagExpression(c *C) {28 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag1 & ((tag3 | tag2) & (tag5 | tag4 | tag3) & tag7) | tag6"}29 c.Assert(filter.filterTags([]string{"tag1", "tag2", "tag7", "tag4"}), Equals, true)30}31func (s *MySuite) TestToEvaluateTagExpressionWithFailingTagExpression(c *C) {32 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag1 & ((tag3 | tag2) & (tag5 | tag4 | tag3) & tag7) & tag6"}33 c.Assert(filter.filterTags([]string{"tag1", "tag2", "tag7", "tag4"}), Equals, false)34}35func (s *MySuite) TestToEvaluateTagExpressionWithWrongTagExpression(c *C) {36 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag1 & ((((tag3 | tag2) & (tag5 | tag4 | tag3) & tag7) & tag6"}37 c.Assert(filter.filterTags([]string{"tag1", "tag2", "tag7", "tag4"}), Equals, false)38}39func (s *MySuite) TestToEvaluateTagExpressionConsistingOfSpaces(c *C) {40 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag 1 & tag3"}41 c.Assert(filter.filterTags([]string{"tag 1", "tag3"}), Equals, true)42}43func (s *MySuite) TestToEvaluateTagExpressionConsistingLogicalNotOperator(c *C) {44 filter := &ScenarioFilterBasedOnTags{tagExpression: "!tag 1 & tag3"}45 c.Assert(filter.filterTags([]string{"tag2", "tag3"}), Equals, true)46}47func (s *MySuite) TestToEvaluateTagExpressionConsistingManyLogicalNotOperator(c *C) {48 filter := &ScenarioFilterBasedOnTags{tagExpression: "!(!(tag 1 | !(tag6 | !(tag5))) & tag2)"}49 value := filter.filterTags([]string{"tag2", "tag4"})50 c.Assert(value, Equals, true)51}52func (s *MySuite) TestToEvaluateTagExpressionConsistingParallelLogicalNotOperator(c *C) {53 filter := &ScenarioFilterBasedOnTags{tagExpression: "!(tag1) & ! (tag3 & ! (tag3))"}54 value := filter.filterTags([]string{"tag2", "tag4"})55 c.Assert(value, Equals, true)56}57func (s *MySuite) TestToEvaluateTagExpressionConsistingComma(c *C) {58 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag 1 , tag3"}59 c.Assert(filter.filterTags([]string{"tag2", "tag3"}), Equals, false)60}61func (s *MySuite) TestToEvaluateTagExpressionConsistingCommaGivesTrue(c *C) {62 filter := &ScenarioFilterBasedOnTags{tagExpression: "tag 1 , tag3"}63 c.Assert(filter.filterTags([]string{"tag1", "tag3"}), Equals, true)64}65func (s *MySuite) TestToEvaluateTagExpressionConsistingTrueAndFalseAsTagNames(c *C) {66 filter := &ScenarioFilterBasedOnTags{tagExpression: "true , false"}67 c.Assert(filter.filterTags([]string{"true", "false"}), Equals, true)68}69func (s *MySuite) TestToEvaluateTagExpressionConsistingTrueAndFalseAsTagNamesWithNegation(c *C) {70 filter := &ScenarioFilterBasedOnTags{tagExpression: "!true"}71 c.Assert(filter.filterTags(nil), Equals, true)72}73func (s *MySuite) TestToEvaluateTagExpressionConsistingSpecialCharacters(c *C) {74 filter := &ScenarioFilterBasedOnTags{tagExpression: "a && b || c | b & b"}75 c.Assert(filter.filterTags([]string{"a", "b"}), Equals, true)76}77func (s *MySuite) TestToEvaluateTagExpressionWhenTagIsSubsetOfTrueOrFalse(c *C) {78 // https://github.com/getgauge/gauge/issues/66779 filter := &ScenarioFilterBasedOnTags{tagExpression: "b || c | b & b && a"}80 c.Assert(filter.filterTags([]string{"a", "b"}), Equals, true)81}82func (s *MySuite) TestParseTagExpression(c *C) {83 filter := &ScenarioFilterBasedOnTags{tagExpression: "b || c | b & b && a"}84 txps, tags := filter.parseTagExpression()85 expectedTxps := []string{"b", "|", "|", "c", "|", "b", "&", "b", "&", "&", "a"}86 expectedTags := []string{"b", "c", "b", "b", "a"}87 for i, t := range txps {88 c.Assert(expectedTxps[i], Equals, t)89 }90 for i, t := range tags {91 c.Assert(expectedTags[i], Equals, t)92 }93}94func (s *MySuite) TestScenarioSpanFilter(c *C) {95 scenario1 := &gauge.Scenario{96 Heading: &gauge.Heading{Value: "First Scenario"},97 Span: &gauge.Span{Start: 1, End: 3},98 }99 scenario2 := &gauge.Scenario{100 Heading: &gauge.Heading{Value: "Second Scenario"},101 Span: &gauge.Span{Start: 4, End: 6},102 }103 scenario3 := &gauge.Scenario{104 Heading: &gauge.Heading{Value: "Third Scenario"},105 Span: &gauge.Span{Start: 7, End: 10},106 }107 scenario4 := &gauge.Scenario{108 Heading: &gauge.Heading{Value: "Fourth Scenario"},109 Span: &gauge.Span{Start: 11, End: 15},110 }111 spec := &gauge.Specification{112 Items: []gauge.Item{scenario1, scenario2, scenario3, scenario4},113 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3, scenario4},114 }115 specWithFilteredItems, specWithOtherItems := spec.Filter(NewScenarioFilterBasedOnSpan([]int{8}))116 c.Assert(len(specWithFilteredItems.Scenarios), Equals, 1)117 c.Assert(specWithFilteredItems.Scenarios[0], Equals, scenario3)118 c.Assert(len(specWithOtherItems.Scenarios), Equals, 3)119 c.Assert(specWithOtherItems.Scenarios[0], Equals, scenario1)120 c.Assert(specWithOtherItems.Scenarios[1], Equals, scenario2)121 c.Assert(specWithOtherItems.Scenarios[2], Equals, scenario4)122}123func (s *MySuite) TestScenarioSpanFilterLastScenario(c *C) {124 scenario1 := &gauge.Scenario{125 Heading: &gauge.Heading{Value: "First Scenario"},126 Span: &gauge.Span{Start: 1, End: 3},127 }128 scenario2 := &gauge.Scenario{129 Heading: &gauge.Heading{Value: "Second Scenario"},130 Span: &gauge.Span{Start: 4, End: 6},131 }132 scenario3 := &gauge.Scenario{133 Heading: &gauge.Heading{Value: "Third Scenario"},134 Span: &gauge.Span{Start: 7, End: 10},135 }136 scenario4 := &gauge.Scenario{137 Heading: &gauge.Heading{Value: "Fourth Scenario"},138 Span: &gauge.Span{Start: 11, End: 15},139 }140 spec := &gauge.Specification{141 Items: []gauge.Item{scenario1, scenario2, scenario3, scenario4},142 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3, scenario4},143 }144 specWithFilteredItems, specWithOtherItems := spec.Filter(NewScenarioFilterBasedOnSpan([]int{13}))145 c.Assert(len(specWithFilteredItems.Scenarios), Equals, 1)146 c.Assert(specWithFilteredItems.Scenarios[0], Equals, scenario4)147 c.Assert(len(specWithOtherItems.Scenarios), Equals, 3)148 c.Assert(specWithOtherItems.Scenarios[0], Equals, scenario1)149 c.Assert(specWithOtherItems.Scenarios[1], Equals, scenario2)150 c.Assert(specWithOtherItems.Scenarios[2], Equals, scenario3)151}152func (s *MySuite) TestScenarioSpanFilterFirstScenario(c *C) {153 scenario1 := &gauge.Scenario{154 Heading: &gauge.Heading{Value: "First Scenario"},155 Span: &gauge.Span{Start: 1, End: 3},156 }157 scenario2 := &gauge.Scenario{158 Heading: &gauge.Heading{Value: "Second Scenario"},159 Span: &gauge.Span{Start: 4, End: 6},160 }161 scenario3 := &gauge.Scenario{162 Heading: &gauge.Heading{Value: "Third Scenario"},163 Span: &gauge.Span{Start: 7, End: 10},164 }165 scenario4 := &gauge.Scenario{166 Heading: &gauge.Heading{Value: "Fourth Scenario"},167 Span: &gauge.Span{Start: 11, End: 15},168 }169 spec := &gauge.Specification{170 Items: []gauge.Item{scenario1, scenario2, scenario3, scenario4},171 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3, scenario4},172 }173 specWithFilteredItems, specWithOtherItems := spec.Filter(NewScenarioFilterBasedOnSpan([]int{2}))174 c.Assert(len(specWithFilteredItems.Scenarios), Equals, 1)175 c.Assert(specWithFilteredItems.Scenarios[0], Equals, scenario1)176 c.Assert(len(specWithOtherItems.Scenarios), Equals, 3)177 c.Assert(specWithOtherItems.Scenarios[0], Equals, scenario2)178 c.Assert(specWithOtherItems.Scenarios[1], Equals, scenario3)179 c.Assert(specWithOtherItems.Scenarios[2], Equals, scenario4)180}181func (s *MySuite) TestScenarioSpanFilterForSingleScenarioSpec(c *C) {182 scenario1 := &gauge.Scenario{183 Heading: &gauge.Heading{Value: "First Scenario"},184 Span: &gauge.Span{Start: 1, End: 3},185 }186 spec := &gauge.Specification{187 Items: []gauge.Item{scenario1},188 Scenarios: []*gauge.Scenario{scenario1},189 }190 specWithFilteredItems, specWithOtherItems := spec.Filter(NewScenarioFilterBasedOnSpan([]int{3}))191 c.Assert(len(specWithFilteredItems.Scenarios), Equals, 1)192 c.Assert(specWithFilteredItems.Scenarios[0], Equals, scenario1)193 c.Assert(len(specWithOtherItems.Scenarios), Equals, 0)194}195func (s *MySuite) TestScenarioSpanFilterWithWrongScenarioIndex(c *C) {196 scenario1 := &gauge.Scenario{197 Heading: &gauge.Heading{Value: "First Scenario"},198 Span: &gauge.Span{Start: 1, End: 3},199 }200 spec := &gauge.Specification{201 Items: []gauge.Item{scenario1},202 Scenarios: []*gauge.Scenario{scenario1},203 }204 specWithFilteredItems, specWithOtherItems := spec.Filter(NewScenarioFilterBasedOnSpan([]int{5}))205 c.Assert(len(specWithFilteredItems.Scenarios), Equals, 0)206 c.Assert(len(specWithOtherItems.Scenarios), Equals, 1)207 c.Assert(specWithOtherItems.Scenarios[0], Equals, scenario1)208}209func (s *MySuite) TestScenarioSpanFilterWithMultipleLineNumbers(c *C) {210 scenario1 := &gauge.Scenario{211 Heading: &gauge.Heading{Value: "First Scenario"},212 Span: &gauge.Span{Start: 1, End: 3},213 }214 scenario2 := &gauge.Scenario{215 Heading: &gauge.Heading{Value: "Second Scenario"},216 Span: &gauge.Span{Start: 4, End: 6},217 }218 scenario3 := &gauge.Scenario{219 Heading: &gauge.Heading{Value: "Third Scenario"},220 Span: &gauge.Span{Start: 7, End: 10},221 }222 scenario4 := &gauge.Scenario{223 Heading: &gauge.Heading{Value: "Fourth Scenario"},224 Span: &gauge.Span{Start: 11, End: 15},225 }226 spec := &gauge.Specification{227 Items: []gauge.Item{scenario1, scenario2, scenario3, scenario4},228 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3, scenario4},229 }230 specWithFilteredItems, specWithOtherItems := spec.Filter(NewScenarioFilterBasedOnSpan([]int{3, 13}))231 c.Assert(len(specWithFilteredItems.Scenarios), Equals, 2)232 c.Assert(specWithFilteredItems.Scenarios[0], Equals, scenario1)233 c.Assert(specWithFilteredItems.Scenarios[1], Equals, scenario4)234 c.Assert(len(specWithOtherItems.Scenarios), Equals, 2)235 c.Assert(specWithOtherItems.Scenarios[0], Equals, scenario2)236 c.Assert(specWithOtherItems.Scenarios[1], Equals, scenario3)237}238func (s *MySuite) TestToFilterSpecsByTagExpOfTwoTags(c *C) {239 myTags := []string{"tag1", "tag2"}240 scenario1 := &gauge.Scenario{241 Heading: &gauge.Heading{Value: "First Scenario"},242 Span: &gauge.Span{Start: 1, End: 3},243 }244 scenario2 := &gauge.Scenario{245 Heading: &gauge.Heading{Value: "Second Scenario"},246 Span: &gauge.Span{Start: 4, End: 6},247 }248 spec1 := &gauge.Specification{249 Items: []gauge.Item{scenario1, scenario2},250 Scenarios: []*gauge.Scenario{scenario1, scenario2},251 Tags: &gauge.Tags{RawValues: [][]string{myTags}},252 }253 spec2 := &gauge.Specification{254 Items: []gauge.Item{scenario1, scenario2},255 Scenarios: []*gauge.Scenario{scenario1, scenario2},256 }257 var specs []*gauge.Specification258 specs = append(specs, spec1, spec2)259 c.Assert(specs[0].Tags.Values()[0], Equals, myTags[0])260 c.Assert(specs[0].Tags.Values()[1], Equals, myTags[1])261 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")262 c.Assert(len(filteredSpecs), Equals, 1)263 c.Assert(len(otherSpecs), Equals, 1)264}265func (s *MySuite) TestToEvaluateTagExpression(c *C) {266 myTags := []string{"tag1", "tag2"}267 scenario1 := &gauge.Scenario{268 Heading: &gauge.Heading{Value: "First Scenario"},269 Span: &gauge.Span{Start: 1, End: 3},270 Tags: &gauge.Tags{RawValues: [][]string{{myTags[0]}}},271 }272 scenario2 := &gauge.Scenario{273 Heading: &gauge.Heading{Value: "Second Scenario"},274 Span: &gauge.Span{Start: 4, End: 6},275 Tags: &gauge.Tags{RawValues: [][]string{{"tag3"}}},276 }277 scenario3 := &gauge.Scenario{278 Heading: &gauge.Heading{Value: "Third Scenario"},279 Span: &gauge.Span{Start: 1, End: 3},280 }281 scenario4 := &gauge.Scenario{282 Heading: &gauge.Heading{Value: "Fourth Scenario"},283 Span: &gauge.Span{Start: 4, End: 6},284 }285 spec1 := &gauge.Specification{286 Items: []gauge.Item{scenario1, scenario2},287 Scenarios: []*gauge.Scenario{scenario1, scenario2},288 }289 spec2 := &gauge.Specification{290 Items: []gauge.Item{scenario3, scenario4},291 Scenarios: []*gauge.Scenario{scenario3, scenario4},292 Tags: &gauge.Tags{RawValues: [][]string{myTags}},293 }294 var specs []*gauge.Specification295 specs = append(specs, spec1, spec2)296 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & !(tag1 & tag4) & (tag2 | tag3)")297 c.Assert(len(filteredSpecs), Equals, 1)298 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 2)299 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario3)300 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario4)301 c.Assert(len(otherSpecs), Equals, 1)302 c.Assert(len(otherSpecs[0].Scenarios), Equals, 2)303 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)304 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario2)305}306func (s *MySuite) TestToFilterSpecsByWrongTagExpression(c *C) {307 myTags := []string{"tag1", "tag2"}308 scenario1 := &gauge.Scenario{309 Heading: &gauge.Heading{Value: "First Scenario"},310 Span: &gauge.Span{Start: 1, End: 3},311 }312 scenario2 := &gauge.Scenario{313 Heading: &gauge.Heading{Value: "Second Scenario"},314 Span: &gauge.Span{Start: 4, End: 6},315 }316 spec1 := &gauge.Specification{317 Items: []gauge.Item{scenario1, scenario2},318 Scenarios: []*gauge.Scenario{scenario1, scenario2},319 Tags: &gauge.Tags{RawValues: [][]string{myTags}},320 }321 spec2 := &gauge.Specification{322 Items: []gauge.Item{scenario1, scenario2},323 Scenarios: []*gauge.Scenario{scenario1, scenario2},324 }325 var specs []*gauge.Specification326 specs = append(specs, spec1, spec2)327 c.Assert(specs[0].Tags.Values()[0], Equals, myTags[0])328 c.Assert(specs[0].Tags.Values()[1], Equals, myTags[1])329 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "(tag1 & tag2")330 c.Assert(len(filteredSpecs), Equals, 0)331 c.Assert(len(otherSpecs), Equals, 2)332}333func (s *MySuite) TestToFilterMultipleScenariosByMultipleTags(c *C) {334 myTags := []string{"tag1", "tag2"}335 scenario1 := &gauge.Scenario{336 Heading: &gauge.Heading{Value: "First Scenario"},337 Span: &gauge.Span{Start: 1, End: 3},338 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},339 }340 scenario2 := &gauge.Scenario{341 Heading: &gauge.Heading{Value: "Second Scenario"},342 Span: &gauge.Span{Start: 4, End: 6},343 Tags: &gauge.Tags{RawValues: [][]string{myTags}},344 }345 scenario3 := &gauge.Scenario{346 Heading: &gauge.Heading{Value: "Third Scenario"},347 Span: &gauge.Span{Start: 1, End: 3},348 Tags: &gauge.Tags{RawValues: [][]string{myTags}},349 }350 scenario4 := &gauge.Scenario{351 Heading: &gauge.Heading{Value: "Fourth Scenario"},352 Span: &gauge.Span{Start: 4, End: 6},353 Tags: &gauge.Tags{RawValues: [][]string{{"prod", "tag7", "tag1", "tag2"}}},354 }355 spec1 := &gauge.Specification{356 Items: []gauge.Item{scenario1, scenario2, scenario3, scenario4},357 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3, scenario4},358 }359 var specs []*gauge.Specification360 specs = append(specs, spec1)361 c.Assert(len(specs[0].Scenarios), Equals, 4)362 c.Assert(len(specs[0].Scenarios[0].Tags.Values()), Equals, 1)363 c.Assert(len(specs[0].Scenarios[1].Tags.Values()), Equals, 2)364 c.Assert(len(specs[0].Scenarios[2].Tags.Values()), Equals, 2)365 c.Assert(len(specs[0].Scenarios[3].Tags.Values()), Equals, 4)366 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")367 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 3)368 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)369 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario3)370 c.Assert(filteredSpecs[0].Scenarios[2], Equals, scenario4)371 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)372 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)373}374func (s *MySuite) TestToFilterScenariosByTagsAtSpecLevel(c *C) {375 myTags := []string{"tag1", "tag2"}376 scenario1 := &gauge.Scenario{377 Heading: &gauge.Heading{Value: "First Scenario"},378 Span: &gauge.Span{Start: 1, End: 3},379 }380 scenario2 := &gauge.Scenario{381 Heading: &gauge.Heading{Value: "Second Scenario"},382 Span: &gauge.Span{Start: 4, End: 6},383 }384 scenario3 := &gauge.Scenario{385 Heading: &gauge.Heading{Value: "Third Scenario"},386 Span: &gauge.Span{Start: 4, End: 6},387 }388 spec1 := &gauge.Specification{389 Items: []gauge.Item{scenario1, scenario2, scenario3},390 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},391 Tags: &gauge.Tags{RawValues: [][]string{myTags}},392 }393 var specs []*gauge.Specification394 specs = append(specs, spec1)395 c.Assert(len(specs[0].Scenarios), Equals, 3)396 c.Assert(len(specs[0].Tags.Values()), Equals, 2)397 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")398 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 3)399 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)400 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario2)401 c.Assert(filteredSpecs[0].Scenarios[2], Equals, scenario3)402 c.Assert(len(otherSpecs), Equals, 0)403}404func (s *MySuite) TestToFilterScenariosByTagExpWithDuplicateTagNames(c *C) {405 myTags := []string{"tag1", "tag12"}406 scenario1 := &gauge.Scenario{407 Heading: &gauge.Heading{Value: "First Scenario"},408 Span: &gauge.Span{Start: 1, End: 3},409 Tags: &gauge.Tags{RawValues: [][]string{myTags}},410 }411 scenario2 := &gauge.Scenario{412 Heading: &gauge.Heading{Value: "Second Scenario"},413 Span: &gauge.Span{Start: 4, End: 6},414 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},415 }416 scenario3 := &gauge.Scenario{417 Heading: &gauge.Heading{Value: "Third Scenario"},418 Span: &gauge.Span{Start: 4, End: 6},419 Tags: &gauge.Tags{RawValues: [][]string{{"tag12"}}},420 }421 spec1 := &gauge.Specification{422 Items: []gauge.Item{scenario1, scenario2, scenario3},423 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},424 }425 var specs []*gauge.Specification426 specs = append(specs, spec1)427 c.Assert(len(specs), Equals, 1)428 c.Assert(len(specs[0].Scenarios), Equals, 3)429 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag12")430 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)431 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)432 c.Assert(len(otherSpecs), Equals, 1)433 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario2)434 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario3)435}436func (s *MySuite) TestFilterTags(c *C) {437 specTags := []string{"abcd", "foo", "bar", "foo bar"}438 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & foo bar")439 evaluateTrue := tagFilter.filterTags(specTags)440 c.Assert(evaluateTrue, Equals, true)441}442func (s *MySuite) TestFilterMixedCaseTags(c *C) {443 before()444 defer after()445 specTags := []string{"abcd", "foo", "BAR", "foo bar"}446 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & FOO bar")447 evaluateTrue := tagFilter.filterTags(specTags)448 c.Assert(evaluateTrue, Equals, true)449}450func (s *MySuite) TestSanitizeTags(c *C) {451 specTags := []string{"abcd", "foo", "bar", "foo bar"}452 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & foo bar | true")453 evaluateTrue := tagFilter.filterTags(specTags)454 c.Assert(evaluateTrue, Equals, true)455}456func (s *MySuite) TestSanitizeMixedCaseTags(c *C) {457 before()458 defer after()459 specTags := []string{"abcd", "foo", "bar", "foo bar"}460 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & foo Bar | true")461 evaluateTrue := tagFilter.filterTags(specTags)462 c.Assert(evaluateTrue, Equals, true)463}464func (s *MySuite) TestToFilterSpecsByTags(c *C) {465 myTags := []string{"tag1", "tag2"}466 scenario1 := &gauge.Scenario{467 Heading: &gauge.Heading{Value: "First Scenario"},468 Span: &gauge.Span{Start: 1, End: 3},469 Tags: &gauge.Tags{RawValues: [][]string{myTags}},470 }471 scenario2 := &gauge.Scenario{472 Heading: &gauge.Heading{Value: "Second Scenario"},473 Span: &gauge.Span{Start: 4, End: 6},474 }475 scenario3 := &gauge.Scenario{476 Heading: &gauge.Heading{Value: "Third Scenario"},477 Span: &gauge.Span{Start: 1, End: 3},478 }479 spec1 := &gauge.Specification{480 Items: []gauge.Item{scenario1, scenario2},481 Scenarios: []*gauge.Scenario{scenario1, scenario2},482 }483 spec2 := &gauge.Specification{484 Items: []gauge.Item{scenario2, scenario3},485 Scenarios: []*gauge.Scenario{scenario2, scenario3},486 }487 spec3 := &gauge.Specification{488 Items: []gauge.Item{scenario1, scenario3},489 Scenarios: []*gauge.Scenario{scenario1, scenario3},490 }491 var specs []*gauge.Specification492 specs = append(specs, spec1, spec2, spec3)493 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")494 c.Assert(len(filteredSpecs), Equals, 2)495 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)496 c.Assert(len(filteredSpecs[1].Scenarios), Equals, 1)497 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)498 c.Assert(filteredSpecs[1].Scenarios[0], Equals, scenario1)499 c.Assert(len(otherSpecs), Equals, 3)500 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)501 c.Assert(len(otherSpecs[1].Scenarios), Equals, 2)502 c.Assert(len(otherSpecs[2].Scenarios), Equals, 1)503 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario2)504 c.Assert(otherSpecs[1].Scenarios[0], Equals, scenario2)505 c.Assert(otherSpecs[1].Scenarios[1], Equals, scenario3)506 c.Assert(otherSpecs[2].Scenarios[0], Equals, scenario3)507}508func (s *MySuite) TestToFilterSpecsByMixedCaseTags(c *C) {509 before()510 defer after()511 myTags := []string{"tag1", "TAG2"}512 scenario1 := &gauge.Scenario{513 Heading: &gauge.Heading{Value: "First Scenario"},514 Span: &gauge.Span{Start: 1, End: 3},515 Tags: &gauge.Tags{RawValues: [][]string{myTags}},516 }517 scenario2 := &gauge.Scenario{518 Heading: &gauge.Heading{Value: "Second Scenario"},519 Span: &gauge.Span{Start: 4, End: 6},520 }521 scenario3 := &gauge.Scenario{522 Heading: &gauge.Heading{Value: "Third Scenario"},523 Span: &gauge.Span{Start: 1, End: 3},524 }525 spec1 := &gauge.Specification{526 Items: []gauge.Item{scenario1, scenario2},527 Scenarios: []*gauge.Scenario{scenario1, scenario2},528 }529 spec2 := &gauge.Specification{530 Items: []gauge.Item{scenario2, scenario3},531 Scenarios: []*gauge.Scenario{scenario2, scenario3},532 }533 spec3 := &gauge.Specification{534 Items: []gauge.Item{scenario1, scenario3},535 Scenarios: []*gauge.Scenario{scenario1, scenario3},536 }537 var specs []*gauge.Specification538 specs = append(specs, spec1, spec2, spec3)539 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & Tag2")540 c.Assert(len(filteredSpecs), Equals, 2)541 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)542 c.Assert(len(filteredSpecs[1].Scenarios), Equals, 1)543 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)544 c.Assert(filteredSpecs[1].Scenarios[0], Equals, scenario1)545 c.Assert(len(otherSpecs), Equals, 3)546 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)547 c.Assert(len(otherSpecs[1].Scenarios), Equals, 2)548 c.Assert(len(otherSpecs[2].Scenarios), Equals, 1)549 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario2)550 c.Assert(otherSpecs[1].Scenarios[0], Equals, scenario2)551 c.Assert(otherSpecs[1].Scenarios[1], Equals, scenario3)552 c.Assert(otherSpecs[2].Scenarios[0], Equals, scenario3)553}554func (s *MySuite) TestToFilterScenariosByTag(c *C) {555 myTags := []string{"tag1", "tag2"}556 scenario1 := &gauge.Scenario{557 Heading: &gauge.Heading{Value: "First Scenario"},558 Span: &gauge.Span{Start: 1, End: 3},559 }560 scenario2 := &gauge.Scenario{561 Heading: &gauge.Heading{Value: "Second Scenario"},562 Span: &gauge.Span{Start: 4, End: 6},563 Tags: &gauge.Tags{RawValues: [][]string{myTags}},564 }565 scenario3 := &gauge.Scenario{566 Heading: &gauge.Heading{Value: "Third Scenario"},567 Span: &gauge.Span{Start: 4, End: 6},568 }569 spec1 := &gauge.Specification{570 Items: []gauge.Item{scenario1, scenario2, scenario3},571 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},572 }573 var specs []*gauge.Specification574 specs = append(specs, spec1)575 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")576 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)577 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)578 c.Assert(len(otherSpecs), Equals, 1)579 c.Assert(len(otherSpecs[0].Scenarios), Equals, 2)580 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)581 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario3)582}583func (s *MySuite) TestToFilterScenariosByMixedCaseTag(c *C) {584 before()585 defer after()586 myTags := []string{"Tag-1", "tag2"}587 scenario1 := &gauge.Scenario{588 Heading: &gauge.Heading{Value: "First Scenario"},589 Span: &gauge.Span{Start: 1, End: 3},590 }591 scenario2 := &gauge.Scenario{592 Heading: &gauge.Heading{Value: "Second Scenario"},593 Span: &gauge.Span{Start: 4, End: 6},594 Tags: &gauge.Tags{RawValues: [][]string{myTags}},595 }596 scenario3 := &gauge.Scenario{597 Heading: &gauge.Heading{Value: "Third Scenario"},598 Span: &gauge.Span{Start: 4, End: 6},599 }600 spec1 := &gauge.Specification{601 Items: []gauge.Item{scenario1, scenario2, scenario3},602 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},603 }604 var specs []*gauge.Specification605 specs = append(specs, spec1)606 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag-1 & tag2")607 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)608 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)609 c.Assert(len(otherSpecs), Equals, 1)610 c.Assert(len(otherSpecs[0].Scenarios), Equals, 2)611 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)612 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario3)613}614func (s *MySuite) TestToFilterMultipleScenariosByTags(c *C) {615 myTags := []string{"tag1", "tag2"}616 scenario1 := &gauge.Scenario{617 Heading: &gauge.Heading{Value: "First Scenario"},618 Span: &gauge.Span{Start: 1, End: 3},619 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},620 }621 scenario2 := &gauge.Scenario{622 Heading: &gauge.Heading{Value: "Second Scenario"},623 Span: &gauge.Span{Start: 4, End: 6},624 Tags: &gauge.Tags{RawValues: [][]string{myTags}},625 }626 scenario3 := &gauge.Scenario{627 Heading: &gauge.Heading{Value: "Third Scenario"},628 Span: &gauge.Span{Start: 4, End: 6},629 Tags: &gauge.Tags{RawValues: [][]string{myTags}},630 }631 spec1 := &gauge.Specification{632 Items: []gauge.Item{scenario1, scenario2, scenario3},633 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},634 }635 var specs []*gauge.Specification636 specs = append(specs, spec1)637 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")638 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 2)639 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)640 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario3)641 c.Assert(len(otherSpecs), Equals, 1)642 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)643 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)644}645func (s *MySuite) TestToFilterScenariosByUnavailableTags(c *C) {646 myTags := []string{"tag1", "tag2"}647 scenario1 := &gauge.Scenario{648 Heading: &gauge.Heading{Value: "First Scenario"},649 Span: &gauge.Span{Start: 1, End: 3},650 }651 scenario2 := &gauge.Scenario{652 Heading: &gauge.Heading{Value: "Second Scenario"},653 Span: &gauge.Span{Start: 4, End: 6},654 Tags: &gauge.Tags{RawValues: [][]string{myTags}},655 }656 scenario3 := &gauge.Scenario{657 Heading: &gauge.Heading{Value: "Third Scenario"},658 Span: &gauge.Span{Start: 4, End: 6},659 }660 spec1 := &gauge.Specification{661 Items: []gauge.Item{scenario1, scenario2, scenario3},662 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},663 }664 var specs []*gauge.Specification665 specs = append(specs, spec1)666 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag3")667 c.Assert(len(filteredSpecs), Equals, 0)668 c.Assert(len(otherSpecs), Equals, 1)669 c.Assert(len(otherSpecs[0].Scenarios), Equals, 3)670 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)671 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario2)672 c.Assert(otherSpecs[0].Scenarios[2], Equals, scenario3)673}674func (s *MySuite) TestFilterScenariosByName(c *C) {675 scenario1 := &gauge.Scenario{676 Heading: &gauge.Heading{Value: "First Scenario"},677 }678 scenario2 := &gauge.Scenario{679 Heading: &gauge.Heading{Value: "Second Scenario"},680 }681 spec1 := &gauge.Specification{682 Items: []gauge.Item{scenario1, scenario2},683 Scenarios: []*gauge.Scenario{scenario1, scenario2},684 }685 var scenarios = []string{"First Scenario"}686 var specs []*gauge.Specification687 specs = append(specs, spec1)688 c.Assert(len(specs[0].Scenarios), Equals, 2)689 specs = filterSpecsByScenarioName(specs, scenarios)690 c.Assert(len(specs[0].Scenarios), Equals, 1)691}692func (s *MySuite) TestFilterScenarioWhichDoesNotExists(c *C) {693 scenario1 := &gauge.Scenario{694 Heading: &gauge.Heading{Value: "First Scenario"},695 }696 scenario2 := &gauge.Scenario{697 Heading: &gauge.Heading{Value: "Second Scenario"},698 }699 spec1 := &gauge.Specification{700 Items: []gauge.Item{scenario1, scenario2},701 Scenarios: []*gauge.Scenario{scenario1, scenario2},702 }703 var scenarios = []string{"Third Scenario"}704 var specs []*gauge.Specification705 specs = append(specs, spec1)706 c.Assert(len(specs[0].Scenarios), Equals, 2)707 specs = filterSpecsByScenarioName(specs, scenarios)708 c.Assert(len(specs), Equals, 0)709}710func (s *MySuite) TestFilterMultipleScenariosByName(c *C) {711 scenario1 := &gauge.Scenario{712 Heading: &gauge.Heading{Value: "First Scenario"},713 }714 scenario2 := &gauge.Scenario{715 Heading: &gauge.Heading{Value: "Second Scenario"},716 }717 spec1 := &gauge.Specification{718 Items: []gauge.Item{scenario1, scenario2},719 Scenarios: []*gauge.Scenario{scenario1, scenario2},720 }721 var scenarios = []string{"First Scenario", "Second Scenario"}722 var specs []*gauge.Specification723 specs = append(specs, spec1)724 c.Assert(len(specs[0].Scenarios), Equals, 2)725 specs = filterSpecsByScenarioName(specs, scenarios)726 c.Assert(len(specs[0].Scenarios), Equals, 2)727}728func (s *MySuite) TestFilterInvalidScenarios(c *C) {729 scenario1 := &gauge.Scenario{730 Heading: &gauge.Heading{Value: "First Scenario"},731 }732 scenario2 := &gauge.Scenario{733 Heading: &gauge.Heading{Value: "Second Scenario"},734 }735 spec1 := &gauge.Specification{736 Items: []gauge.Item{scenario1, scenario2},737 Scenarios: []*gauge.Scenario{scenario1, scenario2},738 }739 var scenarios = []string{"First Scenario", "Third Scenario"}740 var specs []*gauge.Specification741 specs = append(specs, spec1)742 c.Assert(len(specs[0].Scenarios), Equals, 2)743 filteredScenarios := filterValidScenarios(specs, scenarios)744 c.Assert(len(filteredScenarios), Equals, 1)745 c.Assert(filteredScenarios[0], Equals, "First Scenario")746}747func (s *MySuite) TestScenarioTagFilterShouldNotRemoveNonScenarioKindItems(c *C) {748 scenario1 := &gauge.Scenario{749 Heading: &gauge.Heading{Value: "First Scenario"},750 Span: &gauge.Span{Start: 1, End: 3},751 }752 scenario2 := &gauge.Scenario{753 Heading: &gauge.Heading{Value: "Second Scenario"},754 Span: &gauge.Span{Start: 4, End: 6},755 Tags: &gauge.Tags{RawValues: [][]string{{"tag2"}}},756 }757 scenario3 := &gauge.Scenario{758 Heading: &gauge.Heading{Value: "Third Scenario"},759 Span: &gauge.Span{Start: 7, End: 10},760 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},761 }762 spec := &gauge.Specification{763 Items: []gauge.Item{scenario1, scenario2, scenario3, &gauge.Table{}, &gauge.Comment{Value: "Comment", LineNo: 1}, &gauge.Step{}},764 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},765 }766 specWithFilteredItems, specWithOtherItems := filterSpecsByTags([]*gauge.Specification{spec}, "tag1 | tag2")767 c.Assert(len(specWithFilteredItems), Equals, 1)768 c.Assert(len(specWithFilteredItems[0].Items), Equals, 5)769 c.Assert(len(specWithOtherItems), Equals, 1)770 c.Assert(len(specWithOtherItems[0].Items), Equals, 4)771}...
specsFilter.go
Source:specsFilter.go
...8 "strings"9 "github.com/getgauge/gauge/gauge"10 "github.com/getgauge/gauge/logger"11)12type specsFilter interface {13 filter([]*gauge.Specification) []*gauge.Specification14}15type tagsFilter struct {16 tagExp string17}18type tagFilterForParallelRun struct {19 tagExp string20}21type specsGroupFilter struct {22 group int23 execStreams int24}25type scenariosFilter struct {26 scenarios []string27}28func (tf *tagFilterForParallelRun) filter(specs []*gauge.Specification) ([]*gauge.Specification, []*gauge.Specification) {29 return filterByTags(tf.tagExp, specs)30}31func (tagsFilter *tagsFilter) filter(specs []*gauge.Specification) []*gauge.Specification {32 specs, _ = filterByTags(tagsFilter.tagExp, specs)33 return specs34}35func filterByTags(tagExpression string, specs []*gauge.Specification) ([]*gauge.Specification, []*gauge.Specification) {36 if tagExpression != "" {37 logger.Debugf(true, "Applying tags filter: %s", tagExpression)38 validateTagExpression(tagExpression)39 return filterSpecsByTags(specs, tagExpression)40 }41 return specs, specs42}43func (groupFilter *specsGroupFilter) filter(specs []*gauge.Specification) []*gauge.Specification {44 if groupFilter.group == -1 {45 return specs46 }47 logger.Infof(true, "Using the -g flag will make the distribution strategy 'eager'. The --strategy setting will be overridden.")48 if groupFilter.group < 1 || groupFilter.group > groupFilter.execStreams {49 return make([]*gauge.Specification, 0)50 }51 logger.Debugf(true, "Applying group filter: %d", groupFilter.group)52 group := DistributeSpecs(specs, groupFilter.execStreams)[groupFilter.group-1]53 if group == nil {54 return make([]*gauge.Specification, 0)55 }56 return group.Specs()57}58func (scenarioFilter *scenariosFilter) filter(specs []*gauge.Specification) []*gauge.Specification {59 if len(scenarioFilter.scenarios) != 0 {60 logger.Debugf(true, "Applying scenarios filter: %s", strings.Join(scenarioFilter.scenarios, ", "))61 specs = filterSpecsByScenarioName(specs, scenarioFilter.scenarios)62 }63 return specs64}65func DistributeSpecs(specifications []*gauge.Specification, distributions int) []*gauge.SpecCollection {66 s := make([]*gauge.SpecCollection, distributions)67 for i := 0; i < len(specifications); i++ {68 mod := i % distributions69 if s[mod] == nil {70 s[mod] = gauge.NewSpecCollection(make([]*gauge.Specification, 0), false)71 }72 s[mod].Add(specifications[i])73 }74 return s75}...
Filter
Using AI Code Generation
1import (2func Filter() {3 fmt.Println("Filter")4}5func main() {6 gauge.Filter(Filter)7}8import (9func Filter() {10 fmt.Println("Filter")11}12func main() {13 gauge.Filter(Filter)14}15import (16func Filter() {17 fmt.Println("Filter")18}19func main() {20 gauge.Filter(Filter)21}22import (23func Filter() {24 fmt.Println("Filter")25}26func main() {27 gauge.Filter(Filter)28}29import (30func Filter() {31 fmt.Println("Filter")32}33func main() {34 gauge.Filter(Filter)35}
Filter
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World!")4}5import (6func main() {7 fmt.Println("Hello World!")8}9import (10func main() {11 fmt.Println("Hello World!")12}13import (14func main() {15 fmt.Println("Hello World!")16}17import (18func main() {19 fmt.Println("Hello World!")20}21import (22func main() {23 fmt.Println("Hello World!")24}25import (26func main() {27 fmt.Println("Hello World!")28}29import (30func main() {31 fmt.Println("Hello World!")32}33import (34func main() {35 fmt.Println("Hello World!")36}37import (
Filter
Using AI Code Generation
1import (2func main() {3 fmt.Println(gauge.Filter("Hello World", "World"))4}5import (6func main() {7 fmt.Println(gauge.Filter("Hello World", "World", "Hello"))8}9import (10func main() {11 fmt.Println(gauge.Filter("Hello World", "World", "Hello", "World"))12}13import (14func main() {15 fmt.Println(gauge.Filter("Hello World", "World", "Hello", "World", "Hello"))16}17import (18func main() {19 fmt.Println(gauge.Filter("Hello World", "World", "Hello", "World", "Hello", "World"))20}21import (22func main() {23 fmt.Println(gauge.Filter("Hello World", "World", "Hello", "World", "Hello", "World", "Hello"))24}25import (26func main() {27 fmt.Println(gauge.Filter("Hello World", "World", "Hello", "World", "Hello", "World", "Hello", "World"))28}29import (
Filter
Using AI Code Generation
1import "fmt"2type Gauge struct {3}4func (g Gauge) Filter() Gauge {5}6func main() {7 g := Gauge{value: 10}8 g = g.Filter()9 fmt.Println(g.value)10}11import "fmt"12type Gauge struct {13}14func (g *Gauge) Filter() {15}16func main() {17 g := Gauge{value: 10}18 g.Filter()19 fmt.Println(g.value)20}21import "fmt"22type Gauge struct {23}24func (g Gauge) Filter() {25}26func main() {27 g := Gauge{value: 10}28 g.Filter()29 fmt.Println(g.value)30}
Filter
Using AI Code Generation
1import (2type Gauge struct {3}4func Filter(gauges []Gauge, f func(Gauge) bool) []Gauge {5 vsf := make([]Gauge, 0)6 for _, v := range gauges {7 if f(v) {8 vsf = append(vsf, v)9 }10 }11}12func main() {13 gauges := []Gauge{14 {ID: 1, Name: "Gauge 1", Value: 12.3, Unit: "m", Location: "Location 1"},15 {ID: 2, Name: "Gauge 2", Value: 23.4, Unit: "m", Location: "Location 2"},16 {ID: 3, Name: "Gauge 3", Value: 34.5, Unit: "m", Location: "Location 3"},17 {ID: 4, Name: "Gauge 4", Value: 45.6, Unit: "m", Location: "Location 4"},18 {ID: 5, Name: "Gauge 5", Value: 56.7, Unit: "m", Location: "Location 5"},19 {ID: 6, Name: "Gauge 6", Value: 67.8, Unit: "m", Location: "Location 6"},20 {ID: 7, Name: "Gauge 7", Value: 78.9, Unit: "m", Location: "Location 7"},21 {ID: 8, Name: "Gauge 8", Value: 89.1, Unit: "m", Location: "Location 8"},22 {ID: 9, Name: "Gauge 9", Value: 91.2, Unit: "m", Location: "Location 9"},23 {ID: 10, Name: "Gauge 10", Value: 102.3
Filter
Using AI Code Generation
1import (2func main() {3 g.Set(10)4 fmt.Println(g.Filter(5))5}6import (7func main() {8 g.Set(10)9 fmt.Println(g.Filter(5))10}11import (12func main() {13 g.Set(10)14 fmt.Println(g.Filter(5))15}16import (17func main() {18 g.Set(10)19 fmt.Println(g.Filter(5))20}21import (22func main() {23 g.Set(10)24 fmt.Println(g.Filter(5))25}26import (27func main() {28 g.Set(10)29 fmt.Println(g.Filter(5))30}31import (32func main() {33 g.Set(10)34 fmt.Println(g.Filter(5))35}36import (37func main() {38 g.Set(10)39 fmt.Println(g.Filter(5))40}41import (42func main() {
Filter
Using AI Code Generation
1import (2func main() {3 g := Gauge{make([]float64, 0), 0}4 g.Add(2)5 g.Add(3)6 g.Add(4)7 g.Add(5)8 g.Add(6)9 g.Add(7)10 g.Filter(5)11 fmt.Println(g.Values)12}13import (14func main() {15 g := Gauge{make([]float64, 0), 0}16 g.Add(2)17 g.Add(3)18 g.Add(4)19 g.Add(5)20 g.Add(6)21 g.Add(7)22 g.Map(func(x float64) float64 {23 })24 fmt.Println(g.Values)25}26import (27func main() {28 g := Gauge{make([]float64, 0), 0}29 g.Add(2)30 g.Add(3)31 g.Add(4)32 g.Add(5)33 g.Add(6)34 g.Add(7)35 result := g.Reduce(func(x float64, y float64) float64 {36 })37 fmt.Println(result)38}39import (40func main() {41 g := Gauge{make([]float64, 0), 0}42 g.Add(2)43 g.Add(3)44 g.Add(4)45 g.Add(5)46 g.Add(6)47 g.Add(7)48 avg := g.Reduce(func(x float64, y
Filter
Using AI Code Generation
1import (2func main() {3 g := Gauge{value: 10}4 g.Filter()5 fmt.Println(g.value)6}7import (8func main() {9 g := Gauge{value: 10}10 g.Filter()11 fmt.Println(g.value)12}13import (14func main() {15 g := Gauge{value: 10}16 g.Filter()17 fmt.Println(g.value)18}19import (20func main() {21 g := Gauge{value: 10}22 g.Filter()23 fmt.Println(g.value)24}25import (26func main() {27 g := Gauge{value: 10}28 g.Filter()29 fmt.Println(g.value)30}31import (32func main() {33 g := Gauge{value: 10}34 g.Filter()35 fmt.Println(g.value)36}37import (38func main() {39 g := Gauge{value: 10}40 g.Filter()
Filter
Using AI Code Generation
1type Gauge struct {2}3func (gauge *Gauge) Filter() {4}5type Gauge struct {6}7func (gauge *Gauge) Filter() {8}9func GetGauge() *Gauge {10 return &Gauge{}11}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!