How to use Get method of result Package

Best Testkube code snippet using result.Get

aggregation_test.go

Source:aggregation_test.go Github

copy

Full Screen

...39 return rows40}41func (s *testAggFuncSuit) SetUpSuite(c *C) {42 s.ctx = mock.NewContext()43 s.ctx.GetSessionVars().GlobalVarsAccessor = variable.NewMockGlobalAccessor()44 s.rows = generateRowData()45 s.nullRow = chunk.MutRowFromDatums([]types.Datum{{}}).ToRow()46}47func (s *testAggFuncSuit) TestAvg(c *C) {48 col := &expression.Column{49 Index: 0,50 RetType: types.NewFieldType(mysql.TypeLonglong),51 }52 ctx := mock.NewContext()53 avgFunc := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{col}, false).GetAggFunc(ctx)54 evalCtx := avgFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)55 result := avgFunc.GetResult(evalCtx)56 c.Assert(result.IsNull(), IsTrue)57 for _, row := range s.rows {58 err := avgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)59 c.Assert(err, IsNil)60 }61 result = avgFunc.GetResult(evalCtx)62 needed := types.NewDecFromStringForTest("67.000000000000000000000000000000")63 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)64 err := avgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)65 c.Assert(err, IsNil)66 result = avgFunc.GetResult(evalCtx)67 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)68 distinctAvgFunc := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{col}, true).GetAggFunc(ctx)69 evalCtx = distinctAvgFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)70 for _, row := range s.rows {71 err := distinctAvgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)72 c.Assert(err, IsNil)73 }74 result = distinctAvgFunc.GetResult(evalCtx)75 needed = types.NewDecFromStringForTest("50.500000000000000000000000000000")76 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)77 partialResult := distinctAvgFunc.GetPartialResult(evalCtx)78 c.Assert(partialResult[0].GetInt64(), Equals, int64(100))79 needed = types.NewDecFromStringForTest("5050")80 c.Assert(partialResult[1].GetMysqlDecimal().Compare(needed) == 0, IsTrue, Commentf("%v, %v ", result.GetMysqlDecimal(), needed))81}82func (s *testAggFuncSuit) TestAvgFinalMode(c *C) {83 rows := make([][]types.Datum, 0, 100)84 for i := 1; i <= 100; i++ {85 rows = append(rows, types.MakeDatums(i, types.NewDecFromInt(int64(i*i))))86 }87 ctx := mock.NewContext()88 cntCol := &expression.Column{89 Index: 0,90 RetType: types.NewFieldType(mysql.TypeLonglong),91 }92 sumCol := &expression.Column{93 Index: 1,94 RetType: types.NewFieldType(mysql.TypeNewDecimal),95 }96 aggFunc := NewAggFuncDesc(s.ctx, ast.AggFuncAvg, []expression.Expression{cntCol, sumCol}, false)97 aggFunc.Mode = FinalMode98 avgFunc := aggFunc.GetAggFunc(ctx)99 evalCtx := avgFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)100 for _, row := range rows {101 err := avgFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, chunk.MutRowFromDatums(row).ToRow())102 c.Assert(err, IsNil)103 }104 result := avgFunc.GetResult(evalCtx)105 needed := types.NewDecFromStringForTest("67.000000000000000000000000000000")106 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)107}108func (s *testAggFuncSuit) TestSum(c *C) {109 col := &expression.Column{110 Index: 0,111 RetType: types.NewFieldType(mysql.TypeLonglong),112 }113 ctx := mock.NewContext()114 sumFunc := NewAggFuncDesc(s.ctx, ast.AggFuncSum, []expression.Expression{col}, false).GetAggFunc(ctx)115 evalCtx := sumFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)116 result := sumFunc.GetResult(evalCtx)117 c.Assert(result.IsNull(), IsTrue)118 for _, row := range s.rows {119 err := sumFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)120 c.Assert(err, IsNil)121 }122 result = sumFunc.GetResult(evalCtx)123 needed := types.NewDecFromStringForTest("338350")124 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)125 err := sumFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)126 c.Assert(err, IsNil)127 result = sumFunc.GetResult(evalCtx)128 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)129 partialResult := sumFunc.GetPartialResult(evalCtx)130 c.Assert(partialResult[0].GetMysqlDecimal().Compare(needed) == 0, IsTrue)131 distinctSumFunc := NewAggFuncDesc(s.ctx, ast.AggFuncSum, []expression.Expression{col}, true).GetAggFunc(ctx)132 evalCtx = distinctSumFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)133 for _, row := range s.rows {134 err := distinctSumFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)135 c.Assert(err, IsNil)136 }137 result = distinctSumFunc.GetResult(evalCtx)138 needed = types.NewDecFromStringForTest("5050")139 c.Assert(result.GetMysqlDecimal().Compare(needed) == 0, IsTrue)140}141func (s *testAggFuncSuit) TestBitAnd(c *C) {142 col := &expression.Column{143 Index: 0,144 RetType: types.NewFieldType(mysql.TypeLonglong),145 }146 ctx := mock.NewContext()147 bitAndFunc := NewAggFuncDesc(s.ctx, ast.AggFuncBitAnd, []expression.Expression{col}, false).GetAggFunc(ctx)148 evalCtx := bitAndFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)149 result := bitAndFunc.GetResult(evalCtx)150 c.Assert(result.GetUint64(), Equals, uint64(math.MaxUint64))151 row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()152 err := bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)153 c.Assert(err, IsNil)154 result = bitAndFunc.GetResult(evalCtx)155 c.Assert(result.GetUint64(), Equals, uint64(1))156 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)157 c.Assert(err, IsNil)158 result = bitAndFunc.GetResult(evalCtx)159 c.Assert(result.GetUint64(), Equals, uint64(1))160 row = chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()161 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)162 c.Assert(err, IsNil)163 result = bitAndFunc.GetResult(evalCtx)164 c.Assert(result.GetUint64(), Equals, uint64(1))165 row = chunk.MutRowFromDatums(types.MakeDatums(3)).ToRow()166 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)167 c.Assert(err, IsNil)168 result = bitAndFunc.GetResult(evalCtx)169 c.Assert(result.GetUint64(), Equals, uint64(1))170 row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow()171 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)172 c.Assert(err, IsNil)173 result = bitAndFunc.GetResult(evalCtx)174 c.Assert(result.GetUint64(), Equals, uint64(0))175 partialResult := bitAndFunc.GetPartialResult(evalCtx)176 c.Assert(partialResult[0].GetUint64(), Equals, uint64(0))177 // test bit_and( decimal )178 col.RetType = types.NewFieldType(mysql.TypeNewDecimal)179 bitAndFunc.ResetContext(s.ctx.GetSessionVars().StmtCtx, evalCtx)180 result = bitAndFunc.GetResult(evalCtx)181 c.Assert(result.GetUint64(), Equals, uint64(math.MaxUint64))182 var dec types.MyDecimal183 err = dec.FromString([]byte("1.234"))184 c.Assert(err, IsNil)185 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()186 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)187 c.Assert(err, IsNil)188 result = bitAndFunc.GetResult(evalCtx)189 c.Assert(result.GetUint64(), Equals, uint64(1))190 err = dec.FromString([]byte("3.012"))191 c.Assert(err, IsNil)192 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()193 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)194 c.Assert(err, IsNil)195 result = bitAndFunc.GetResult(evalCtx)196 c.Assert(result.GetUint64(), Equals, uint64(1))197 err = dec.FromString([]byte("2.12345678"))198 c.Assert(err, IsNil)199 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()200 err = bitAndFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)201 c.Assert(err, IsNil)202 result = bitAndFunc.GetResult(evalCtx)203 c.Assert(result.GetUint64(), Equals, uint64(0))204}205func (s *testAggFuncSuit) TestBitOr(c *C) {206 col := &expression.Column{207 Index: 0,208 RetType: types.NewFieldType(mysql.TypeLonglong),209 }210 ctx := mock.NewContext()211 bitOrFunc := NewAggFuncDesc(s.ctx, ast.AggFuncBitOr, []expression.Expression{col}, false).GetAggFunc(ctx)212 evalCtx := bitOrFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)213 result := bitOrFunc.GetResult(evalCtx)214 c.Assert(result.GetUint64(), Equals, uint64(0))215 row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()216 err := bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)217 c.Assert(err, IsNil)218 result = bitOrFunc.GetResult(evalCtx)219 c.Assert(result.GetUint64(), Equals, uint64(1))220 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)221 c.Assert(err, IsNil)222 result = bitOrFunc.GetResult(evalCtx)223 c.Assert(result.GetUint64(), Equals, uint64(1))224 row = chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()225 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)226 c.Assert(err, IsNil)227 result = bitOrFunc.GetResult(evalCtx)228 c.Assert(result.GetUint64(), Equals, uint64(1))229 row = chunk.MutRowFromDatums(types.MakeDatums(3)).ToRow()230 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)231 c.Assert(err, IsNil)232 result = bitOrFunc.GetResult(evalCtx)233 c.Assert(result.GetUint64(), Equals, uint64(3))234 row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow()235 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)236 c.Assert(err, IsNil)237 result = bitOrFunc.GetResult(evalCtx)238 c.Assert(result.GetUint64(), Equals, uint64(3))239 partialResult := bitOrFunc.GetPartialResult(evalCtx)240 c.Assert(partialResult[0].GetUint64(), Equals, uint64(3))241 // test bit_or( decimal )242 col.RetType = types.NewFieldType(mysql.TypeNewDecimal)243 bitOrFunc.ResetContext(s.ctx.GetSessionVars().StmtCtx, evalCtx)244 result = bitOrFunc.GetResult(evalCtx)245 c.Assert(result.GetUint64(), Equals, uint64(0))246 var dec types.MyDecimal247 err = dec.FromString([]byte("12.234"))248 c.Assert(err, IsNil)249 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()250 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)251 c.Assert(err, IsNil)252 result = bitOrFunc.GetResult(evalCtx)253 c.Assert(result.GetUint64(), Equals, uint64(12))254 err = dec.FromString([]byte("1.012"))255 c.Assert(err, IsNil)256 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()257 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)258 c.Assert(err, IsNil)259 result = bitOrFunc.GetResult(evalCtx)260 c.Assert(result.GetUint64(), Equals, uint64(13))261 err = dec.FromString([]byte("15.12345678"))262 c.Assert(err, IsNil)263 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()264 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)265 c.Assert(err, IsNil)266 result = bitOrFunc.GetResult(evalCtx)267 c.Assert(result.GetUint64(), Equals, uint64(15))268 err = dec.FromString([]byte("16.00"))269 c.Assert(err, IsNil)270 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()271 err = bitOrFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)272 c.Assert(err, IsNil)273 result = bitOrFunc.GetResult(evalCtx)274 c.Assert(result.GetUint64(), Equals, uint64(31))275}276func (s *testAggFuncSuit) TestBitXor(c *C) {277 col := &expression.Column{278 Index: 0,279 RetType: types.NewFieldType(mysql.TypeLonglong),280 }281 ctx := mock.NewContext()282 bitXorFunc := NewAggFuncDesc(s.ctx, ast.AggFuncBitXor, []expression.Expression{col}, false).GetAggFunc(ctx)283 evalCtx := bitXorFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)284 result := bitXorFunc.GetResult(evalCtx)285 c.Assert(result.GetUint64(), Equals, uint64(0))286 row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()287 err := bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)288 c.Assert(err, IsNil)289 result = bitXorFunc.GetResult(evalCtx)290 c.Assert(result.GetUint64(), Equals, uint64(1))291 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)292 c.Assert(err, IsNil)293 result = bitXorFunc.GetResult(evalCtx)294 c.Assert(result.GetUint64(), Equals, uint64(1))295 row = chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()296 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)297 c.Assert(err, IsNil)298 result = bitXorFunc.GetResult(evalCtx)299 c.Assert(result.GetUint64(), Equals, uint64(0))300 row = chunk.MutRowFromDatums(types.MakeDatums(3)).ToRow()301 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)302 c.Assert(err, IsNil)303 result = bitXorFunc.GetResult(evalCtx)304 c.Assert(result.GetUint64(), Equals, uint64(3))305 row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow()306 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)307 c.Assert(err, IsNil)308 result = bitXorFunc.GetResult(evalCtx)309 c.Assert(result.GetUint64(), Equals, uint64(1))310 partialResult := bitXorFunc.GetPartialResult(evalCtx)311 c.Assert(partialResult[0].GetUint64(), Equals, uint64(1))312 // test bit_xor( decimal )313 col.RetType = types.NewFieldType(mysql.TypeNewDecimal)314 bitXorFunc.ResetContext(s.ctx.GetSessionVars().StmtCtx, evalCtx)315 result = bitXorFunc.GetResult(evalCtx)316 c.Assert(result.GetUint64(), Equals, uint64(0))317 var dec types.MyDecimal318 err = dec.FromString([]byte("1.234"))319 c.Assert(err, IsNil)320 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()321 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)322 c.Assert(err, IsNil)323 result = bitXorFunc.GetResult(evalCtx)324 c.Assert(result.GetUint64(), Equals, uint64(1))325 err = dec.FromString([]byte("1.012"))326 c.Assert(err, IsNil)327 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()328 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)329 c.Assert(err, IsNil)330 result = bitXorFunc.GetResult(evalCtx)331 c.Assert(result.GetUint64(), Equals, uint64(0))332 err = dec.FromString([]byte("2.12345678"))333 c.Assert(err, IsNil)334 row = chunk.MutRowFromDatums(types.MakeDatums(&dec)).ToRow()335 err = bitXorFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)336 c.Assert(err, IsNil)337 result = bitXorFunc.GetResult(evalCtx)338 c.Assert(result.GetUint64(), Equals, uint64(2))339}340func (s *testAggFuncSuit) TestCount(c *C) {341 col := &expression.Column{342 Index: 0,343 RetType: types.NewFieldType(mysql.TypeLonglong),344 }345 ctx := mock.NewContext()346 countFunc := NewAggFuncDesc(s.ctx, ast.AggFuncCount, []expression.Expression{col}, false).GetAggFunc(ctx)347 evalCtx := countFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)348 result := countFunc.GetResult(evalCtx)349 c.Assert(result.GetInt64(), Equals, int64(0))350 for _, row := range s.rows {351 err := countFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)352 c.Assert(err, IsNil)353 }354 result = countFunc.GetResult(evalCtx)355 c.Assert(result.GetInt64(), Equals, int64(5050))356 err := countFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, s.nullRow)357 c.Assert(err, IsNil)358 result = countFunc.GetResult(evalCtx)359 c.Assert(result.GetInt64(), Equals, int64(5050))360 partialResult := countFunc.GetPartialResult(evalCtx)361 c.Assert(partialResult[0].GetInt64(), Equals, int64(5050))362 distinctCountFunc := NewAggFuncDesc(s.ctx, ast.AggFuncCount, []expression.Expression{col}, true).GetAggFunc(ctx)363 evalCtx = distinctCountFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)364 for _, row := range s.rows {365 err := distinctCountFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)366 c.Assert(err, IsNil)367 }368 result = distinctCountFunc.GetResult(evalCtx)369 c.Assert(result.GetInt64(), Equals, int64(100))370}371func (s *testAggFuncSuit) TestConcat(c *C) {372 col := &expression.Column{373 Index: 0,374 RetType: types.NewFieldType(mysql.TypeLonglong),375 }376 sep := &expression.Column{377 Index: 1,378 RetType: types.NewFieldType(mysql.TypeVarchar),379 }380 ctx := mock.NewContext()381 concatFunc := NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, false).GetAggFunc(ctx)382 evalCtx := concatFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)383 result := concatFunc.GetResult(evalCtx)384 c.Assert(result.IsNull(), IsTrue)385 row := chunk.MutRowFromDatums(types.MakeDatums(1, "x"))386 err := concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())387 c.Assert(err, IsNil)388 result = concatFunc.GetResult(evalCtx)389 c.Assert(result.GetString(), Equals, "1")390 row.SetDatum(0, types.NewIntDatum(2))391 err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())392 c.Assert(err, IsNil)393 result = concatFunc.GetResult(evalCtx)394 c.Assert(result.GetString(), Equals, "1x2")395 row.SetDatum(0, types.NewDatum(nil))396 err = concatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())397 c.Assert(err, IsNil)398 result = concatFunc.GetResult(evalCtx)399 c.Assert(result.GetString(), Equals, "1x2")400 partialResult := concatFunc.GetPartialResult(evalCtx)401 c.Assert(partialResult[0].GetString(), Equals, "1x2")402 distinctConcatFunc := NewAggFuncDesc(s.ctx, ast.AggFuncGroupConcat, []expression.Expression{col, sep}, true).GetAggFunc(ctx)403 evalCtx = distinctConcatFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)404 row.SetDatum(0, types.NewIntDatum(1))405 err = distinctConcatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())406 c.Assert(err, IsNil)407 result = distinctConcatFunc.GetResult(evalCtx)408 c.Assert(result.GetString(), Equals, "1")409 row.SetDatum(0, types.NewIntDatum(1))410 err = distinctConcatFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())411 c.Assert(err, IsNil)412 result = distinctConcatFunc.GetResult(evalCtx)413 c.Assert(result.GetString(), Equals, "1")414}415func (s *testAggFuncSuit) TestFirstRow(c *C) {416 col := &expression.Column{417 Index: 0,418 RetType: types.NewFieldType(mysql.TypeLonglong),419 }420 ctx := mock.NewContext()421 firstRowFunc := NewAggFuncDesc(s.ctx, ast.AggFuncFirstRow, []expression.Expression{col}, false).GetAggFunc(ctx)422 evalCtx := firstRowFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)423 row := chunk.MutRowFromDatums(types.MakeDatums(1)).ToRow()424 err := firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)425 c.Assert(err, IsNil)426 result := firstRowFunc.GetResult(evalCtx)427 c.Assert(result.GetUint64(), Equals, uint64(1))428 row = chunk.MutRowFromDatums(types.MakeDatums(2)).ToRow()429 err = firstRowFunc.Update(evalCtx, s.ctx.GetSessionVars().StmtCtx, row)430 c.Assert(err, IsNil)431 result = firstRowFunc.GetResult(evalCtx)432 c.Assert(result.GetUint64(), Equals, uint64(1))433 partialResult := firstRowFunc.GetPartialResult(evalCtx)434 c.Assert(partialResult[0].GetUint64(), Equals, uint64(1))435}436func (s *testAggFuncSuit) TestMaxMin(c *C) {437 col := &expression.Column{438 Index: 0,439 RetType: types.NewFieldType(mysql.TypeLonglong),440 }441 ctx := mock.NewContext()442 maxFunc := NewAggFuncDesc(s.ctx, ast.AggFuncMax, []expression.Expression{col}, false).GetAggFunc(ctx)443 minFunc := NewAggFuncDesc(s.ctx, ast.AggFuncMin, []expression.Expression{col}, false).GetAggFunc(ctx)444 maxEvalCtx := maxFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)445 minEvalCtx := minFunc.CreateContext(s.ctx.GetSessionVars().StmtCtx)446 result := maxFunc.GetResult(maxEvalCtx)447 c.Assert(result.IsNull(), IsTrue)448 result = minFunc.GetResult(minEvalCtx)449 c.Assert(result.IsNull(), IsTrue)450 row := chunk.MutRowFromDatums(types.MakeDatums(2))451 err := maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())452 c.Assert(err, IsNil)453 result = maxFunc.GetResult(maxEvalCtx)454 c.Assert(result.GetInt64(), Equals, int64(2))455 err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())456 c.Assert(err, IsNil)457 result = minFunc.GetResult(minEvalCtx)458 c.Assert(result.GetInt64(), Equals, int64(2))459 row.SetDatum(0, types.NewIntDatum(3))460 err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())461 c.Assert(err, IsNil)462 result = maxFunc.GetResult(maxEvalCtx)463 c.Assert(result.GetInt64(), Equals, int64(3))464 err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())465 c.Assert(err, IsNil)466 result = minFunc.GetResult(minEvalCtx)467 c.Assert(result.GetInt64(), Equals, int64(2))468 row.SetDatum(0, types.NewIntDatum(1))469 err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())470 c.Assert(err, IsNil)471 result = maxFunc.GetResult(maxEvalCtx)472 c.Assert(result.GetInt64(), Equals, int64(3))473 err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())474 c.Assert(err, IsNil)475 result = minFunc.GetResult(minEvalCtx)476 c.Assert(result.GetInt64(), Equals, int64(1))477 row.SetDatum(0, types.NewDatum(nil))478 err = maxFunc.Update(maxEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())479 c.Assert(err, IsNil)480 result = maxFunc.GetResult(maxEvalCtx)481 c.Assert(result.GetInt64(), Equals, int64(3))482 err = minFunc.Update(minEvalCtx, s.ctx.GetSessionVars().StmtCtx, row.ToRow())483 c.Assert(err, IsNil)484 result = minFunc.GetResult(minEvalCtx)485 c.Assert(result.GetInt64(), Equals, int64(1))486 partialResult := minFunc.GetPartialResult(minEvalCtx)487 c.Assert(partialResult[0].GetInt64(), Equals, int64(1))488}...

