How to use New method of data Package

Best K6 code snippet using data.New

codec_test.go

Source:codec_test.go Github

copy

Full Screen

...295 instr.op(instr, state, decIndirect(p, instr.indir))296 state.fieldnum = 6297}298func newDecodeStateFromData(data []byte) *decoderState {299 b := bytes.NewBuffer(data)300 state := newDecodeState(b)301 state.fieldnum = -1302 return state303}304// Test instruction execution for decoding.305// Do not run the machine yet; instead do individual instructions crafted by hand.306func TestScalarDecInstructions(t *testing.T) {307 ovfl := errors.New("overflow")308 // bool309 {310 var data struct {311 a bool312 }313 instr := &decInstr{decBool, 6, 0, 0, ovfl}314 state := newDecodeStateFromData(boolResult)315 execDec("bool", instr, state, t, unsafe.Pointer(&data))316 if data.a != true {317 t.Errorf("bool a = %v not true", data.a)318 }319 }320 // int321 {322 var data struct {323 a int324 }325 instr := &decInstr{decOpTable[reflect.Int], 6, 0, 0, ovfl}326 state := newDecodeStateFromData(signedResult)327 execDec("int", instr, state, t, unsafe.Pointer(&data))328 if data.a != 17 {329 t.Errorf("int a = %v not 17", data.a)330 }331 }332 // uint333 {334 var data struct {335 a uint336 }337 instr := &decInstr{decOpTable[reflect.Uint], 6, 0, 0, ovfl}338 state := newDecodeStateFromData(unsignedResult)339 execDec("uint", instr, state, t, unsafe.Pointer(&data))340 if data.a != 17 {341 t.Errorf("uint a = %v not 17", data.a)342 }343 }344 // int8345 {346 var data struct {347 a int8348 }349 instr := &decInstr{decInt8, 6, 0, 0, ovfl}350 state := newDecodeStateFromData(signedResult)351 execDec("int8", instr, state, t, unsafe.Pointer(&data))352 if data.a != 17 {353 t.Errorf("int8 a = %v not 17", data.a)354 }355 }356 // uint8357 {358 var data struct {359 a uint8360 }361 instr := &decInstr{decUint8, 6, 0, 0, ovfl}362 state := newDecodeStateFromData(unsignedResult)363 execDec("uint8", instr, state, t, unsafe.Pointer(&data))364 if data.a != 17 {365 t.Errorf("uint8 a = %v not 17", data.a)366 }367 }368 // int16369 {370 var data struct {371 a int16372 }373 instr := &decInstr{decInt16, 6, 0, 0, ovfl}374 state := newDecodeStateFromData(signedResult)375 execDec("int16", instr, state, t, unsafe.Pointer(&data))376 if data.a != 17 {377 t.Errorf("int16 a = %v not 17", data.a)378 }379 }380 // uint16381 {382 var data struct {383 a uint16384 }385 instr := &decInstr{decUint16, 6, 0, 0, ovfl}386 state := newDecodeStateFromData(unsignedResult)387 execDec("uint16", instr, state, t, unsafe.Pointer(&data))388 if data.a != 17 {389 t.Errorf("uint16 a = %v not 17", data.a)390 }391 }392 // int32393 {394 var data struct {395 a int32396 }397 instr := &decInstr{decInt32, 6, 0, 0, ovfl}398 state := newDecodeStateFromData(signedResult)399 execDec("int32", instr, state, t, unsafe.Pointer(&data))400 if data.a != 17 {401 t.Errorf("int32 a = %v not 17", data.a)402 }403 }404 // uint32405 {406 var data struct {407 a uint32408 }409 instr := &decInstr{decUint32, 6, 0, 0, ovfl}410 state := newDecodeStateFromData(unsignedResult)411 execDec("uint32", instr, state, t, unsafe.Pointer(&data))412 if data.a != 17 {413 t.Errorf("uint32 a = %v not 17", data.a)414 }415 }416 // uintptr417 {418 var data struct {419 a uintptr420 }421 instr := &decInstr{decOpTable[reflect.Uintptr], 6, 0, 0, ovfl}422 state := newDecodeStateFromData(unsignedResult)423 execDec("uintptr", instr, state, t, unsafe.Pointer(&data))424 if data.a != 17 {425 t.Errorf("uintptr a = %v not 17", data.a)426 }427 }428 // int64429 {430 var data struct {431 a int64432 }433 instr := &decInstr{decInt64, 6, 0, 0, ovfl}434 state := newDecodeStateFromData(signedResult)435 execDec("int64", instr, state, t, unsafe.Pointer(&data))436 if data.a != 17 {437 t.Errorf("int64 a = %v not 17", data.a)438 }439 }440 // uint64441 {442 var data struct {443 a uint64444 }445 instr := &decInstr{decUint64, 6, 0, 0, ovfl}446 state := newDecodeStateFromData(unsignedResult)447 execDec("uint64", instr, state, t, unsafe.Pointer(&data))448 if data.a != 17 {449 t.Errorf("uint64 a = %v not 17", data.a)450 }451 }452 // float32453 {454 var data struct {455 a float32456 }457 instr := &decInstr{decFloat32, 6, 0, 0, ovfl}458 state := newDecodeStateFromData(floatResult)459 execDec("float32", instr, state, t, unsafe.Pointer(&data))460 if data.a != 17 {461 t.Errorf("float32 a = %v not 17", data.a)462 }463 }464 // float64465 {466 var data struct {467 a float64468 }469 instr := &decInstr{decFloat64, 6, 0, 0, ovfl}470 state := newDecodeStateFromData(floatResult)471 execDec("float64", instr, state, t, unsafe.Pointer(&data))472 if data.a != 17 {473 t.Errorf("float64 a = %v not 17", data.a)474 }475 }476 // complex64477 {478 var data struct {479 a complex64480 }481 instr := &decInstr{decOpTable[reflect.Complex64], 6, 0, 0, ovfl}482 state := newDecodeStateFromData(complexResult)483 execDec("complex", instr, state, t, unsafe.Pointer(&data))484 if data.a != 17+19i {485 t.Errorf("complex a = %v not 17+19i", data.a)486 }487 }488 // complex128489 {490 var data struct {491 a complex128492 }493 instr := &decInstr{decOpTable[reflect.Complex128], 6, 0, 0, ovfl}494 state := newDecodeStateFromData(complexResult)495 execDec("complex", instr, state, t, unsafe.Pointer(&data))496 if data.a != 17+19i {497 t.Errorf("complex a = %v not 17+19i", data.a)498 }499 }500 // bytes == []uint8501 {502 var data struct {503 a []byte504 }505 instr := &decInstr{decUint8Slice, 6, 0, 0, ovfl}506 state := newDecodeStateFromData(bytesResult)507 execDec("bytes", instr, state, t, unsafe.Pointer(&data))508 if string(data.a) != "hello" {509 t.Errorf(`bytes a = %q not "hello"`, string(data.a))510 }511 }512 // string513 {514 var data struct {515 a string516 }517 instr := &decInstr{decString, 6, 0, 0, ovfl}518 state := newDecodeStateFromData(bytesResult)519 execDec("bytes", instr, state, t, unsafe.Pointer(&data))520 if data.a != "hello" {521 t.Errorf(`bytes a = %q not "hello"`, data.a)522 }523 }524}525func TestEndToEnd(t *testing.T) {526 type T2 struct {527 T string528 }529 s1 := "string1"530 s2 := "string2"531 type T1 struct {532 A, B, C int533 M map[string]*float64534 EmptyMap map[string]int // to check that we receive a non-nil map.535 N *[3]float64536 Strs *[2]string537 Int64s *[]int64538 RI complex64539 S string540 Y []byte541 T *T2542 }543 pi := 3.14159544 e := 2.71828545 t1 := &T1{546 A: 17,547 B: 18,548 C: -5,549 M: map[string]*float64{"pi": &pi, "e": &e},550 EmptyMap: make(map[string]int),551 N: &[3]float64{1.5, 2.5, 3.5},552 Strs: &[2]string{s1, s2},553 Int64s: &[]int64{77, 89, 123412342134},554 RI: 17 - 23i,555 S: "Now is the time",556 Y: []byte("hello, sailor"),557 T: &T2{"this is T2"},558 }559 b := new(bytes.Buffer)560 err := NewEncoder(b).Encode(t1)561 if err != nil {562 t.Error("encode:", err)563 }564 var _t1 T1565 err = NewDecoder(b).Decode(&_t1)566 if err != nil {567 t.Fatal("decode:", err)568 }569 if !reflect.DeepEqual(t1, &_t1) {570 t.Errorf("encode expected %v got %v", *t1, _t1)571 }572 // Be absolutely sure the received map is non-nil.573 if t1.EmptyMap == nil {574 t.Errorf("nil map sent")575 }576 if _t1.EmptyMap == nil {577 t.Errorf("nil map received")578 }579}580func TestOverflow(t *testing.T) {581 type inputT struct {582 Maxi int64583 Mini int64584 Maxu uint64585 Maxf float64586 Minf float64587 Maxc complex128588 Minc complex128589 }590 var it inputT591 var err error592 b := new(bytes.Buffer)593 enc := NewEncoder(b)594 dec := NewDecoder(b)595 // int8596 b.Reset()597 it = inputT{598 Maxi: math.MaxInt8 + 1,599 }600 type outi8 struct {601 Maxi int8602 Mini int8603 }604 var o1 outi8605 enc.Encode(it)606 err = dec.Decode(&o1)607 if err == nil || err.Error() != `value for "Maxi" out of range` {608 t.Error("wrong overflow error for int8:", err)609 }610 it = inputT{611 Mini: math.MinInt8 - 1,612 }613 b.Reset()614 enc.Encode(it)615 err = dec.Decode(&o1)616 if err == nil || err.Error() != `value for "Mini" out of range` {617 t.Error("wrong underflow error for int8:", err)618 }619 // int16620 b.Reset()621 it = inputT{622 Maxi: math.MaxInt16 + 1,623 }624 type outi16 struct {625 Maxi int16626 Mini int16627 }628 var o2 outi16629 enc.Encode(it)630 err = dec.Decode(&o2)631 if err == nil || err.Error() != `value for "Maxi" out of range` {632 t.Error("wrong overflow error for int16:", err)633 }634 it = inputT{635 Mini: math.MinInt16 - 1,636 }637 b.Reset()638 enc.Encode(it)639 err = dec.Decode(&o2)640 if err == nil || err.Error() != `value for "Mini" out of range` {641 t.Error("wrong underflow error for int16:", err)642 }643 // int32644 b.Reset()645 it = inputT{646 Maxi: math.MaxInt32 + 1,647 }648 type outi32 struct {649 Maxi int32650 Mini int32651 }652 var o3 outi32653 enc.Encode(it)654 err = dec.Decode(&o3)655 if err == nil || err.Error() != `value for "Maxi" out of range` {656 t.Error("wrong overflow error for int32:", err)657 }658 it = inputT{659 Mini: math.MinInt32 - 1,660 }661 b.Reset()662 enc.Encode(it)663 err = dec.Decode(&o3)664 if err == nil || err.Error() != `value for "Mini" out of range` {665 t.Error("wrong underflow error for int32:", err)666 }667 // uint8668 b.Reset()669 it = inputT{670 Maxu: math.MaxUint8 + 1,671 }672 type outu8 struct {673 Maxu uint8674 }675 var o4 outu8676 enc.Encode(it)677 err = dec.Decode(&o4)678 if err == nil || err.Error() != `value for "Maxu" out of range` {679 t.Error("wrong overflow error for uint8:", err)680 }681 // uint16682 b.Reset()683 it = inputT{684 Maxu: math.MaxUint16 + 1,685 }686 type outu16 struct {687 Maxu uint16688 }689 var o5 outu16690 enc.Encode(it)691 err = dec.Decode(&o5)692 if err == nil || err.Error() != `value for "Maxu" out of range` {693 t.Error("wrong overflow error for uint16:", err)694 }695 // uint32696 b.Reset()697 it = inputT{698 Maxu: math.MaxUint32 + 1,699 }700 type outu32 struct {701 Maxu uint32702 }703 var o6 outu32704 enc.Encode(it)705 err = dec.Decode(&o6)706 if err == nil || err.Error() != `value for "Maxu" out of range` {707 t.Error("wrong overflow error for uint32:", err)708 }709 // float32710 b.Reset()711 it = inputT{712 Maxf: math.MaxFloat32 * 2,713 }714 type outf32 struct {715 Maxf float32716 Minf float32717 }718 var o7 outf32719 enc.Encode(it)720 err = dec.Decode(&o7)721 if err == nil || err.Error() != `value for "Maxf" out of range` {722 t.Error("wrong overflow error for float32:", err)723 }724 // complex64725 b.Reset()726 it = inputT{727 Maxc: complex(math.MaxFloat32*2, math.MaxFloat32*2),728 }729 type outc64 struct {730 Maxc complex64731 Minc complex64732 }733 var o8 outc64734 enc.Encode(it)735 err = dec.Decode(&o8)736 if err == nil || err.Error() != `value for "Maxc" out of range` {737 t.Error("wrong overflow error for complex64:", err)738 }739}740func TestNesting(t *testing.T) {741 type RT struct {742 A string743 Next *RT744 }745 rt := new(RT)746 rt.A = "level1"747 rt.Next = new(RT)748 rt.Next.A = "level2"749 b := new(bytes.Buffer)750 NewEncoder(b).Encode(rt)751 var drt RT752 dec := NewDecoder(b)753 err := dec.Decode(&drt)754 if err != nil {755 t.Fatal("decoder error:", err)756 }757 if drt.A != rt.A {758 t.Errorf("nesting: encode expected %v got %v", *rt, drt)759 }760 if drt.Next == nil {761 t.Errorf("nesting: recursion failed")762 }763 if drt.Next.A != rt.Next.A {764 t.Errorf("nesting: encode expected %v got %v", *rt.Next, *drt.Next)765 }766}767// These three structures have the same data with different indirections768type T0 struct {769 A int770 B int771 C int772 D int773}774type T1 struct {775 A int776 B *int777 C **int778 D ***int779}780type T2 struct {781 A ***int782 B **int783 C *int784 D int785}786func TestAutoIndirection(t *testing.T) {787 // First transfer t1 into t0788 var t1 T1789 t1.A = 17790 t1.B = new(int)791 *t1.B = 177792 t1.C = new(*int)793 *t1.C = new(int)794 **t1.C = 1777795 t1.D = new(**int)796 *t1.D = new(*int)797 **t1.D = new(int)798 ***t1.D = 17777799 b := new(bytes.Buffer)800 enc := NewEncoder(b)801 enc.Encode(t1)802 dec := NewDecoder(b)803 var t0 T0804 dec.Decode(&t0)805 if t0.A != 17 || t0.B != 177 || t0.C != 1777 || t0.D != 17777 {806 t.Errorf("t1->t0: expected {17 177 1777 17777}; got %v", t0)807 }808 // Now transfer t2 into t0809 var t2 T2810 t2.D = 17777811 t2.C = new(int)812 *t2.C = 1777813 t2.B = new(*int)814 *t2.B = new(int)815 **t2.B = 177816 t2.A = new(**int)817 *t2.A = new(*int)818 **t2.A = new(int)819 ***t2.A = 17820 b.Reset()821 enc.Encode(t2)822 t0 = T0{}823 dec.Decode(&t0)824 if t0.A != 17 || t0.B != 177 || t0.C != 1777 || t0.D != 17777 {825 t.Errorf("t2->t0 expected {17 177 1777 17777}; got %v", t0)826 }827 // Now transfer t0 into t1828 t0 = T0{17, 177, 1777, 17777}829 b.Reset()830 enc.Encode(t0)831 t1 = T1{}832 dec.Decode(&t1)833 if t1.A != 17 || *t1.B != 177 || **t1.C != 1777 || ***t1.D != 17777 {834 t.Errorf("t0->t1 expected {17 177 1777 17777}; got {%d %d %d %d}", t1.A, *t1.B, **t1.C, ***t1.D)835 }836 // Now transfer t0 into t2837 b.Reset()838 enc.Encode(t0)839 t2 = T2{}840 dec.Decode(&t2)841 if ***t2.A != 17 || **t2.B != 177 || *t2.C != 1777 || t2.D != 17777 {842 t.Errorf("t0->t2 expected {17 177 1777 17777}; got {%d %d %d %d}", ***t2.A, **t2.B, *t2.C, t2.D)843 }844 // Now do t2 again but without pre-allocated pointers.845 b.Reset()846 enc.Encode(t0)847 ***t2.A = 0848 **t2.B = 0849 *t2.C = 0850 t2.D = 0851 dec.Decode(&t2)852 if ***t2.A != 17 || **t2.B != 177 || *t2.C != 1777 || t2.D != 17777 {853 t.Errorf("t0->t2 expected {17 177 1777 17777}; got {%d %d %d %d}", ***t2.A, **t2.B, *t2.C, t2.D)854 }855}856type RT0 struct {857 A int858 B string859 C float64860}861type RT1 struct {862 C float64863 B string864 A int865 NotSet string866}867func TestReorderedFields(t *testing.T) {868 var rt0 RT0869 rt0.A = 17870 rt0.B = "hello"871 rt0.C = 3.14159872 b := new(bytes.Buffer)873 NewEncoder(b).Encode(rt0)874 dec := NewDecoder(b)875 var rt1 RT1876 // Wire type is RT0, local type is RT1.877 err := dec.Decode(&rt1)878 if err != nil {879 t.Fatal("decode error:", err)880 }881 if rt0.A != rt1.A || rt0.B != rt1.B || rt0.C != rt1.C {882 t.Errorf("rt1->rt0: expected %v; got %v", rt0, rt1)883 }884}885// Like an RT0 but with fields we'll ignore on the decode side.886type IT0 struct {887 A int64888 B string889 Ignore_d []int890 Ignore_e [3]float64891 Ignore_f bool892 Ignore_g string893 Ignore_h []byte894 Ignore_i *RT1895 Ignore_m map[string]int896 C float64897}898func TestIgnoredFields(t *testing.T) {899 var it0 IT0900 it0.A = 17901 it0.B = "hello"902 it0.C = 3.14159903 it0.Ignore_d = []int{1, 2, 3}904 it0.Ignore_e[0] = 1.0905 it0.Ignore_e[1] = 2.0906 it0.Ignore_e[2] = 3.0907 it0.Ignore_f = true908 it0.Ignore_g = "pay no attention"909 it0.Ignore_h = []byte("to the curtain")910 it0.Ignore_i = &RT1{3.1, "hi", 7, "hello"}911 it0.Ignore_m = map[string]int{"one": 1, "two": 2}912 b := new(bytes.Buffer)913 NewEncoder(b).Encode(it0)914 dec := NewDecoder(b)915 var rt1 RT1916 // Wire type is IT0, local type is RT1.917 err := dec.Decode(&rt1)918 if err != nil {919 t.Error("error: ", err)920 }921 if int(it0.A) != rt1.A || it0.B != rt1.B || it0.C != rt1.C {922 t.Errorf("rt0->rt1: expected %v; got %v", it0, rt1)923 }924}925func TestBadRecursiveType(t *testing.T) {926 type Rec ***Rec927 var rec Rec928 b := new(bytes.Buffer)929 err := NewEncoder(b).Encode(&rec)930 if err == nil {931 t.Error("expected error; got none")932 } else if strings.Index(err.Error(), "recursive") < 0 {933 t.Error("expected recursive type error; got", err)934 }935 // Can't test decode easily because we can't encode one, so we can't pass one to a Decoder.936}937type Indirect struct {938 A ***[3]int939 S ***[]int940 M ****map[string]int941}942type Direct struct {943 A [3]int944 S []int945 M map[string]int946}947func TestIndirectSliceMapArray(t *testing.T) {948 // Marshal indirect, unmarshal to direct.949 i := new(Indirect)950 i.A = new(**[3]int)951 *i.A = new(*[3]int)952 **i.A = new([3]int)953 ***i.A = [3]int{1, 2, 3}954 i.S = new(**[]int)955 *i.S = new(*[]int)956 **i.S = new([]int)957 ***i.S = []int{4, 5, 6}958 i.M = new(***map[string]int)959 *i.M = new(**map[string]int)960 **i.M = new(*map[string]int)961 ***i.M = new(map[string]int)962 ****i.M = map[string]int{"one": 1, "two": 2, "three": 3}963 b := new(bytes.Buffer)964 NewEncoder(b).Encode(i)965 dec := NewDecoder(b)966 var d Direct967 err := dec.Decode(&d)968 if err != nil {969 t.Error("error: ", err)970 }971 if len(d.A) != 3 || d.A[0] != 1 || d.A[1] != 2 || d.A[2] != 3 {972 t.Errorf("indirect to direct: d.A is %v not %v", d.A, ***i.A)973 }974 if len(d.S) != 3 || d.S[0] != 4 || d.S[1] != 5 || d.S[2] != 6 {975 t.Errorf("indirect to direct: d.S is %v not %v", d.S, ***i.S)976 }977 if len(d.M) != 3 || d.M["one"] != 1 || d.M["two"] != 2 || d.M["three"] != 3 {978 t.Errorf("indirect to direct: d.M is %v not %v", d.M, ***i.M)979 }980 // Marshal direct, unmarshal to indirect.981 d.A = [3]int{11, 22, 33}982 d.S = []int{44, 55, 66}983 d.M = map[string]int{"four": 4, "five": 5, "six": 6}984 i = new(Indirect)985 b.Reset()986 NewEncoder(b).Encode(d)987 dec = NewDecoder(b)988 err = dec.Decode(&i)989 if err != nil {990 t.Fatal("error: ", err)991 }992 if len(***i.A) != 3 || (***i.A)[0] != 11 || (***i.A)[1] != 22 || (***i.A)[2] != 33 {993 t.Errorf("direct to indirect: ***i.A is %v not %v", ***i.A, d.A)994 }995 if len(***i.S) != 3 || (***i.S)[0] != 44 || (***i.S)[1] != 55 || (***i.S)[2] != 66 {996 t.Errorf("direct to indirect: ***i.S is %v not %v", ***i.S, ***i.S)997 }998 if len(****i.M) != 3 || (****i.M)["four"] != 4 || (****i.M)["five"] != 5 || (****i.M)["six"] != 6 {999 t.Errorf("direct to indirect: ****i.M is %v not %v", ****i.M, d.M)1000 }1001}1002// An interface with several implementations1003type Squarer interface {1004 Square() int1005}1006type Int int1007func (i Int) Square() int {1008 return int(i * i)1009}1010type Float float641011func (f Float) Square() int {1012 return int(f * f)1013}1014type Vector []int1015func (v Vector) Square() int {1016 sum := 01017 for _, x := range v {1018 sum += x * x1019 }1020 return sum1021}1022type Point struct {1023 X, Y int1024}1025func (p Point) Square() int {1026 return p.X*p.X + p.Y*p.Y1027}1028// A struct with interfaces in it.1029type InterfaceItem struct {1030 I int1031 Sq1, Sq2, Sq3 Squarer1032 F float641033 Sq []Squarer1034}1035// The same struct without interfaces1036type NoInterfaceItem struct {1037 I int1038 F float641039}1040func TestInterface(t *testing.T) {1041 iVal := Int(3)1042 fVal := Float(5)1043 // Sending a Vector will require that the receiver define a type in the middle of1044 // receiving the value for item2.1045 vVal := Vector{1, 2, 3}1046 b := new(bytes.Buffer)1047 item1 := &InterfaceItem{1, iVal, fVal, vVal, 11.5, []Squarer{iVal, fVal, nil, vVal}}1048 // Register the types.1049 Register(Int(0))1050 Register(Float(0))1051 Register(Vector{})1052 err := NewEncoder(b).Encode(item1)1053 if err != nil {1054 t.Error("expected no encode error; got", err)1055 }1056 item2 := InterfaceItem{}1057 err = NewDecoder(b).Decode(&item2)1058 if err != nil {1059 t.Fatal("decode:", err)1060 }1061 if item2.I != item1.I {1062 t.Error("normal int did not decode correctly")1063 }1064 if item2.Sq1 == nil || item2.Sq1.Square() != iVal.Square() {1065 t.Error("Int did not decode correctly")1066 }1067 if item2.Sq2 == nil || item2.Sq2.Square() != fVal.Square() {1068 t.Error("Float did not decode correctly")1069 }1070 if item2.Sq3 == nil || item2.Sq3.Square() != vVal.Square() {1071 t.Error("Vector did not decode correctly")1072 }1073 if item2.F != item1.F {1074 t.Error("normal float did not decode correctly")1075 }1076 // Now check that we received a slice of Squarers correctly, including a nil element1077 if len(item1.Sq) != len(item2.Sq) {1078 t.Fatalf("[]Squarer length wrong: got %d; expected %d", len(item2.Sq), len(item1.Sq))1079 }1080 for i, v1 := range item1.Sq {1081 v2 := item2.Sq[i]1082 if v1 == nil || v2 == nil {1083 if v1 != nil || v2 != nil {1084 t.Errorf("item %d inconsistent nils", i)1085 }1086 } else if v1.Square() != v2.Square() {1087 t.Errorf("item %d inconsistent values: %v %v", i, v1, v2)1088 }1089 }1090}1091// A struct with all basic types, stored in interfaces.1092type BasicInterfaceItem struct {1093 Int, Int8, Int16, Int32, Int64 interface{}1094 Uint, Uint8, Uint16, Uint32, Uint64 interface{}1095 Float32, Float64 interface{}1096 Complex64, Complex128 interface{}1097 Bool interface{}1098 String interface{}1099 Bytes interface{}1100}1101func TestInterfaceBasic(t *testing.T) {1102 b := new(bytes.Buffer)1103 item1 := &BasicInterfaceItem{1104 int(1), int8(1), int16(1), int32(1), int64(1),1105 uint(1), uint8(1), uint16(1), uint32(1), uint64(1),1106 float32(1), 1.0,1107 complex64(1i), complex128(1i),1108 true,1109 "hello",1110 []byte("sailor"),1111 }1112 err := NewEncoder(b).Encode(item1)1113 if err != nil {1114 t.Error("expected no encode error; got", err)1115 }1116 item2 := &BasicInterfaceItem{}1117 err = NewDecoder(b).Decode(&item2)1118 if err != nil {1119 t.Fatal("decode:", err)1120 }1121 if !reflect.DeepEqual(item1, item2) {1122 t.Errorf("encode expected %v got %v", item1, item2)1123 }1124 // Hand check a couple for correct types.1125 if v, ok := item2.Bool.(bool); !ok || !v {1126 t.Error("boolean should be true")1127 }1128 if v, ok := item2.String.(string); !ok || v != item1.String.(string) {1129 t.Errorf("string should be %v is %v", item1.String, v)1130 }1131}1132type String string1133type PtrInterfaceItem struct {1134 Str1 interface{} // basic1135 Str2 interface{} // derived1136}1137// We'll send pointers; should receive values.1138// Also check that we can register T but send *T.1139func TestInterfacePointer(t *testing.T) {1140 b := new(bytes.Buffer)1141 str1 := "howdy"1142 str2 := String("kiddo")1143 item1 := &PtrInterfaceItem{1144 &str1,1145 &str2,1146 }1147 // Register the type.1148 Register(str2)1149 err := NewEncoder(b).Encode(item1)1150 if err != nil {1151 t.Error("expected no encode error; got", err)1152 }1153 item2 := &PtrInterfaceItem{}1154 err = NewDecoder(b).Decode(&item2)1155 if err != nil {1156 t.Fatal("decode:", err)1157 }1158 // Hand test for correct types and values.1159 if v, ok := item2.Str1.(string); !ok || v != str1 {1160 t.Errorf("basic string failed: %q should be %q", v, str1)1161 }1162 if v, ok := item2.Str2.(String); !ok || v != str2 {1163 t.Errorf("derived type String failed: %q should be %q", v, str2)1164 }1165}1166func TestIgnoreInterface(t *testing.T) {1167 iVal := Int(3)1168 fVal := Float(5)1169 // Sending a Point will require that the receiver define a type in the middle of1170 // receiving the value for item2.1171 pVal := Point{2, 3}1172 b := new(bytes.Buffer)1173 item1 := &InterfaceItem{1, iVal, fVal, pVal, 11.5, nil}1174 // Register the types.1175 Register(Int(0))1176 Register(Float(0))1177 Register(Point{})1178 err := NewEncoder(b).Encode(item1)1179 if err != nil {1180 t.Error("expected no encode error; got", err)1181 }1182 item2 := NoInterfaceItem{}1183 err = NewDecoder(b).Decode(&item2)1184 if err != nil {1185 t.Fatal("decode:", err)1186 }1187 if item2.I != item1.I {1188 t.Error("normal int did not decode correctly")1189 }1190 if item2.F != item2.F {1191 t.Error("normal float did not decode correctly")1192 }1193}1194type U struct {1195 A int1196 B string1197 c float641198 D uint1199}1200func TestUnexportedFields(t *testing.T) {1201 var u0 U1202 u0.A = 171203 u0.B = "hello"1204 u0.c = 3.141591205 u0.D = 231206 b := new(bytes.Buffer)1207 NewEncoder(b).Encode(u0)1208 dec := NewDecoder(b)1209 var u1 U1210 u1.c = 1234.1211 err := dec.Decode(&u1)1212 if err != nil {1213 t.Fatal("decode error:", err)1214 }1215 if u0.A != u0.A || u0.B != u1.B || u0.D != u1.D {1216 t.Errorf("u1->u0: expected %v; got %v", u0, u1)1217 }1218 if u1.c != 1234. {1219 t.Error("u1.c modified")1220 }1221}1222var singletons = []interface{}{1223 true,1224 7,1225 3.2,1226 "hello",1227 [3]int{11, 22, 33},1228 []float32{0.5, 0.25, 0.125},1229 map[string]int{"one": 1, "two": 2},1230}1231func TestDebugSingleton(t *testing.T) {1232 if debugFunc == nil {1233 return1234 }1235 b := new(bytes.Buffer)1236 // Accumulate a number of values and print them out all at once.1237 for _, x := range singletons {1238 err := NewEncoder(b).Encode(x)1239 if err != nil {1240 t.Fatal("encode:", err)1241 }1242 }1243 debugFunc(b)1244}1245// A type that won't be defined in the gob until we send it in an interface value.1246type OnTheFly struct {1247 A int1248}1249type DT struct {1250 // X OnTheFly1251 A int1252 B string1253 C float641254 I interface{}1255 J interface{}1256 I_nil interface{}1257 M map[string]int1258 T [3]int1259 S []string1260}1261func TestDebugStruct(t *testing.T) {1262 if debugFunc == nil {1263 return1264 }1265 Register(OnTheFly{})1266 var dt DT1267 dt.A = 171268 dt.B = "hello"1269 dt.C = 3.141591270 dt.I = 2718281271 dt.J = OnTheFly{3}1272 dt.I_nil = nil1273 dt.M = map[string]int{"one": 1, "two": 2}1274 dt.T = [3]int{11, 22, 33}1275 dt.S = []string{"hi", "joe"}1276 b := new(bytes.Buffer)1277 err := NewEncoder(b).Encode(dt)1278 if err != nil {1279 t.Fatal("encode:", err)1280 }1281 debugBuffer := bytes.NewBuffer(b.Bytes())1282 dt2 := &DT{}1283 err = NewDecoder(b).Decode(&dt2)1284 if err != nil {1285 t.Error("decode:", err)1286 }1287 debugFunc(debugBuffer)1288}1289func encFuzzDec(rng *rand.Rand, in interface{}) error {1290 buf := new(bytes.Buffer)1291 enc := NewEncoder(buf)1292 if err := enc.Encode(&in); err != nil {1293 return err1294 }1295 b := buf.Bytes()1296 for i, bi := range b {1297 if rng.Intn(10) < 3 {1298 b[i] = bi + uint8(rng.Intn(256))1299 }1300 }1301 dec := NewDecoder(buf)1302 var e interface{}1303 if err := dec.Decode(&e); err != nil {1304 return err1305 }1306 return nil1307}1308// This does some "fuzz testing" by attempting to decode a sequence of random bytes.1309func TestFuzz(t *testing.T) {1310 if !*doFuzzTests {1311 t.Logf("disabled; run with -gob.fuzz to enable")1312 return1313 }1314 // all possible inputs1315 input := []interface{}{1316 new(int),1317 new(float32),1318 new(float64),1319 new(complex128),1320 &ByteStruct{255},1321 &ArrayStruct{},1322 &StringStruct{"hello"},1323 &GobTest1{0, &StringStruct{"hello"}},1324 }1325 testFuzz(t, time.Now().UnixNano(), 100, input...)1326}1327func TestFuzzRegressions(t *testing.T) {1328 if !*doFuzzTests {1329 t.Logf("disabled; run with -gob.fuzz to enable")1330 return1331 }1332 // An instance triggering a type name of length ~102 GB.1333 testFuzz(t, 1328492090837718000, 100, new(float32))1334 // An instance triggering a type name of 1.6 GB.1335 // Note: can take several minutes to run.1336 testFuzz(t, 1330522872628565000, 100, new(int))1337}1338func testFuzz(t *testing.T, seed int64, n int, input ...interface{}) {1339 for _, e := range input {1340 t.Logf("seed=%d n=%d e=%T", seed, n, e)1341 rng := rand.New(rand.NewSource(seed))1342 for i := 0; i < n; i++ {1343 encFuzzDec(rng, e)1344 }1345 }1346}...

Full Screen

Full Screen

dataparser.go

Source:dataparser.go Github

copy

Full Screen

...77///////////////////////////////////////////////////////////////////////////////78func init() {79 // generate the CalcUnit map80 dataCalcDB = make(map[string]*CalcUnit, 50)81 dataCalcDB[Cmd_WorkStatus] = NewCalcUnit(Cmd_WorkStatus)82 dataCalcDB[Cmd_RunTimeTotal] = NewCalcUnit(Cmd_RunTimeTotal)83 dataCalcDB[Cmd_EnergyTotal] = NewCalcUnit(Cmd_EnergyTotal)84 dataCalcDB[Cmd_EnergyDay] = NewCalcUnit(Cmd_EnergyDay)85 dataCalcDB[Cmd_ITemp] = NewCalcUnit(Cmd_ITemp)86 dataCalcDB[Cmd_VdcPV1] = NewCalcUnit(Cmd_VdcPV1)87 dataCalcDB[Cmd_IdcPV1] = NewCalcUnit(Cmd_IdcPV1)88 dataCalcDB[Cmd_DCPowerPV1] = NewCalcUnit(Cmd_DCPowerPV1)89 dataCalcDB[Cmd_VdcPV2] = NewCalcUnit(Cmd_VdcPV2)90 dataCalcDB[Cmd_IdcPV2] = NewCalcUnit(Cmd_IdcPV2)91 dataCalcDB[Cmd_DCPowerPV2] = NewCalcUnit(Cmd_DCPowerPV2)92 dataCalcDB[Cmd_VdcPV3] = NewCalcUnit(Cmd_VdcPV3)93 dataCalcDB[Cmd_IdcPV3] = NewCalcUnit(Cmd_IdcPV3)94 dataCalcDB[Cmd_DCPowerPV3] = NewCalcUnit(Cmd_DCPowerPV3)95 dataCalcDB[Cmd_VdcPV4] = NewCalcUnit(Cmd_VdcPV4)96 dataCalcDB[Cmd_IdcPV4] = NewCalcUnit(Cmd_IdcPV4)97 dataCalcDB[Cmd_DCPowerPV4] = NewCalcUnit(Cmd_DCPowerPV4)98 dataCalcDB[Cmd_GFCIResistorPV1] = NewCalcUnit(Cmd_GFCIResistorPV1)99 dataCalcDB[Cmd_GFCIResistorPV2] = NewCalcUnit(Cmd_GFCIResistorPV2)100 dataCalcDB[Cmd_GFCIResistorPV3] = NewCalcUnit(Cmd_GFCIResistorPV3)101 dataCalcDB[Cmd_GFCIResistorPV4] = NewCalcUnit(Cmd_GFCIResistorPV4)102 dataCalcDB[Cmd_AverVdcPV] = NewCalcUnit(Cmd_AverVdcPV)103 dataCalcDB[Cmd_IdcTotal] = NewCalcUnit(Cmd_IdcTotal)104 dataCalcDB[Cmd_DCPowerTotal] = NewCalcUnit(Cmd_DCPowerTotal)105 dataCalcDB[Cmd_VacR] = NewCalcUnit(Cmd_VacR)106 dataCalcDB[Cmd_IacR] = NewCalcUnit(Cmd_IacR)107 dataCalcDB[Cmd_ACPwerR] = NewCalcUnit(Cmd_ACPwerR)108 dataCalcDB[Cmd_FacR] = NewCalcUnit(Cmd_FacR)109 dataCalcDB[Cmd_VacS] = NewCalcUnit(Cmd_VacS)110 dataCalcDB[Cmd_IacS] = NewCalcUnit(Cmd_IacS)111 dataCalcDB[Cmd_ACPwerS] = NewCalcUnit(Cmd_ACPwerS)112 dataCalcDB[Cmd_FacS] = NewCalcUnit(Cmd_FacS)113 dataCalcDB[Cmd_VacT] = NewCalcUnit(Cmd_VacT)114 dataCalcDB[Cmd_IacT] = NewCalcUnit(Cmd_IacT)115 dataCalcDB[Cmd_ACPwerT] = NewCalcUnit(Cmd_ACPwerT)116 dataCalcDB[Cmd_FacT] = NewCalcUnit(Cmd_FacT)117 dataCalcDB[Cmd_AverVac] = NewCalcUnit(Cmd_AverVac)118 dataCalcDB[Cmd_ACActivePowerTotal] = NewCalcUnit(Cmd_ACActivePowerTotal)119 dataCalcDB[Cmd_IacTotal] = NewCalcUnit(Cmd_IacTotal)120 dataCalcDB[Cmd_VacBalance] = NewCalcUnit(Cmd_VacBalance)121 dataCalcDB[Cmd_IacBalance] = NewCalcUnit(Cmd_IacBalance)122 dataCalcDB[Cmd_Fgrid] = NewCalcUnit(Cmd_Fgrid)123 dataCalcDB[Cmd_Efficiency] = NewCalcUnit(Cmd_Efficiency)124 dataCalcDB[Cmd_SPLPEnergy] = NewCalcUnit(Cmd_SPLPEnergy)125 dataCalcDB[Cmd_ErrorMessage] = NewCalcUnit(Cmd_ErrorMessage)126}127func NewCalcUnit(cmd string) *CalcUnit {128 return &CalcUnit{Cmd: cmd}129}130func RefreshDataCalcDB() {131 //132}133///////////////////////////////////////////////////////////////////////////////134///////////////////////////////////////////////////////////////////////////////135///////////////////////////////////////////////////////////////////////////////136func genSubCmdUnit(v *simplejson.Json, data *CalcUnit) {137 // generate the items & digital138 switch data.Oper {139 case ucmd.FNAME_DIV:140 item, _ := v.Get(FItem_Dividend).String()141 data.SubCmd = append(data.SubCmd, item)142 item, _ = v.Get(FItem_Divisor).String()143 data.SubCmd = append(data.SubCmd, item)144 case ucmd.FNAME_HL:145 item, _ := v.Get(FItem_H).String()146 data.SubCmd = append(data.SubCmd, item)147 item, _ = v.Get(FItem_L).String()148 data.SubCmd = append(data.SubCmd, item)149 item, _ = v.Get(FItem_N).String()150 data.SubCmd = append(data.SubCmd, item)151 case ucmd.FNAME_GDEF:152 var err error153 if data.Default, err = v.Get(FItem_Default).String(); err != nil {154 if data.Default, err = v.Get(FItem_Default).Float64(); err != nil {155 data.Default, _ = v.Get(FItem_Default).Int64()156 }157 }158 //fmt.Println("default value:", data.Default)159 default:160 // normal sub command161 data.SubCmd, _ = v.Get(FItem_Items).StringArray()162 }163 data.Digital = v.Get(FItem_Digit).MustFloat64()164}165func genCalcPara(oper string, orig []interface{}) interface{} {166 switch oper {167 case ucmd.FNAME_HL:168 length := len(orig)169 para := make([]uint64, length)170 for i, v := range orig {171 //var ok bool172 //fmt.Printf("CMD_HL: v[%d]=%v", i, v)173 if tmpVal, ok := v.(float64); ok {174 para[i] = uint64(tmpVal)175 //fmt.Println("para is float64 type")176 }177 }178 return para179 case ucmd.FNAME_SUM:180 fallthrough181 case ucmd.FNAME_AVG:182 fallthrough183 case ucmd.FNAME_DIV:184 fallthrough185 case ucmd.FNAME_MUL:186 fallthrough187 case ucmd.FNAME_STDEV:188 length := len(orig)189 para := make([]float64, length)190 for i, v := range orig {191 para[i], _ = v.(float64)192 }193 return para194 case ucmd.FNAME_ISEQUAL:195 length := len(orig)196 para := make([]interface{}, length)197 for i, v := range orig {198 para[i] = v199 }200 return para201 case ucmd.FNAME_NVSTRCAT:202 length := len(orig)203 para := make([]string, length)204 for i, v := range orig {205 para[i], _ = v.(string)206 }207 return para208 }209 return nil210}211func reInitCalcUnit(unit *CalcUnit) {212 unit.SubCmd = nil213 unit.SubResult = nil214 unit.Digital = 0.0215 unit.Default = nil216}217func DoRunCalcFunc(fname string, unit *CalcUnit, value *simplejson.Json, dataMap map[string]interface{}) (interface{}, error) {218 unit.Oper, _ = value.Get(FItem_Function).String()219 reInitCalcUnit(unit)220 genSubCmdUnit(value, unit)221 //fmt.Printf("function unit:%v\n", unit)222 //traverse the sub command223 for _, subCmd := range unit.SubCmd {224 subUnit := NewCalcUnit(subCmd)225 subVal, _ := DoRunCalcUnit(fname, subUnit, dataMap)226 unit.SubResult = append(unit.SubResult, subVal)227 }228 // calc the result229 var cmdPara interface{}230 switch unit.Oper {231 case ucmd.FNAME_GDEF:232 cmdPara = unit.Default233 //cmdPara0, _ := cmdPara.(int64)234 //cmdPara1, _ := cmdPara.(float64)235 //fmt.Printf("cmdPara=%v, cmdParaf=%v\n", cmdPara0, cmdPara1)236 default:237 cmdPara = genCalcPara(unit.Oper, unit.SubResult)238 //fmt.Println("cmdPara=", cmdPara)239 }240 //fmt.Printf("Oper=%v, SubResult=%v, Digital=%v, cmdPara=%v\n", unit.Oper, unit.SubResult, unit.Digital, cmdPara)241 result := ucmd.Run(unit.Oper, cmdPara, unit.Digital)242 //fmt.Println("result=", result)243 return result, nil244}245// The function used calculate the input unit's value246func DoRunCalcUnit(fname string, unit *CalcUnit, dataMap map[string]interface{}) (interface{}, error) {247 data, ok := dataMap[unit.Cmd]248 if ok {249 // find the value250 //fmt.Println("1 ------ in value data: data=", data)251 return data, nil252 } else {253 // can't find the value254 if value, err := HandleJSONCmd(fname, unit.Cmd); err != nil {255 // no this command!256 //fmt.Println("NO this command")257 //fmt.Println("2 ------ No this command")258 return nil, err259 } else {260 // parse sub command, traverse all items261 //fmt.Println("3 ------ parse this command")262 return DoRunCalcFunc(fname, unit, value, dataMap)263 }264 }265 return nil, nil266}267func RunCalcUnit(fname, cmd string, dataMap map[string]interface{}) (interface{}, error) {268 unit, ok := dataCalcDB[cmd]269 if ok {270 return DoRunCalcUnit(fname, unit, dataMap)271 } else {272 return nil, errors.New("No this calculator unit!")273 }274}275func GenerateRealTimeObject() {276 //fmt.Printf("dataCalcDB=%v\n", dataCalcDB)277 for k, v := range dataCalcDB {278 fmt.Printf("k=%s, cmd=%s\n", k, v.Cmd)279 }280}...

Full Screen

Full Screen

data_nodes_delta_test.go

Source:data_nodes_delta_test.go Github

copy

Full Screen

...31 testutil.AssertSame(t, dataNodes[3], dataNode4)32}33func TestDataNodesDelta(t *testing.T) {34 conf = newConfig(26, 3, fnvHash)35 stateDelta := statemgmt.NewStateDelta()36 stateDelta.Set("chaincodeID1", "key1", []byte("value1_1"), nil)37 stateDelta.Set("chaincodeID1", "key2", []byte("value1_2"), nil)38 stateDelta.Set("chaincodeID2", "key1", []byte("value2_1"), nil)39 stateDelta.Set("chaincodeID2", "key2", []byte("value2_2"), nil)40 dataNodesDelta := newDataNodesDelta(stateDelta)41 affectedBuckets := dataNodesDelta.getAffectedBuckets()42 testutil.AssertContains(t, affectedBuckets, newDataKey("chaincodeID1", "key1").getBucketKey())43 testutil.AssertContains(t, affectedBuckets, newDataKey("chaincodeID1", "key2").getBucketKey())44 testutil.AssertContains(t, affectedBuckets, newDataKey("chaincodeID2", "key1").getBucketKey())45 testutil.AssertContains(t, affectedBuckets, newDataKey("chaincodeID2", "key2").getBucketKey())46}...

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 d := data.New(10)4 fmt.Println(d.Get())5}6import "fmt"7func main() {8 d := data.New(10)9 fmt.Println(d.Get())10}11import "fmt"12func main() {13 d := data.New(10)14 fmt.Println(d.Get())15}16import "fmt"17func main() {18 d := data.New(10)19 fmt.Println(d.Get())20}21import "fmt"22func main() {23 d := data.New(10)24 fmt.Println(d.Get())25}26import "fmt"27func main() {28 d := data.New(10)29 fmt.Println(d.Get())30}31import "fmt"32func main() {33 d := data.New(10)34 fmt.Println(d.Get())35}36import "fmt"37func main() {38 d := data.New(10)39 fmt.Println(d.Get())40}41import "fmt"42func main() {43 d := data.New(10)44 fmt.Println(d.Get())45}46import "fmt"47func main() {48 d := data.New(10)49 fmt.Println(d.Get())50}51import "fmt"52func main() {53 d := data.New(10)54 fmt.Println(d.Get())55}56import "fmt"57func main() {58 d := data.New(10)59 fmt.Println(d.Get())

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := mydata.New(1, 2)4 fmt.Println(data)5}6import (7func main() {8 data := mydata.New(1, 2)9 fmt.Println(data)10}11type Data struct {12}13func New(x, y int) *Data {14 return &Data{x, y}15}16import "testing"17func TestNew(t *testing.T) {18 data := New(1, 2)19 if data.x != 1 || data.y != 2 {20 t.Errorf("data is not 1,2: %v", data)21 }22}23type Data2 struct {24}25func New2(x, y int) *Data2 {26 return &Data2{x, y}27}28import "testing"29func TestNew2(t *testing.T) {30 data := New2(1, 2)31 if data.x != 1 || data.y != 2 {32 t.Errorf("data is not 1,2: %v", data)33 }34}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2type data struct {3}4func (d data) String() string {5 return fmt.Sprintf("Name: %s Age: %d", d.name, d.age)6}7func New(name string, age int) data {8 return data{name, age}9}10func main() {11 d := New("Raj", 22)12 fmt.Println(d)13}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d2 := new(data)4 d3 := data{}5 d4 := &data{}6 d5 := data.New()7 d6 := new(data).New()8 fmt.Println(d1)9 fmt.Println(d2)10 fmt.Println(d3)11 fmt.Println(d4)12 fmt.Println(d5)13 fmt.Println(d6)14}15import (16func main() {17 d2 := new(data)18 d3 := data{}19 d4 := &data{}20 d5 := data.New()21 d6 := new(data).New()22 fmt.Println(d1)23 fmt.Println(d2)24 fmt.Println(d3)25 fmt.Println(d4)26 fmt.Println(d5)27 fmt.Println(d6)28}29import (30func main() {31 d2 := new(data)32 d3 := data{}33 d4 := &data{}34 d5 := data.New()35 d6 := new(data).New()36 fmt.Println(d1)37 fmt.Println(d2)38 fmt.Println(d3)39 fmt.Println(d4)40 fmt.Println(d5)41 fmt.Println(d6)42}43import (44func main() {

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d := New(10)4 fmt.Println(d)5}6import (7func main() {8 d := data{10}9 fmt.Println(d)10}11import (12func main() {13 d := data{10}14 fmt.Println(d.String())15}16import (17func main() {18 d := data{10}19 fmt.Println(d.String())20}21import (22func main() {23 d := data{10}24 fmt.Println(d.String())25}26import (27func main() {28 d := data{10}29 fmt.Println(d.String())30}31import (32func main() {33 d := data{10}34 fmt.Println(d.String())35}36import (37func main() {38 d := data{10}39 fmt.Println(d.String())40}41import (42func main() {43 d := data{10}44 fmt.Println(d.String())45}46import (47func main() {48 d := data{10}49 fmt.Println(d.String())50}51import (52func main() {53 d := data{10}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(data.New())4}5import (6func main() {7 fmt.Println(data.New())8}9import (10func main() {11 fmt.Println(data.New())12}13import (14func main() {15 fmt.Println(data.New())16}17import (18func main() {19 fmt.Println(data.New())20}21import (22func main() {23 fmt.Println(data.New())24}25import (26func main() {27 fmt.Println(data.New())28}29import (30func main() {31 fmt.Println(data.New())32}33import (34func main() {35 fmt.Println(data.New())36}37import (38func main() {39 fmt.Println(data.New())40}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d = data.New("hello")4 fmt.Println(d)5}6import (7func main() {8 d := data.New("hello")9 fmt.Println(d)10}11import (12func main() {13 d := data.New("hello")14 fmt.Println(d)15}16import (17func main() {18 d := data.New("hello")19 fmt.Println(d)20}21import (22func main() {23 d := data.New("hello")24 fmt.Println(d)25}26import (27func main() {28 d := data.New("hello")29 fmt.Println(d)30}31import (32func main() {33 d := data.New("hello")34 fmt.Println(d)35}36import (37func main() {38 d := data.New("hello")39 fmt.Println(d)40}41import (42func main() {43 d := data.New("hello")44 fmt.Println(d)45}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5func main() {6}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a := data.New(10, 20)4 a.Display()5}6import (7func main() {8 a := data.New(10, 20)9 a.Display()10}11import (12func main() {13 a := data.New(10, 20)14 a.Display()15}16import (17func main() {18 a := data.New(10, 20)19 a.Display()20}21import (22func main() {23 a := data.New(10, 20)24 a.Display()25}26import (27func main() {28 a := data.New(10, 20)29 a.Display()30}31import (32func main() {33 a := data.New(10, 20)34 a.Display()35}36import (37func main() {38 a := data.New(10, 20)39 a.Display()40}41import (42func main() {43 a := data.New(10, 20)44 a.Display()45}46import (47func main() {

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