How to use newArray method of td Package

Best Go-testdeep code snippet using td.newArray

dto.go

Source:dto.go Github

copy

Full Screen

...770 set[i] = true771 }772 }773 if len(td.Base) > 0 {774 var newArray []*TradeDataBasic775 for i, d := range td.Base {776 if _, ok := set[i]; !ok {777 newArray = append(newArray, d)778 }779 }780 td.Base = newArray781 }782 if len(td.LogRtn) > 0 {783 var newArray []*TradeDataLogRtn784 for i, d := range td.LogRtn {785 if _, ok := set[i]; !ok {786 newArray = append(newArray, d)787 }788 }789 td.LogRtn = newArray790 }791 if len(td.MovAvgLogRtn) > 0 {792 var newArray []*TradeDataMovAvgLogRtn793 for i, d := range td.MovAvgLogRtn {794 if _, ok := set[i]; !ok {795 newArray = append(newArray, d)796 }797 }798 td.MovAvgLogRtn = newArray799 }800 if len(td.MovAvg) > 0 {801 var newArray []*TradeDataMovAvg802 for i, d := range td.MovAvg {803 if _, ok := set[i]; !ok {804 newArray = append(newArray, d)805 }806 }807 td.MovAvg = newArray808 }809}810//Keep the specified elements in the trade data arrays.811//***Warning***: Calling Keep with empty array will remove all elements.812func (td *TradeData) Keep(positions ...int) {813 if len(positions) == 0 {814 td.Base = make([]*TradeDataBasic, 0, 16)815 td.MovAvg = make([]*TradeDataMovAvg, 0, 16)816 td.MovAvgLogRtn = make([]*TradeDataMovAvgLogRtn, 0, 16)817 td.LogRtn = make([]*TradeDataLogRtn, 0, 16)818 return819 }820 maxLen := td.MaxLen()821 set := make(map[int]bool)822 for i := range positions {823 if 0 <= i && i < maxLen {824 set[i] = true825 }826 }827 if len(td.Base) > 0 {828 var newArray []*TradeDataBasic829 for i, d := range td.Base {830 if _, ok := set[i]; ok {831 newArray = append(newArray, d)832 }833 }834 td.Base = newArray835 }836 if len(td.LogRtn) > 0 {837 var newArray []*TradeDataLogRtn838 for i, d := range td.LogRtn {839 if _, ok := set[i]; ok {840 newArray = append(newArray, d)841 }842 }843 td.LogRtn = newArray844 }845 if len(td.MovAvgLogRtn) > 0 {846 var newArray []*TradeDataMovAvgLogRtn847 for i, d := range td.MovAvgLogRtn {848 if _, ok := set[i]; ok {849 newArray = append(newArray, d)850 }851 }852 td.MovAvgLogRtn = newArray853 }854 if len(td.MovAvg) > 0 {855 var newArray []*TradeDataMovAvg856 for i, d := range td.MovAvg {857 if _, ok := set[i]; ok {858 newArray = append(newArray, d)859 }860 }861 td.MovAvg = newArray862 }863}864//GetDates of any of the series.865func (td *TradeData) GetDates() (dates []string) {866 if len(td.Base) > 0 {867 for _, d := range td.Base {868 dates = append(dates, d.Date)869 }870 return871 } else if len(td.MovAvg) > 0 {872 for _, d := range td.MovAvg {873 dates = append(dates, d.Date)874 }875 return...

Full Screen

Full Screen

heroes.go

Source:heroes.go Github

copy

Full Screen