Full Screen

Full Screen

context_test.go

Source:context_test.go Github

copy

Full Screen

1// Copyright 2018 Frédéric Guillot. All rights reserved.2// Use of this source code is governed by the Apache 2.03// license that can be found in the LICENSE file.4package request // import "miniflux.app/http/request"5import (6 "context"7 "net/http"8 "testing"9)10func TestContextStringValue(t *testing.T) {11 r, _ := http.NewRequest("GET", "http://example.org", nil)12 ctx := r.Context()13 ctx = context.WithValue(ctx, ClientIPContextKey, "IP")14 r = r.WithContext(ctx)15 result := getContextStringValue(r, ClientIPContextKey)16 expected := "IP"17 if result != expected {18 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)19 }20}21func TestContextStringValueWithInvalidType(t *testing.T) {22 r, _ := http.NewRequest("GET", "http://example.org", nil)23 ctx := r.Context()24 ctx = context.WithValue(ctx, ClientIPContextKey, 0)25 r = r.WithContext(ctx)26 result := getContextStringValue(r, ClientIPContextKey)27 expected := ""28 if result != expected {29 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)30 }31}32func TestContextStringValueWhenUnset(t *testing.T) {33 r, _ := http.NewRequest("GET", "http://example.org", nil)34 result := getContextStringValue(r, ClientIPContextKey)35 expected := ""36 if result != expected {37 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)38 }39}40func TestContextBoolValue(t *testing.T) {41 r, _ := http.NewRequest("GET", "http://example.org", nil)42 ctx := r.Context()43 ctx = context.WithValue(ctx, IsAdminUserContextKey, true)44 r = r.WithContext(ctx)45 result := getContextBoolValue(r, IsAdminUserContextKey)46 expected := true47 if result != expected {48 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)49 }50}51func TestContextBoolValueWithInvalidType(t *testing.T) {52 r, _ := http.NewRequest("GET", "http://example.org", nil)53 ctx := r.Context()54 ctx = context.WithValue(ctx, IsAdminUserContextKey, "invalid")55 r = r.WithContext(ctx)56 result := getContextBoolValue(r, IsAdminUserContextKey)57 expected := false58 if result != expected {59 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)60 }61}62func TestContextBoolValueWhenUnset(t *testing.T) {63 r, _ := http.NewRequest("GET", "http://example.org", nil)64 result := getContextBoolValue(r, IsAdminUserContextKey)65 expected := false66 if result != expected {67 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)68 }69}70func TestContextInt64Value(t *testing.T) {71 r, _ := http.NewRequest("GET", "http://example.org", nil)72 ctx := r.Context()73 ctx = context.WithValue(ctx, UserIDContextKey, int64(1234))74 r = r.WithContext(ctx)75 result := getContextInt64Value(r, UserIDContextKey)76 expected := int64(1234)77 if result != expected {78 t.Errorf(`Unexpected context value, got %d instead of %d`, result, expected)79 }80}81func TestContextInt64ValueWithInvalidType(t *testing.T) {82 r, _ := http.NewRequest("GET", "http://example.org", nil)83 ctx := r.Context()84 ctx = context.WithValue(ctx, UserIDContextKey, "invalid")85 r = r.WithContext(ctx)86 result := getContextInt64Value(r, UserIDContextKey)87 expected := int64(0)88 if result != expected {89 t.Errorf(`Unexpected context value, got %d instead of %d`, result, expected)90 }91}92func TestContextInt64ValueWhenUnset(t *testing.T) {93 r, _ := http.NewRequest("GET", "http://example.org", nil)94 result := getContextInt64Value(r, UserIDContextKey)95 expected := int64(0)96 if result != expected {97 t.Errorf(`Unexpected context value, got %d instead of %d`, result, expected)98 }99}100func TestIsAdmin(t *testing.T) {101 r, _ := http.NewRequest("GET", "http://example.org", nil)102 result := IsAdminUser(r)103 expected := false104 if result != expected {105 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)106 }107 ctx := r.Context()108 ctx = context.WithValue(ctx, IsAdminUserContextKey, true)109 r = r.WithContext(ctx)110 result = IsAdminUser(r)111 expected = true112 if result != expected {113 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)114 }115}116func TestIsAuthenticated(t *testing.T) {117 r, _ := http.NewRequest("GET", "http://example.org", nil)118 result := IsAuthenticated(r)119 expected := false120 if result != expected {121 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)122 }123 ctx := r.Context()124 ctx = context.WithValue(ctx, IsAuthenticatedContextKey, true)125 r = r.WithContext(ctx)126 result = IsAuthenticated(r)127 expected = true128 if result != expected {129 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)130 }131}132func TestUserID(t *testing.T) {133 r, _ := http.NewRequest("GET", "http://example.org", nil)134 result := UserID(r)135 expected := int64(0)136 if result != expected {137 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)138 }139 ctx := r.Context()140 ctx = context.WithValue(ctx, UserIDContextKey, int64(123))141 r = r.WithContext(ctx)142 result = UserID(r)143 expected = int64(123)144 if result != expected {145 t.Errorf(`Unexpected context value, got %v instead of %v`, result, expected)146 }147}148func TestUserTimezone(t *testing.T) {149 r, _ := http.NewRequest("GET", "http://example.org", nil)150 result := UserTimezone(r)151 expected := "UTC"152 if result != expected {153 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)154 }155 ctx := r.Context()156 ctx = context.WithValue(ctx, UserTimezoneContextKey, "Europe/Paris")157 r = r.WithContext(ctx)158 result = UserTimezone(r)159 expected = "Europe/Paris"160 if result != expected {161 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)162 }163}164func TestUserLanguage(t *testing.T) {165 r, _ := http.NewRequest("GET", "http://example.org", nil)166 result := UserLanguage(r)167 expected := "en_US"168 if result != expected {169 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)170 }171 ctx := r.Context()172 ctx = context.WithValue(ctx, UserLanguageContextKey, "fr_FR")173 r = r.WithContext(ctx)174 result = UserLanguage(r)175 expected = "fr_FR"176 if result != expected {177 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)178 }179}180func TestUserTheme(t *testing.T) {181 r, _ := http.NewRequest("GET", "http://example.org", nil)182 result := UserTheme(r)183 expected := "system_serif"184 if result != expected {185 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)186 }187 ctx := r.Context()188 ctx = context.WithValue(ctx, UserThemeContextKey, "dark_serif")189 r = r.WithContext(ctx)190 result = UserTheme(r)191 expected = "dark_serif"192 if result != expected {193 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)194 }195}196func TestCSRF(t *testing.T) {197 r, _ := http.NewRequest("GET", "http://example.org", nil)198 result := CSRF(r)199 expected := ""200 if result != expected {201 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)202 }203 ctx := r.Context()204 ctx = context.WithValue(ctx, CSRFContextKey, "secret")205 r = r.WithContext(ctx)206 result = CSRF(r)207 expected = "secret"208 if result != expected {209 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)210 }211}212func TestSessionID(t *testing.T) {213 r, _ := http.NewRequest("GET", "http://example.org", nil)214 result := SessionID(r)215 expected := ""216 if result != expected {217 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)218 }219 ctx := r.Context()220 ctx = context.WithValue(ctx, SessionIDContextKey, "id")221 r = r.WithContext(ctx)222 result = SessionID(r)223 expected = "id"224 if result != expected {225 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)226 }227}228func TestUserSessionToken(t *testing.T) {229 r, _ := http.NewRequest("GET", "http://example.org", nil)230 result := UserSessionToken(r)231 expected := ""232 if result != expected {233 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)234 }235 ctx := r.Context()236 ctx = context.WithValue(ctx, UserSessionTokenContextKey, "token")237 r = r.WithContext(ctx)238 result = UserSessionToken(r)239 expected = "token"240 if result != expected {241 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)242 }243}244func TestOAuth2State(t *testing.T) {245 r, _ := http.NewRequest("GET", "http://example.org", nil)246 result := OAuth2State(r)247 expected := ""248 if result != expected {249 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)250 }251 ctx := r.Context()252 ctx = context.WithValue(ctx, OAuth2StateContextKey, "state")253 r = r.WithContext(ctx)254 result = OAuth2State(r)255 expected = "state"256 if result != expected {257 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)258 }259}260func TestFlashMessage(t *testing.T) {261 r, _ := http.NewRequest("GET", "http://example.org", nil)262 result := FlashMessage(r)263 expected := ""264 if result != expected {265 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)266 }267 ctx := r.Context()268 ctx = context.WithValue(ctx, FlashMessageContextKey, "message")269 r = r.WithContext(ctx)270 result = FlashMessage(r)271 expected = "message"272 if result != expected {273 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)274 }275}276func TestFlashErrorMessage(t *testing.T) {277 r, _ := http.NewRequest("GET", "http://example.org", nil)278 result := FlashErrorMessage(r)279 expected := ""280 if result != expected {281 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)282 }283 ctx := r.Context()284 ctx = context.WithValue(ctx, FlashErrorMessageContextKey, "error message")285 r = r.WithContext(ctx)286 result = FlashErrorMessage(r)287 expected = "error message"288 if result != expected {289 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)290 }291}292func TestPocketRequestToken(t *testing.T) {293 r, _ := http.NewRequest("GET", "http://example.org", nil)294 result := PocketRequestToken(r)295 expected := ""296 if result != expected {297 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)298 }299 ctx := r.Context()300 ctx = context.WithValue(ctx, PocketRequestTokenContextKey, "request token")301 r = r.WithContext(ctx)302 result = PocketRequestToken(r)303 expected = "request token"304 if result != expected {305 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)306 }307}308func TestClientIP(t *testing.T) {309 r, _ := http.NewRequest("GET", "http://example.org", nil)310 result := ClientIP(r)311 expected := ""312 if result != expected {313 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)314 }315 ctx := r.Context()316 ctx = context.WithValue(ctx, ClientIPContextKey, "127.0.0.1")317 r = r.WithContext(ctx)318 result = ClientIP(r)319 expected = "127.0.0.1"320 if result != expected {321 t.Errorf(`Unexpected context value, got %q instead of %q`, result, expected)322 }323}...

Full Screen

Full Screen

position.go

Source:position.go Github

copy

Full Screen

...132 p := PositionFromFileRank(file, rank)133 return p, true134}135func (p Position) String() string {136 f := byte(p.GetFile())137 r := byte(p.GetRank())138 return string([]byte{f, r})139}140func (p Position) GetRank() Rank {141 rank := p/8 + 1142 return Rank(rank + '0')143}144func (p Position) GetFile() File {145 file := p % 8146 return File(file + 'a')147}148func (p Position) GetWhitePawnAttacks() []Position {149 positions := []Position{}150 file, rank := p.GetFile(), p.GetRank()151 if rank > '1' && rank < '8' {152 if file > 'a' {153 positions = append(positions, p+7)154 }155 if file < 'h' {156 positions = append(positions, p+9)157 }158 }159 return positions160}161func (p Position) GetBlackPawnAttacks() []Position {162 positions := []Position{}163 file, rank := p.GetFile(), p.GetRank()164 if rank > '1' && rank < '8' {165 if file > 'a' {166 positions = append(positions, p-9)167 }168 if file < 'h' {169 positions = append(positions, p-7)170 }171 }172 return positions173}174func (p Position) GetWhitePawnMoves() [][]Position {175 pieceMoves := p.GetPieceMoves(WhitePawn)176 result := [][]Position{}177 result = append(result, pieceMoves)178 return result179}180func (p Position) GetBlackPawnMoves() [][]Position {181 pieceMoves := p.GetPieceMoves(BlackPawn)182 result := [][]Position{}183 result = append(result, pieceMoves)184 return result185}186func (p Position) GetAdjacentFiles() []File {187 f := p.GetFile()188 result := []File{}189 if f != 'a' {190 result = append(result, File(byte(f)-1))191 }192 if f != 'h' {193 result = append(result, File(byte(f)+1))194 }195 return result196}197func (p Position) GetEnPassantCapture() Position {198 if p.GetRank() == '3' {199 return p + 8200 }201 return p - 8202}203func (p Position) GetPieceMoves(piece Piece) []Position {204 return PieceMoves[int(piece)*64+int(p)]205}206func (p Position) GetMoveVectors(piece Piece) [][]Position {207 return MoveVectors[int(piece)*64+int(p)]208}209func (p Position) GetAttackVectors(piece Piece) [][]Position {210 return AttackVectors[int(piece)*64+int(p)]211}212func (p Position) GetPawnAttacks(color Color) []Position {213 return PawnAttacksBitmap[int(color.Opposite())*64+int(p)].ToPositions()214}215func (p Position) GetKnightMoves() []Position {216 return p.GetPieceMoves(WhiteKnight)217}218func (p Position) GetLines() [][]Position {219 return p.GetMoveVectors(WhiteRook)220}221func (p Position) GetDiagonals() [][]Position {222 return p.GetMoveVectors(WhiteBishop)223}224func (p Position) GetKingMoves() []Position {225 return p.GetPieceMoves(WhiteKing)226}227func (p Position) GetQueenMoves() [][]Position {228 return p.GetMoveVectors(WhiteQueen)229}230func (p Position) IsPawnAttack(p2 Position, color Color) bool {231 return PawnAttacksBitmap[int(color.Opposite())*64+int(p)].IsSet(p2)232}233func (p Position) IsPawnOpeningJump(color Color) bool {234 if color == Black {235 return p.GetRank() == '5'236 }237 return p.GetRank() == '4'238}239func (p Position) CanPawnOpeningJump(color Color) bool {240 if color == Black {241 return p.GetRank() == '7'242 }243 return p.GetRank() == '2'244}245func (p Position) GetPawnOpeningJump(color Color) Position {246 if color == Black {247 return p - 16248 }249 return p + 16250}251func PositionFromFileRank(f File, r Rank) Position {252 rank := int(r - '1')253 file := int(f - 'a')254 return Position(rank*8 + file)255}256func init() {257 if false {258 formatPos := func(p Position) string {259 return strings.ToUpper(p.String())260 }261 formatMoves := func(moves []Position) string {262 result := []string{}263 for _, m := range moves {264 result = append(result, formatPos(m))265 }266 return "[]Position{" + strings.Join(result, ", ") + "}"267 }268 result := "package chess_engine\n\n"269 flatten := func(positions [][]Position) []Position {270 result := []Position{}271 for _, line := range positions {272 for _, pos := range line {273 result = append(result, pos)274 }275 }276 return result277 }278 expand := func(positions []Position) [][]Position {279 result := [][]Position{}280 for _, p := range positions {281 result = append(result, []Position{p})282 }283 return result284 }285 getPositions := func(p Piece, pos Position) []Position {286 if p.ToNormalizedPiece() == King {287 return pos.GetKingMoves()288 } else if p.ToNormalizedPiece() == Knight {289 return pos.GetKnightMoves()290 } else if p.ToNormalizedPiece() == Pawn {291 if p.Color() == White {292 return flatten(pos.GetWhitePawnMoves())293 } else {294 return flatten(pos.GetBlackPawnMoves())295 }296 } else if p.ToNormalizedPiece() == Rook {297 return flatten(pos.GetLines())298 } else if p.ToNormalizedPiece() == Bishop {299 return flatten(pos.GetDiagonals())300 } else if p.ToNormalizedPiece() == Queen {301 return flatten(pos.GetQueenMoves())302 }303 panic("adsa")304 }305 getLines := func(p Piece, pos Position) [][]Position {306 if p.ToNormalizedPiece() == King {307 return expand(pos.GetKingMoves())308 } else if p.ToNormalizedPiece() == Knight {309 return expand(pos.GetKnightMoves())310 } else if p.ToNormalizedPiece() == Pawn {311 if p.Color() == White {312 return pos.GetWhitePawnMoves()313 } else {314 return pos.GetBlackPawnMoves()315 }316 } else if p.ToNormalizedPiece() == Rook {317 return (pos.GetLines())318 } else if p.ToNormalizedPiece() == Bishop {319 return (pos.GetDiagonals())320 } else if p.ToNormalizedPiece() == Queen {321 return (pos.GetQueenMoves())322 }323 panic("adsa")324 }325 getAttacks := func(p Piece, pos Position) [][]Position {326 if p.ToNormalizedPiece() == King {327 return expand(pos.GetKingMoves())328 } else if p.ToNormalizedPiece() == Knight {329 return expand(pos.GetKnightMoves())330 } else if p.ToNormalizedPiece() == Pawn {331 if p.Color() == White {332 return expand(pos.GetWhitePawnAttacks())333 } else {334 return expand(pos.GetBlackPawnAttacks())335 }336 } else if p.ToNormalizedPiece() == Rook {337 return (pos.GetLines())338 } else if p.ToNormalizedPiece() == Bishop {339 return (pos.GetDiagonals())340 } else if p.ToNormalizedPiece() == Queen {341 return (pos.GetQueenMoves())342 }343 panic("adsa")344 }345 result += "var MoveVectors = [][][]Position{\n"346 for _, piece := range Pieces {347 result += "\t// " + piece.String() + "\n"348 for i := 0; i < 64; i++ {349 lines := getLines(piece, Position(i))350 if len(lines) == 0 || (len(lines) == 1 && len(lines[0]) == 0) {351 result += "\t[][]Position{},\n"352 continue353 }354 result += "\t[][]Position{\n"355 for _, moves := range lines {...

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Result struct {3}4func (r *Result) Get() int {5}6func (r *Result) Set(result int) {7}8func main() {9 r.Set(10)10 fmt.Println(r.Get())11}12import "fmt"13type Result struct {14}15func (r *Result) Get() int {16}17func (r *Result) Set(result int) {18}19func main() {20 r.Set(10)21 fmt.Println(r.Get())22}23import "fmt"24type Result struct {25}26func (r *Result) Get() int {27}28func (r *Result) Set(result int) {29}30func main() {31 r.Set(10)32 fmt.Println(r.Get())33}34import "fmt"35type Result struct {36}37func (r *Result) Get() int {38}39func (r *Result) Set(result int) {40}41func main() {42 r.Set(10)43 fmt.Println(r.Get())44}45import "fmt"46type Result struct {47}48func (r *Result) Get() int {49}50func (r *Result) Set(result int) {51}52func main() {53 r.Set(10)54 fmt.Println(r.Get())55}56import "fmt"57type Result struct {58}59func (r *Result) Get() int {60}61func (r *Result) Set(result int) {62}63func main() {64 r.Set(

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2type result struct {3}4func (r result) Get() (int, int) {5}6func main() {7r := result{a: 10, b: 20}8a, b := r.Get()9fmt.Println("a=", a, "b=", b)10}11import (12type result struct {13}14func (r result) Get() (int, int) {15}16func (r *result) Set(a, b int) {17}18func main() {19r := result{a: 10, b: 20}20a, b := r.Get()21fmt.Println("a=", a, "b=", b)22r.Set(100, 200)23a, b = r.Get()24fmt.Println("a=", a, "b=", b)25}26import (27type result struct {28}29func (r result) Get() (int, int) {30}31func (r *result) Set(a, b int) {32}33func main() {34r := result{a: 10, b: 20}35a, b := r.Get()36fmt.Println("a=", a, "b=", b)37r.Set(100, 200)38a, b = r.Get()39fmt.Println("a=", a, "b=", b)40r2.Set(1000, 2000)41a, b = r.Get()42fmt.Println("a=", a, "b=", b)43}

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2type Result struct {3}4func (r *Result) Get() string {5}6func main() {7 r := new(Result)8 fmt.Println(r.Get())9}

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful