Best Go-testdeep code snippet using td.CmpN
parse_ops.go
Source:parse_ops.go
1// Package parse contains operations for scanning the bulk data files2// and returning a list of objects derived from each file.3// Date parsing is currently deprecated in this version.4package parse5import (6 "bufio"7 "io"8 "strconv"9 "strings"10 "github.com/elections/source/donations"11)12type mapOfFields map[int]string13// ScanCandidates scans 10000 lines of a candidates file14// and returns 10000 Candidate objects per call.15func ScanCandidates(file io.ReadSeeker, start int64) ([]interface{}, int64, error) {16 offset := int64(start)17 // seek to starting byte offset18 if _, err := file.Seek(offset, 0); err != nil {19 return nil, start, err20 }21 scanner := bufio.NewScanner(file)22 fieldMap := make(mapOfFields)23 queue := []interface{}{}24 // scanLines records the byte offset in order to recover from a failure25 scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {26 advance, token, err = bufio.ScanLines(data, atEOF)27 offset += int64(advance)28 return29 }30 scanner.Split(scanLines)31 for scanner.Scan() {32 row := scanner.Text()33 // scan row and map field values34 fieldMap = scanRow(row, fieldMap)35 // create object to be stored in database36 cand := &donations.Candidate{37 ID: fieldMap[0],38 Name: fieldMap[1],39 Party: fieldMap[2],40 ElectnYr: fieldMap[3],41 OfficeState: fieldMap[4],42 Office: fieldMap[5],43 PCC: fieldMap[9],44 City: fieldMap[12],45 State: fieldMap[13],46 }47 // add donation to queue of items, stop at 25 items48 queue = append(queue, cand)49 if len(queue) == 10000 {50 break51 }52 fieldMap = make(mapOfFields)53 }54 return queue, offset, nil55}56// ScanCommittees scans 10000 lines of a committees file57// and returns 10000 Committee & corresponding CmteTxData objects per call.58func ScanCommittees(file io.ReadSeeker, start int64) ([]interface{}, []interface{}, int64, error) {59 offset := int64(start)60 // seek to starting byte offset61 if _, err := file.Seek(offset, 0); err != nil {62 return nil, nil, start, err63 }64 scanner := bufio.NewScanner(file)65 fieldMap := make(mapOfFields)66 queue := []interface{}{}67 dataQueue := []interface{}{}68 // scanLines records the byte offset in order to recover from a failure69 scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {70 advance, token, err = bufio.ScanLines(data, atEOF)71 offset += int64(advance)72 return73 }74 scanner.Split(scanLines)75 for scanner.Scan() {76 row := scanner.Text()77 // scan row and map field values78 fieldMap = scanRow(row, fieldMap)79 // create object to be stored in database80 cmte := &donations.Committee{81 ID: fieldMap[0],82 Name: fieldMap[1],83 TresName: fieldMap[2],84 City: fieldMap[5],85 State: fieldMap[6],86 Zip: fieldMap[7],87 Designation: fieldMap[8],88 Type: fieldMap[9],89 Party: fieldMap[10],90 FilingFreq: fieldMap[11],91 OrgType: fieldMap[12],92 ConnectedOrg: fieldMap[13],93 CandID: fieldMap[14],94 }95 if cmte.Party == "" {96 cmte.Party = "UNK"97 }98 // initialize corresponding CmteTxData object99 txData := &donations.CmteTxData{100 CmteID: cmte.ID,101 CandID: cmte.CandID,102 Party: cmte.Party,103 }104 // add donation to queue of items, stop at 25 items105 queue = append(queue, cmte)106 dataQueue = append(dataQueue, txData)107 if len(queue) == 10000 {108 break109 }110 fieldMap = make(mapOfFields)111 }112 return queue, dataQueue, offset, nil113}114// ScanCmpnFin scans 10000 lines of a campaing financials file115// and returns 10000 CmpnFinancials objects per call.116func ScanCmpnFin(file io.ReadSeeker, start int64) ([]interface{}, int64, error) {117 offset := start118 // seek to starting byte offset119 if _, err := file.Seek(offset, 0); err != nil {120 return nil, offset, err121 }122 scanner := bufio.NewScanner(file)123 fieldMap := make(mapOfFields)124 queue := []interface{}{}125 // scanLines records the byte offset in order to recover from a failure126 scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {127 advance, token, err = bufio.ScanLines(data, atEOF)128 offset += int64(advance)129 return130 }131 scanner.Split(scanLines)132 for scanner.Scan() {133 row := scanner.Text()134 // scan row and map field values135 fieldMap = scanRow(row, fieldMap)136 // convert non-string values from original strings137 tr, err := strconv.ParseFloat(fieldMap[5], 32)138 if err != nil {139 tr = 0140 }141 tfa, err := strconv.ParseFloat(fieldMap[6], 32)142 if err != nil {143 tfa = 0144 }145 td, err := strconv.ParseFloat(fieldMap[7], 32)146 if err != nil {147 td = 0148 }149 tta, err := strconv.ParseFloat(fieldMap[8], 32)150 if err != nil {151 tta = 0152 }153 bop, err := strconv.ParseFloat(fieldMap[9], 32)154 if err != nil {155 bop = 0156 }157 cop, err := strconv.ParseFloat(fieldMap[10], 32)158 if err != nil {159 cop = 0160 }161 cc, err := strconv.ParseFloat(fieldMap[11], 32)162 if err != nil {163 cc = 0164 }165 cl, err := strconv.ParseFloat(fieldMap[12], 32)166 if err != nil {167 cl = 0168 }169 ol, err := strconv.ParseFloat(fieldMap[13], 32)170 if err != nil {171 ol = 0172 }173 clr, err := strconv.ParseFloat(fieldMap[14], 32)174 if err != nil {175 clr = 0176 }177 olr, err := strconv.ParseFloat(fieldMap[15], 32)178 if err != nil {179 olr = 0180 }181 dob, err := strconv.ParseFloat(fieldMap[16], 32)182 if err != nil {183 dob = 0184 }185 tic, err := strconv.ParseFloat(fieldMap[17], 32)186 if err != nil {187 tic = 0188 }189 gep, err := strconv.ParseFloat(fieldMap[24], 32)190 if err != nil {191 gep = 0192 }193 pcc, err := strconv.ParseFloat(fieldMap[25], 32)194 if err != nil {195 pcc = 0196 }197 ppc, err := strconv.ParseFloat(fieldMap[26], 32)198 if err != nil {199 ppc = 0200 }201 ir, err := strconv.ParseFloat(fieldMap[28], 32)202 if err != nil {203 ir = 0204 }205 cr, err := strconv.ParseFloat(fieldMap[29], 32)206 if err != nil {207 cr = 0208 }209 // txDateFmt := "01/02/2006"210 // ced, err := time.Parse(txDateFmt, fieldMap[24])211 // if err != nil {212 // fmt.Println(err)213 // }214 // create object to be stored in database215 fin := &donations.CmpnFinancials{216 CandID: fieldMap[0],217 Name: fieldMap[1],218 PartyCd: fieldMap[3],219 Party: fieldMap[4],220 TotalReceipts: float32(tr),221 TransFrAuth: float32(tfa),222 TotalDisbsmts: float32(td),223 TransToAuth: float32(tta),224 COHBOP: float32(bop),225 COHCOP: float32(cop),226 CandConts: float32(cc),227 CandLoans: float32(cl),228 OtherLoans: float32(ol),229 CandLoanRepay: float32(clr),230 OtherLoanRepay: float32(olr),231 DebtsOwedBy: float32(dob),232 TotalIndvConts: float32(tic),233 OfficeState: fieldMap[18],234 OfficeDistrict: fieldMap[19],235 SpecElection: fieldMap[20],236 PrimElection: fieldMap[21],237 RunElection: fieldMap[22],238 GenElection: fieldMap[23],239 GenElectionPct: float32(gep),240 OtherCmteConts: float32(pcc),241 PtyConts: float32(ppc),242 IndvRefunds: float32(ir),243 CmteRefunds: float32(cr),244 // CovgEndDate: ced,245 }246 // add donation to queue of items, stop at 25 items247 queue = append(queue, fin)248 if len(queue) == 10000 {249 break250 }251 fieldMap = make(mapOfFields)252 }253 return queue, offset, nil254}255// ScanCmteFin scans 10000 lines of a committee financials file256// and returns 10000 CmteFinancials objects per call257func ScanCmteFin(file io.ReadSeeker, start int64) ([]interface{}, int64, error) {258 offset := start259 // seek to starting byte offset260 if _, err := file.Seek(offset, 0); err != nil {261 return nil, offset, err262 }263 scanner := bufio.NewScanner(file)264 fieldMap := make(mapOfFields)265 queue := []interface{}{}266 // scanLines records the byte offset in order to recover from a failure267 scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {268 advance, token, err = bufio.ScanLines(data, atEOF)269 offset += int64(advance)270 return271 }272 scanner.Split(scanLines)273 for scanner.Scan() {274 row := scanner.Text()275 // scan row and map field values276 fieldMap = scanRow(row, fieldMap)277 // convert non-string values from original strings278 tr, err := strconv.Atoi(fieldMap[5])279 if err != nil {280 tr = 0281 }282 tfa, err := strconv.Atoi(fieldMap[6])283 if err != nil {284 tfa = 0285 }286 ic, err := strconv.Atoi(fieldMap[7])287 if err != nil {288 ic = 0289 }290 oc, err := strconv.Atoi(fieldMap[8])291 if err != nil {292 oc = 0293 }294 cc, err := strconv.Atoi(fieldMap[9])295 if err != nil {296 cc = 0297 }298 tl, err := strconv.Atoi(fieldMap[10])299 if err != nil {300 tl = 0301 }302 td, err := strconv.Atoi(fieldMap[11])303 if err != nil {304 td = 0305 }306 tta, err := strconv.Atoi(fieldMap[12])307 if err != nil {308 tta = 0309 }310 ir, err := strconv.Atoi(fieldMap[13])311 if err != nil {312 ir = 0313 }314 or, err := strconv.Atoi(fieldMap[14])315 if err != nil {316 or = 0317 }318 lr, err := strconv.Atoi(fieldMap[15])319 if err != nil {320 lr = 0321 }322 cbop, err := strconv.Atoi(fieldMap[16])323 if err != nil {324 cbop = 0325 }326 ccop, err := strconv.Atoi(fieldMap[17])327 if err != nil {328 ccop = 0329 }330 do, err := strconv.Atoi(fieldMap[18])331 if err != nil {332 cc = 0333 }334 nft, err := strconv.Atoi(fieldMap[19])335 if err != nil {336 cc = 0337 }338 ctoc, err := strconv.Atoi(fieldMap[20])339 if err != nil {340 ctoc = 0341 }342 ie, err := strconv.Atoi(fieldMap[21])343 if err != nil {344 ie = 0345 }346 pe, err := strconv.Atoi(fieldMap[22])347 if err != nil {348 pe = 0349 }350 nfe, err := strconv.Atoi(fieldMap[23])351 if err != nil {352 nfe = 0353 }354 // txDateFmt := "01/02/2006"355 // ced, err := time.Parse(txDateFmt, fieldMap[24])356 // if err != nil {357 // fmt.Println(err)358 // }359 // create object to be stored in database360 fin := &donations.CmteFinancials{361 CmteID: fieldMap[0],362 Type: fieldMap[2],363 TotalReceipts: float32(tr),364 TxsFromAff: float32(tfa),365 IndvConts: float32(ic),366 OtherConts: float32(oc),367 CandCont: float32(cc),368 TotalLoans: float32(tl),369 TotalDisb: float32(td),370 TxToAff: float32(tta),371 IndvRefunds: float32(ir),372 OtherRefunds: float32(or),373 LoanRepay: float32(lr),374 CashBOP: float32(cbop),375 CashCOP: float32(ccop),376 DebtsOwed: float32(do),377 NonFedTxsRecvd: float32(nft),378 ContToOtherCmte: float32(ctoc),379 IndExp: float32(ie),380 PartyExp: float32(pe),381 NonFedSharedExp: float32(nfe),382 // CovgEndDate: ced,383 }384 // add donation to queue of items, stop at 25 items385 queue = append(queue, fin)386 if len(queue) == 10000 {387 break388 }389 fieldMap = make(mapOfFields)390 }391 return queue, offset, nil392}393// ScanContributions scans 10000 lines of a contributions file394// and returns 10000 Contribution objects per call.395func ScanContributions(year string, file io.ReadSeeker, start int64) ([]*donations.Contribution, int64, error) {396 // seek to starting byte offset397 offset := int64(start)398 if _, err := file.Seek((offset), 0); err != nil {399 return nil, start, err400 }401 scanner := bufio.NewScanner(file)402 fieldMap := make(mapOfFields)403 icQueue := []*donations.Contribution{}404 // scanLines records the byte offset in order to recover from a failure405 scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {406 advance, token, err = bufio.ScanLines(data, atEOF)407 offset += int64(advance)408 return409 }410 scanner.Split(scanLines)411 for scanner.Scan() {412 row := scanner.Text()413 // scan row and map field values414 fieldMap = scanRow(row, fieldMap)415 // convert non-string values from original strings416 /* txDateFmt := "01/02/2006"417 txDate, err := time.Parse(txDateFmt, fmtDateStr(fieldMap[13]))418 if err != nil {419 fmt.Println(err)420 fmt.Println("txID: ", fieldMap[16])421 return nil, start, fmt.Errorf("ParseContributions failed: %v", err)422 } */423 txAmt, _ := strconv.ParseFloat(fieldMap[14], 32)424 fileNum, _ := strconv.Atoi(fieldMap[17])425 subID, _ := strconv.Atoi(fieldMap[20])426 // create object to be stored in database427 donation := &donations.Contribution{428 CmteID: fieldMap[0],429 AmndtInd: fieldMap[1],430 ReportType: fieldMap[2],431 TxPGI: fieldMap[3],432 ImgNum: fieldMap[4],433 TxType: fieldMap[5],434 EntityType: fieldMap[6],435 Name: fieldMap[7],436 City: fieldMap[8],437 State: fieldMap[9],438 Zip: fieldMap[10],439 Employer: fieldMap[11],440 Occupation: fieldMap[12],441 // TxDate: txDate,442 TxAmt: float32(txAmt),443 OtherID: fieldMap[15],444 TxID: fieldMap[16],445 FileNum: fileNum,446 MemoCode: fieldMap[18],447 MemoText: fieldMap[19],448 SubID: subID,449 }450 // add donation to queue of items, stop at 25 items451 icQueue = append(icQueue, donation)452 if len(icQueue) == 100000 {453 break454 }455 fieldMap = make(mapOfFields)456 }457 return icQueue, offset, nil458}459// ScanDisbursements scans 10000 lines of a disbursements file460// and returns 10000 Disbursement objects per call.461func ScanDisbursements(year string, file io.ReadSeeker, start int64) ([]*donations.Disbursement, int64, error) {462 // seek to starting byte offset463 offset := int64(start)464 if _, err := file.Seek((offset), 0); err != nil {465 return nil, start, err466 }467 scanner := bufio.NewScanner(file)468 fieldMap := make(mapOfFields)469 dQueue := []*donations.Disbursement{}470 // scanLines records the byte offset in order to recover from a failure471 scanLines := func(data []byte, atEOF bool) (advance int, token []byte, err error) {472 advance, token, err = bufio.ScanLines(data, atEOF)473 offset += int64(advance)474 return475 }476 scanner.Split(scanLines)477 for scanner.Scan() {478 row := scanner.Text()479 // scan row and map field values480 fieldMap = scanRow(row, fieldMap)481 // convert non-string values from original strings482 /* txDateFmt := "01/02/2006"483 txDate, err := time.Parse(txDateFmt, fieldMap[12])484 if err != nil {485 fmt.Println(err)486 } */487 txAmt, _ := strconv.ParseFloat(fieldMap[13], 32)488 fileNum, _ := strconv.Atoi(fieldMap[22])489 subID, _ := strconv.Atoi(fieldMap[21])490 // create object to be stored in database491 disb := &donations.Disbursement{492 CmteID: fieldMap[0],493 Name: fieldMap[8],494 City: fieldMap[9],495 State: fieldMap[10],496 Zip: fieldMap[11],497 // TxDate: txDate,498 TxAmt: float32(txAmt),499 TxPGI: fieldMap[14],500 Purpose: fieldMap[15],501 Category: fieldMap[16],502 CategoryDesc: fieldMap[17],503 MemoTxt: fieldMap[19],504 EntityType: fieldMap[20],505 SubID: subID,506 FileNum: fileNum,507 TxID: fieldMap[23],508 BackRefTxID: fieldMap[24],509 }510 // add donation to queue of items, stop at 25 items511 dQueue = append(dQueue, disb)512 if len(dQueue) == 100000 {513 break514 }515 fieldMap = make(mapOfFields)516 }517 return dQueue, offset, nil518}519// Utility funcs520func scanRow(row string, m map[int]string) map[int]string {521 scanner := bufio.NewScanner(strings.NewReader(row))522 scanner.Split(rowSplit)523 i := 0524 for scanner.Scan() {525 m[i] = scanner.Text()526 i++527 }528 return m529}530func rowSplit(data []byte, atEOF bool) (advance int, token []byte, err error) {531 // Return nothing if at end of file and no data passed532 if atEOF && len(data) == 0 {533 return 0, nil, nil534 }535 // Find the index of the input of a "|"536 if i := strings.Index(string(data), "|"); i >= 0 {537 return i + 1, data[0:i], nil538 }539 // If at end of file with data return the data540 if atEOF {541 return len(data), data, nil542 }543 return544}545func fmtDateStr(date string) string {546 newFmt := ""547 for i, c := range date {548 newFmt = newFmt + string(c)549 if i == 1 || i == 3 {550 newFmt = newFmt + "/"551 }552 }553 return newFmt554}...
td_compat.go
Source:td_compat.go
...40// CmpFalse is a deprecated alias of [td.CmpFalse].41var CmpFalse = td.CmpFalse42// CmpError is a deprecated alias of [td.CmpError].43var CmpError = td.CmpError44// CmpNoError is a deprecated alias of [td.CmpNoError].45var CmpNoError = td.CmpNoError46// CmpPanic is a deprecated alias of [td.CmpPanic].47var CmpPanic = td.CmpPanic48// CmpNotPanic is a deprecated alias of [td.CmpNotPanic].49var CmpNotPanic = td.CmpNotPanic50// EqDeeply is a deprecated alias of [td.EqDeeply].51var EqDeeply = td.EqDeeply52// EqDeeplyError is a deprecated alias of [td.EqDeeplyError].53var EqDeeplyError = td.EqDeeplyError54// AddAnchorableStructType is a deprecated alias of [td.AddAnchorableStructType].55var AddAnchorableStructType = td.AddAnchorableStructType56// NewT is a deprecated alias of [td.NewT].57var NewT = td.NewT58// Assert is a deprecated alias of [td.Assert].59var Assert = td.Assert60// Require is a deprecated alias of [td.Require].61var Require = td.Require62// AssertRequire is a deprecated alias of [td.AssertRequire].63var AssertRequire = td.AssertRequire64// CmpAll is a deprecated alias of [td.CmpAll].65var CmpAll = td.CmpAll66// CmpAny is a deprecated alias of [td.CmpAny].67var CmpAny = td.CmpAny68// CmpArray is a deprecated alias of [td.CmpArray].69var CmpArray = td.CmpArray70// CmpArrayEach is a deprecated alias of [td.CmpArrayEach].71var CmpArrayEach = td.CmpArrayEach72// CmpBag is a deprecated alias of [td.CmpBag].73var CmpBag = td.CmpBag74// CmpBetween is a deprecated alias of [td.CmpBetween].75var CmpBetween = td.CmpBetween76// CmpCap is a deprecated alias of [td.CmpCap].77var CmpCap = td.CmpCap78// CmpCode is a deprecated alias of [td.CmpCode].79var CmpCode = td.CmpCode80// CmpContains is a deprecated alias of [td.CmpContains].81var CmpContains = td.CmpContains82// CmpContainsKey is a deprecated alias of [td.CmpContainsKey].83var CmpContainsKey = td.CmpContainsKey84// CmpEmpty is a deprecated alias of [td.CmpEmpty].85var CmpEmpty = td.CmpEmpty86// CmpGt is a deprecated alias of [td.CmpGt].87var CmpGt = td.CmpGt88// CmpGte is a deprecated alias of [td.CmpGte].89var CmpGte = td.CmpGte90// CmpHasPrefix is a deprecated alias of [td.CmpHasPrefix].91var CmpHasPrefix = td.CmpHasPrefix92// CmpHasSuffix is a deprecated alias of [td.CmpHasSuffix].93var CmpHasSuffix = td.CmpHasSuffix94// CmpIsa is a deprecated alias of [td.CmpIsa].95var CmpIsa = td.CmpIsa96// CmpJSON is a deprecated alias of [td.CmpJSON].97var CmpJSON = td.CmpJSON98// CmpKeys is a deprecated alias of [td.CmpKeys].99var CmpKeys = td.CmpKeys100// CmpLax is a deprecated alias of [td.CmpLax].101var CmpLax = td.CmpLax102// CmpLen is a deprecated alias of [td.CmpLen].103var CmpLen = td.CmpLen104// CmpLt is a deprecated alias of [td.CmpLt].105var CmpLt = td.CmpLt106// CmpLte is a deprecated alias of [td.CmpLte].107var CmpLte = td.CmpLte108// CmpMap is a deprecated alias of [td.CmpMap].109var CmpMap = td.CmpMap110// CmpMapEach is a deprecated alias of [td.CmpMapEach].111var CmpMapEach = td.CmpMapEach112// CmpN is a deprecated alias of [td.CmpN].113var CmpN = td.CmpN114// CmpNaN is a deprecated alias of [td.CmpNaN].115var CmpNaN = td.CmpNaN116// CmpNil is a deprecated alias of [td.CmpNil].117var CmpNil = td.CmpNil118// CmpNone is a deprecated alias of [td.CmpNone].119var CmpNone = td.CmpNone120// CmpNot is a deprecated alias of [td.CmpNot].121var CmpNot = td.CmpNot122// CmpNotAny is a deprecated alias of [td.CmpNotAny].123var CmpNotAny = td.CmpNotAny124// CmpNotEmpty is a deprecated alias of [td.CmpNotEmpty].125var CmpNotEmpty = td.CmpNotEmpty126// CmpNotNaN is a deprecated alias of [td.CmpNotNaN].127var CmpNotNaN = td.CmpNotNaN128// CmpNotNil is a deprecated alias of [td.CmpNotNil].129var CmpNotNil = td.CmpNotNil130// CmpNotZero is a deprecated alias of [td.CmpNotZero].131var CmpNotZero = td.CmpNotZero132// CmpPPtr is a deprecated alias of [td.CmpPPtr].133var CmpPPtr = td.CmpPPtr134// CmpPtr is a deprecated alias of [td.CmpPtr].135var CmpPtr = td.CmpPtr136// CmpRe is a deprecated alias of [td.CmpRe].137var CmpRe = td.CmpRe138// CmpReAll is a deprecated alias of [td.CmpReAll].139var CmpReAll = td.CmpReAll140// CmpSet is a deprecated alias of [td.CmpSet].141var CmpSet = td.CmpSet142// CmpShallow is a deprecated alias of [td.CmpShallow].143var CmpShallow = td.CmpShallow144// CmpSlice is a deprecated alias of [td.CmpSlice].145var CmpSlice = td.CmpSlice...
td_compat_test.go
Source:td_compat_test.go
...26 td.CmpDeeply(t, 1, 1)27 td.CmpTrue(t, true)28 td.CmpFalse(t, false)29 td.CmpError(t, errors.New("Error"))30 td.CmpNoError(t, nil)31 td.CmpPanic(t, func() { panic("boom!") }, "boom!")32 td.CmpNotPanic(t, func() {})33 td.CmpTrue(t, td.EqDeeply(1, 1))34 td.CmpNoError(t, td.EqDeeplyError(1, 1))35 })36 td.AddAnchorableStructType(func(nextAnchor int) MyStruct {37 return MyStruct{Num: 999999999 - int64(nextAnchor)}38 })39 tt.Run("td.T", func(tt *testing.T) {40 t := td.NewT(tt)41 t.Cmp(1, 1)42 assert := td.Assert(tt)43 assert.Cmp(1, 1)44 require := td.Require(tt)45 require.Cmp(1, 1)46 assert, require = td.AssertRequire(tt)47 assert.Cmp(1, 1)48 require.Cmp(1, 1)49 })50 tt.Run("All", func(t *testing.T) {51 td.Cmp(t, 1, td.All(1))52 td.CmpAll(t, 1, []any{1})53 })54 tt.Run("Any", func(t *testing.T) {55 td.Cmp(t, 1, td.Any(3, 2, 1))56 td.CmpAny(t, 1, []any{3, 2, 1})57 })58 tt.Run("Array", func(t *testing.T) {59 td.Cmp(t, [2]int{1, 2}, td.Array([2]int{}, td.ArrayEntries{0: 1, 1: 2}))60 td.CmpArray(t, [2]int{1, 2}, [2]int{}, td.ArrayEntries{0: 1, 1: 2})61 })62 tt.Run("ArrayEach", func(t *testing.T) {63 got := []int{1, 1}64 td.Cmp(t, got, td.ArrayEach(1))65 td.CmpArrayEach(t, got, 1)66 })67 tt.Run("Bag", func(t *testing.T) {68 got := []int{1, 2}69 td.Cmp(t, got, td.Bag(1, 2))70 td.CmpBag(t, got, []any{1, 2})71 })72 tt.Run("Between", func(t *testing.T) {73 for _, bounds := range []td.BoundsKind{74 td.BoundsInIn, td.BoundsInOut, td.BoundsOutIn, td.BoundsOutOut,75 } {76 td.Cmp(t, 5, td.Between(0, 10, bounds))77 td.CmpBetween(t, 5, 0, 10, bounds)78 }79 })80 tt.Run("Cap", func(t *testing.T) {81 got := make([]int, 2, 3)82 td.Cmp(t, got, td.Cap(3))83 td.CmpCap(t, got, 3)84 })85 tt.Run("Catch", func(t *testing.T) {86 var num int87 td.Cmp(t, 12, td.Catch(&num, 12))88 td.Cmp(t, num, 12)89 })90 tt.Run("Code", func(t *testing.T) {91 fn := func(n int) bool { return n == 5 }92 td.Cmp(t, 5, td.Code(fn))93 td.CmpCode(t, 5, fn)94 })95 tt.Run("Contains", func(t *testing.T) {96 td.Cmp(t, "foobar", td.Contains("ob"))97 td.CmpContains(t, "foobar", "ob")98 })99 tt.Run("ContainsKey", func(t *testing.T) {100 got := map[string]bool{"a": false}101 td.Cmp(t, got, td.ContainsKey("a"))102 td.CmpContainsKey(t, got, "a")103 })104 tt.Run("Empty", func(t *testing.T) {105 td.Cmp(t, "", td.Empty())106 td.CmpEmpty(t, "")107 })108 tt.Run("Gt", func(t *testing.T) {109 td.Cmp(t, 5, td.Gt(3))110 td.CmpGt(t, 5, 3)111 })112 tt.Run("Gte", func(t *testing.T) {113 td.Cmp(t, 5, td.Gte(3))114 td.CmpGte(t, 5, 3)115 })116 tt.Run("HasPrefix", func(t *testing.T) {117 td.Cmp(t, "foobar", td.HasPrefix("foo"))118 td.CmpHasPrefix(t, "foobar", "foo")119 })120 tt.Run("HasSuffix", func(t *testing.T) {121 td.Cmp(t, "foobar", td.HasSuffix("bar"))122 td.CmpHasSuffix(t, "foobar", "bar")123 })124 td.Cmp(tt, 42, td.Ignore())125 tt.Run("Isa", func(t *testing.T) {126 td.Cmp(t, 2, td.Isa(0))127 td.CmpIsa(t, 2, 0)128 })129 tt.Run("JSON", func(t *testing.T) {130 td.Cmp(t, []int{1, 2}, td.JSON(`[1,$val]`, td.Tag("val", 2)))131 td.CmpJSON(t, []int{1, 2}, `[1,$val]`, []any{td.Tag("val", 2)})132 })133 tt.Run("Keys", func(t *testing.T) {134 got := map[string]bool{"a": false}135 td.Cmp(t, got, td.Keys([]string{"a"}))136 td.CmpKeys(t, got, []string{"a"})137 })138 tt.Run("Lax", func(t *testing.T) {139 td.Cmp(t, int64(42), td.Lax(42))140 td.CmpLax(t, int64(42), 42)141 })142 tt.Run("Len", func(t *testing.T) {143 got := make([]int, 2, 3)144 td.Cmp(t, got, td.Len(2))145 td.CmpLen(t, got, 2)146 })147 tt.Run("Lt", func(t *testing.T) {148 td.Cmp(t, 5, td.Lt(10))149 td.CmpLt(t, 5, 10)150 })151 tt.Run("Lte", func(t *testing.T) {152 td.Cmp(t, 5, td.Lte(10))153 td.CmpLte(t, 5, 10)154 })155 tt.Run("Map", func(t *testing.T) {156 got := map[string]bool{"a": false, "b": true}157 td.Cmp(t, got, td.Map(map[string]bool{"a": false}, td.MapEntries{"b": true}))158 td.CmpMap(t, got, map[string]bool{"a": false}, td.MapEntries{"b": true})159 })160 tt.Run("MapEach", func(t *testing.T) {161 got := map[string]int{"a": 1}162 td.Cmp(t, got, td.MapEach(1))163 td.CmpMapEach(t, got, 1)164 })165 tt.Run("N", func(t *testing.T) {166 td.Cmp(t, 12, td.N(10, 2))167 td.CmpN(t, 12, 10, 2)168 })169 tt.Run("NaN", func(t *testing.T) {170 td.Cmp(t, math.NaN(), td.NaN())171 td.CmpNaN(t, math.NaN())172 })173 tt.Run("Nil", func(t *testing.T) {174 td.Cmp(t, nil, td.Nil())175 td.CmpNil(t, nil)176 })177 tt.Run("None", func(t *testing.T) {178 td.Cmp(t, 28, td.None(3, 4, 5))179 td.CmpNone(t, 28, []any{3, 4, 5})180 })181 tt.Run("Not", func(t *testing.T) {182 td.Cmp(t, 28, td.Not(3))183 td.CmpNot(t, 28, 3)184 })185 tt.Run("NotAny", func(t *testing.T) {186 got := []int{5}187 td.Cmp(t, got, td.NotAny(1, 2, 3))188 td.CmpNotAny(t, got, []any{1, 2, 3})189 })190 tt.Run("NotEmpty", func(t *testing.T) {191 td.Cmp(t, "OOO", td.NotEmpty())192 td.CmpNotEmpty(t, "OOO")193 })194 tt.Run("NotNaN", func(t *testing.T) {195 td.Cmp(t, 12., td.NotNaN())196 td.CmpNotNaN(t, 12.)197 })198 tt.Run("NotNil", func(t *testing.T) {199 td.Cmp(t, 4, td.NotNil())200 td.CmpNotNil(t, 4)201 })202 tt.Run("NotZero", func(t *testing.T) {203 td.Cmp(t, 3, td.NotZero())204 td.CmpNotZero(t, 3)205 })206 tt.Run("Ptr", func(t *testing.T) {207 num := 12208 td.Cmp(t, &num, td.Ptr(12))209 td.CmpPtr(t, &num, 12)210 })211 tt.Run("PPtr", func(t *testing.T) {212 num := 12213 pnum := &num214 td.Cmp(t, &pnum, td.PPtr(12))215 td.CmpPPtr(t, &pnum, 12)216 })217 tt.Run("Re", func(t *testing.T) {218 td.Cmp(t, "foobar", td.Re(`o+`))...
CmpN
Using AI Code Generation
1import (2type td struct {3}4func (v td) Abs() float64 {5 return math.Sqrt(v.x*v.x + v.y*v.y)6}7func (v td) CmpN() float64 {8}9func main() {10 v := td{3, 4}11 fmt.Println(v.Abs())12 fmt.Println(v.CmpN())13}14This means the receiver type has the literal syntax *T for some type T. (Also, T cannot itself be a pointer such as *int.)15import "fmt"16type Vertex struct {17}18func (v *Vertex) Scale(f float64) {19}20func main() {21 v := Vertex{3, 4}22 v.Scale(10)23 fmt.Println(v.X, v.Y)24}25With a value receiver, the Scale method operates on a copy of the original Vertex value. (This is the same behavior as for any other
CmpN
Using AI Code Generation
1import "fmt"2func main() {3 t1 := td{1, 2, 3}4 t2 := td{1, 2, 3}5 t3 := td{1, 2, 4}6}
CmpN
Using AI Code Generation
1import "fmt"2import "td"3func main() {4 a.Set(1, 2, 3)5 b.Set(1, 2, 3)6 if a.CmpN(b) {7 fmt.Println("a and b are equal")8 } else {9 fmt.Println("a and b are not equal")10 }11}12❖ func New(h, m, s int) Td13func (t *Td) CmpN ¶ Uses14❖ func (t *Td) CmpN(t2 Td) bool15func (t *Td) Set ¶ Uses16❖ func (t *Td) Set(h, m, s int)
CmpN
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Print("Enter two numbers: ")4 fmt.Scan(&x, &y)5 z = td.CmpN(x, y)6 fmt.Println("The largest number is", z)7}8import "fmt"9func main() {10 fmt.Print("Enter two numbers: ")11 fmt.Scan(&x, &y)12 z = td.CmpN(x, y)13 fmt.Println("The largest number is", z)14}15import "fmt"16func main() {17 fmt.Print("Enter two numbers: ")18 fmt.Scan(&x, &y)19 z = td.CmpN(x, y)20 fmt.Println("The largest number is", z)21}22import "fmt"23func main() {24 fmt.Print("Enter two numbers: ")25 fmt.Scan(&x, &y)26 z = td.CmpN(x, y)27 fmt.Println("The largest number is", z)28}29import "fmt"30func main() {31 fmt.Print("Enter two numbers: ")32 fmt.Scan(&x, &y)33 z = td.CmpN(x, y)34 fmt.Println("The largest number is", z)35}36import "fmt"37func main() {38 fmt.Print("Enter two numbers: ")39 fmt.Scan(&x, &y)40 z = td.CmpN(x, y)41 fmt.Println("The largest number is", z)42}
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!!