1package spider23import (4 "dotaapi/app/model/heroes"5 heroService "dotaapi/app/service/heroes"6 "encoding/json"7 "fmt"8 "regexp"9 "strings"10 "sync"1112 "github.com/PuerkitoBio/goquery"13 "github.com/gogf/gf/container/garray"14 "github.com/gogf/gf/container/gmap"15 "github.com/gogf/gf/frame/g"16)1718//GetHeroInfo 获取英雄头像,图片,技能等数据19func GetHeroInfo() {20 // data, _ := g.Redis().DoVar("GET", keyHeroesInfo)21 // if data.String() != "" {22 // return23 // }24 s := heroService.GetHeroes()25 m := make(map[string]*heroes.Entity)26 for _, v := range s {27 m[v.Name] = v28 }29 //图片数据30 spider := Spider{URL: maxBaseURL + "hero/rate/"}31 doc := spider.GetDoc()3233 heroItemMaps := gmap.New(true)34 var wg sync.WaitGroup3536 //获取头像 胜率 使用场次37 doc.Find(".table-list tbody tr").Each(func(i int, s *goquery.Selection) {38 wg.Add(1)39 heroItemMap := make(map[string]string)40 name := ""41 s.Find("td").Each(func(i int, td *goquery.Selection) {4243 //头像44 if i == 0 {45 src, _ := td.Find(".hero-img-list").First().Attr("src")46 heroItemMap["src"] = src47 name = strings.TrimPrefix(src, "http://cdn.dota2.com/apps/dota2/images/heroes/")48 name = strings.TrimSuffix(name, "_hphover.png")49 }50 //胜率51 if i == 1 {52 heroItemMap["winRate"] = td.Find("div").First().Text()53 }54 //场次55 if i == 2 {56 heroItemMap["counts"] = td.Find("div").First().Text()57 }58 })59 if m[name] == nil {60 go func(name string) {61 fmt.Println(name)62 wg.Done()63 }(name)64 } else {65 //英雄详情页面66 go func(name string, ID float64) {67 heroItemMap["talents"], heroItemMap["ability"] = parseHeroInfo(name, m[name].ID)68 heroItemMaps.Set(m[name].ID, heroItemMap)69 wg.Done()70 }(name, m[name].ID)71 }72 })73 wg.Wait()74 herosJSON, _ := json.Marshal(heroItemMaps)75 g.Redis().DoVar("SET", keyHeroesInfo, string(herosJSON))76 fmt.Println("sync heroes info down")77}7879func parseHeroInfo(heroName string, ID float64) (string, string) {80 spider := Spider{URL: maxBaseURL + "hero/detail/" + heroName + "/"}81 doc := spider.GetDoc()82 talents := gmap.New()83 //天赋84 doc.Find(".talent_self").Each(func(i int, s *goquery.Selection) {85 left := strings.TrimSpace(s.Find(".talent_text_left").First().Text())86 right := strings.TrimSpace(s.Find(".talent_text_right").First().Text())87 talents.Set(10+i*5, left+","+right)88 })89 talentsJSON, _ := json.Marshal(talents)9091 abilityArray := garray.NewArray()92 ability := gmap.New()93 //技能94 doc.Find("#accordion>div").Each(func(i int, s *goquery.Selection) {95 if i > 3 {96 if i%2 == 0 {97 ability.Set("name", strings.TrimSpace(s.Text()))98 src, _ := s.Find("img").First().Attr("src")99 ability.Set("img", src)100 } else {101 abilitieInfos := garray.NewArray(true)102 //ability desc103 ability.Set("desc", s.Children().First().Text())104 //ability info105 abilitieInfos.Append(map[string]string{106 "label": "mana",107 "value": s.Find(".mana").First().Text(),108 })109110 abilitieInfos.Append(map[string]string{111 "label": "cooldown",112 "value": s.Find(".cooldown").First().Text(),113 })114115 html, _ := s.Html()116 reg := regexp.MustCompile(`<br/>(?s:(.*?))<span class="attribVal">(?s:(.*?))</span>`)117 if reg != nil {118 result := reg.FindAllStringSubmatch(html, -1)119 for _, text := range result {120 reg, _ = regexp.Compile("\\<[\\S\\s]+?\\>")121 text[2] = reg.ReplaceAllString(text[2], "")122 abilitieInfos.Append(map[string]string{123 "label": strings.TrimSpace(text[1]),124 "value": strings.TrimSpace(text[2]),125 })126 }127 ability.Set("abilitieInfos", abilitieInfos)128 abilityArray.Append(ability)129 }130 ability = gmap.New()131 }132 }133 })134 abilityJSON, _ := json.Marshal(abilityArray)135 //g.Dump(string(abilityJSON))136 return string(talentsJSON), string(abilityJSON)137138} ...

Full Screen

Full Screen

newArray

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 for i := 0; i < 5; i++ {4 }5 fmt.Println(total / 5)6}7import "fmt"8func main() {9 x := [5]float64{10 }11 for i := 0; i < 5; i++ {12 }13 fmt.Println(total / 5)14}15import "fmt"16func main() {17 x := [5]float64{18 }19 for _, value := range x {20 }21 fmt.Println(total / float64(len(x)))22}23import "fmt"24func main() {25 x := make([]float64, 5, 10)26 fmt.Println(x)27}28import "fmt"29func main() {30 x := make([]float64, 5, 10)31 fmt.Println(x)32 fmt.Println(len(x))33 fmt.Println(cap(x))34}35import "fmt"36func main() {37 x := make([]float64, 5, 10)

Full Screen

Full Screen

newArray

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func (t td) newArray() {5 fmt.Println(arr)6}7func (t td) newSlice() {8 slc := make([]int, 0, 3)9 slc = append(slc, 1)10 slc = append(slc, 2)11 slc = append(slc, 3)12 fmt.Println(slc)13}14func (t td) newMap() {15 m := make(map[string]int)16 fmt.Println(m)17}18func (t td) newStruct() {19 type st struct {20 }21 s := st{a: 1, b: 2, c: 3}22 fmt.Println(s)23}24func (t td) newInterface() {25 var i interface{}26 fmt.Println(i)27}28func (t td) newChan() {29 ch := make(chan int, 3)30 close(ch)31 fmt.Println(<-ch)32 fmt.Println(<-ch)33 fmt.Println(<-ch)34}35func (t td) newFunc() {36 f := func() {37 fmt.Println("hello")38 }39 f()40}41func (t td) newPtr() {42 fmt.Println(*p)43}44func main() {45 t := td{}46 t.newArray()47 t.newSlice()48 t.newMap()49 t.newStruct()50 t.newInterface()51 t.newChan()52 t.newFunc()53 t.newPtr()54}55{1 2

Full Screen

Full Screen

newArray

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td.newArray()4}5import (6type testdata struct {7}8func (td testdata) newArray() {9 fmt.Println(array)10}

Full Screen

Full Screen

newArray

Using AI Code Generation

copy

Full Screen

1import(2func main(){3 fmt.Println(a)4 fmt.Println(reflect.TypeOf(a))5 b := reflect.TypeOf(a)6 fmt.Println(b)7 c := b.New()8 fmt.Println(c)9 fmt.Println(reflect.TypeOf(c))10 fmt.Println(c.Kind())11 fmt.Println(c.Len())12}13import(14func main(){15 fmt.Println(a)16 fmt.Println(reflect.TypeOf(a))17 b := reflect.TypeOf(a)18 fmt.Println(b)19 c := reflect.ArrayOf(5, reflect.TypeOf(a))20 fmt.Println(c)21 fmt.Println(reflect.TypeOf(c))22 fmt.Println(c.Kind())23 fmt.Println(c.Len())24}25import(26func main(){27 fmt.Println(a)28 fmt.Println(reflect.TypeOf(a))29 b := reflect.TypeOf(a)30 fmt.Println(b)31 c := reflect.ArrayOf(5, reflect.TypeOf(a))32 fmt.Println(c)33 fmt.Println(reflect.TypeOf(c))34 fmt.Println(c.Kind())35 fmt.Println(c.Len())36 d := reflect.MakeSlice(c, 0, 0)37 fmt.Println(d)38 fmt.Println(d.Kind())39 fmt.Println(d.Len())40 fmt.Println(d.Cap())41}42import(43func main(){44 fmt.Println(a)45 fmt.Println(reflect.TypeOf(a))46 b := reflect.TypeOf(a

Full Screen

Full Screen

newArray

Using AI Code Generation

copy

Full Screen

1 td := new(td)2 td.newArray(2,2)3 td.printArray()4import (5type td struct {6}7func (td *td) newArray(row, column int) {8 td.array = make([][]int, row)9 for i := range td.array {10 td.array[i] = make([]int, column)11 }12}13func (td *td) printArray() {14 for i := range td.array {15 fmt.Println(td.array[i])16 }17}

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run Go-testdeep automation tests on LambdaTest cloud grid

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

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful