How to use New method of is Package

Best Is code snippet using is.New

json.qtpl_test.go

Source:json.qtpl_test.go Github

copy

Full Screen

...15 IsHidden bool16 IsDisabled bool17 IsReadOnly bool18 IsSlice bool19 IsNewPrimary bool20 SelectWithNew bool21 InputType string22 DefaultInputValue string23 Attachments []AttachmentList24 SelectOptions map[string]string25 PatternList dbEngine.Table26 PatternName string27 PlaceHolder string28 LinkNew string29 Label string30 pattern string31 patternDesc string32 Value interface{}33 Suggestions string34 }35 tests := []struct {36 name string37 fields fields38 want string39 }{40 // TODO: Add test cases.41 {42 "id_photos",43 fields{44 Column: dbEngine.NewStringColumn("id_photos", "test column", false),45 Attachments: []AttachmentList{46 {47 1,48 "https://site.com/photots/",49 },50 },51 },52 `{"name": "id_photos","required":false,"type": "", "title": "", "list":[{"id":1,"url":"https://site.com/photots/"}]53}`,54 },55 }56 for _, tt := range tests {57 t.Run(tt.name, func(t *testing.T) {58 col := &ColumnDecor{59 Column: tt.fields.Column,60 IsHidden: tt.fields.IsHidden,61 IsDisabled: tt.fields.IsDisabled,62 IsReadOnly: tt.fields.IsReadOnly,63 IsSlice: tt.fields.IsSlice,64 IsNewPrimary: tt.fields.IsNewPrimary,65 SelectWithNew: tt.fields.SelectWithNew,66 InputType: tt.fields.InputType,67 DefaultInputValue: tt.fields.DefaultInputValue,68 Attachments: tt.fields.Attachments,69 SelectOptions: tt.fields.SelectOptions,70 PatternList: tt.fields.PatternList,71 PatternName: tt.fields.PatternName,72 PlaceHolder: tt.fields.PlaceHolder,73 LinkNew: tt.fields.LinkNew,74 Label: tt.fields.Label,75 pattern: tt.fields.pattern,76 patternDesc: tt.fields.patternDesc,77 Value: tt.fields.Value,78 Suggestions: tt.fields.Suggestions,79 }80 got := col.ToJSON()81 assert.Equal(t, tt.want, got)82 })83 }84}85func TestColumnDecor_InputTypeForJSON(t *testing.T) {86 type fields struct {87 Column dbEngine.Column88 IsHidden bool89 IsDisabled bool90 IsReadOnly bool91 IsSlice bool92 IsNewPrimary bool93 SelectWithNew bool94 InputType string95 DefaultInputValue string96 Attachments []AttachmentList97 SelectOptions map[string]string98 PatternList dbEngine.Table99 PatternName string100 PlaceHolder string101 LinkNew string102 Label string103 pattern string104 patternDesc string105 Value interface{}106 Suggestions string107 }108 tests := []struct {109 name string110 fields fields111 want string112 }{113 // TODO: Add test cases.114 }115 for _, tt := range tests {116 t.Run(tt.name, func(t *testing.T) {117 col := &ColumnDecor{118 Column: tt.fields.Column,119 IsHidden: tt.fields.IsHidden,120 IsDisabled: tt.fields.IsDisabled,121 IsReadOnly: tt.fields.IsReadOnly,122 IsSlice: tt.fields.IsSlice,123 IsNewPrimary: tt.fields.IsNewPrimary,124 SelectWithNew: tt.fields.SelectWithNew,125 InputType: tt.fields.InputType,126 DefaultInputValue: tt.fields.DefaultInputValue,127 Attachments: tt.fields.Attachments,128 SelectOptions: tt.fields.SelectOptions,129 PatternList: tt.fields.PatternList,130 PatternName: tt.fields.PatternName,131 PlaceHolder: tt.fields.PlaceHolder,132 LinkNew: tt.fields.LinkNew,133 Label: tt.fields.Label,134 pattern: tt.fields.pattern,135 patternDesc: tt.fields.patternDesc,136 Value: tt.fields.Value,137 Suggestions: tt.fields.Suggestions,138 }139 if got := col.InputTypeForJSON(); got != tt.want {140 t.Errorf("InputTypeForJSON() = %v, want %v", got, tt.want)141 }142 })143 }144}145func TestColumnDecor_RenderAttr(t *testing.T) {146 type fields struct {147 Column dbEngine.Column148 IsHidden bool149 IsDisabled bool150 IsReadOnly bool151 IsSlice bool152 IsNewPrimary bool153 SelectWithNew bool154 InputType string155 DefaultInputValue string156 Attachments []AttachmentList157 SelectOptions map[string]string158 PatternList dbEngine.Table159 PatternName string160 PlaceHolder string161 LinkNew string162 Label string163 pattern string164 patternDesc string165 Value interface{}166 Suggestions string167 }168 type args struct {169 i int170 }171 tests := []struct {172 name string173 fields fields174 args args175 want string176 }{177 // TODO: Add test cases.178 }179 for _, tt := range tests {180 t.Run(tt.name, func(t *testing.T) {181 col := &ColumnDecor{182 Column: tt.fields.Column,183 IsHidden: tt.fields.IsHidden,184 IsDisabled: tt.fields.IsDisabled,185 IsReadOnly: tt.fields.IsReadOnly,186 IsSlice: tt.fields.IsSlice,187 IsNewPrimary: tt.fields.IsNewPrimary,188 SelectWithNew: tt.fields.SelectWithNew,189 InputType: tt.fields.InputType,190 DefaultInputValue: tt.fields.DefaultInputValue,191 Attachments: tt.fields.Attachments,192 SelectOptions: tt.fields.SelectOptions,193 PatternList: tt.fields.PatternList,194 PatternName: tt.fields.PatternName,195 PlaceHolder: tt.fields.PlaceHolder,196 LinkNew: tt.fields.LinkNew,197 Label: tt.fields.Label,198 pattern: tt.fields.pattern,199 patternDesc: tt.fields.patternDesc,200 Value: tt.fields.Value,201 Suggestions: tt.fields.Suggestions,202 }203 if got := col.RenderAttr(tt.args.i); got != tt.want {204 t.Errorf("RenderAttr() = %v, want %v", got, tt.want)205 }206 })207 }208}209func TestColumnDecor_RenderInputs(t *testing.T) {210 type fields struct {211 Column dbEngine.Column212 IsHidden bool213 IsDisabled bool214 IsReadOnly bool215 IsSlice bool216 IsNewPrimary bool217 SelectWithNew bool218 InputType string219 DefaultInputValue string220 Attachments []AttachmentList221 SelectOptions map[string]string222 PatternList dbEngine.Table223 PatternName string224 PlaceHolder string225 LinkNew string226 Label string227 pattern string228 patternDesc string229 Value interface{}230 Suggestions string231 }232 type args struct {233 data map[string]interface{}234 }235 tests := []struct {236 name string237 fields fields238 args args239 want string240 }{241 // TODO: Add test cases.242 }243 for _, tt := range tests {244 t.Run(tt.name, func(t *testing.T) {245 col := &ColumnDecor{246 Column: tt.fields.Column,247 IsHidden: tt.fields.IsHidden,248 IsDisabled: tt.fields.IsDisabled,249 IsReadOnly: tt.fields.IsReadOnly,250 IsSlice: tt.fields.IsSlice,251 IsNewPrimary: tt.fields.IsNewPrimary,252 SelectWithNew: tt.fields.SelectWithNew,253 InputType: tt.fields.InputType,254 DefaultInputValue: tt.fields.DefaultInputValue,255 Attachments: tt.fields.Attachments,256 SelectOptions: tt.fields.SelectOptions,257 PatternList: tt.fields.PatternList,258 PatternName: tt.fields.PatternName,259 PlaceHolder: tt.fields.PlaceHolder,260 LinkNew: tt.fields.LinkNew,261 Label: tt.fields.Label,262 pattern: tt.fields.pattern,263 patternDesc: tt.fields.patternDesc,264 Value: tt.fields.Value,265 Suggestions: tt.fields.Suggestions,266 }267 if got := col.RenderInputs(tt.args.data); got != tt.want {268 t.Errorf("RenderInputs() = %v, want %v", got, tt.want)269 }270 })271 }272}273func TestColumnDecor_RenderValue(t *testing.T) {274 type fields struct {275 Column dbEngine.Column276 IsHidden bool277 IsDisabled bool278 IsReadOnly bool279 IsSlice bool280 IsNewPrimary bool281 SelectWithNew bool282 InputType string283 DefaultInputValue string284 Attachments []AttachmentList285 SelectOptions map[string]string286 PatternList dbEngine.Table287 PatternName string288 PlaceHolder string289 LinkNew string290 Label string291 pattern string292 patternDesc string293 Value interface{}294 Suggestions string295 }296 type args struct {297 value interface{}298 }299 tests := []struct {300 name string301 fields fields302 args args303 want string304 }{305 // TODO: Add test cases.306 }307 for _, tt := range tests {308 t.Run(tt.name, func(t *testing.T) {309 col := &ColumnDecor{310 Column: tt.fields.Column,311 IsHidden: tt.fields.IsHidden,312 IsDisabled: tt.fields.IsDisabled,313 IsReadOnly: tt.fields.IsReadOnly,314 IsSlice: tt.fields.IsSlice,315 IsNewPrimary: tt.fields.IsNewPrimary,316 SelectWithNew: tt.fields.SelectWithNew,317 InputType: tt.fields.InputType,318 DefaultInputValue: tt.fields.DefaultInputValue,319 Attachments: tt.fields.Attachments,320 SelectOptions: tt.fields.SelectOptions,321 PatternList: tt.fields.PatternList,322 PatternName: tt.fields.PatternName,323 PlaceHolder: tt.fields.PlaceHolder,324 LinkNew: tt.fields.LinkNew,325 Label: tt.fields.Label,326 pattern: tt.fields.pattern,327 patternDesc: tt.fields.patternDesc,328 Value: tt.fields.Value,329 Suggestions: tt.fields.Suggestions,330 }331 if got := col.RenderValue(tt.args.value); got != tt.want {332 t.Errorf("RenderValue() = %v, want %v", got, tt.want)333 }334 })335 }336}337func TestColumnDecor_StreamDataForJSON(t *testing.T) {338 type fields struct {339 Column dbEngine.Column340 IsHidden bool341 IsDisabled bool342 IsReadOnly bool343 IsSlice bool344 IsNewPrimary bool345 SelectWithNew bool346 InputType string347 DefaultInputValue string348 Attachments []AttachmentList349 SelectOptions map[string]string350 PatternList dbEngine.Table351 PatternName string352 PlaceHolder string353 LinkNew string354 Label string355 pattern string356 patternDesc string357 Value interface{}358 Suggestions string359 }360 type args struct {361 qw422016 *qt422016.Writer362 }363 tests := []struct {364 name string365 fields fields366 args args367 }{368 // TODO: Add test cases.369 }370 for _, tt := range tests {371 t.Run(tt.name, func(t *testing.T) {372 col := &ColumnDecor{373 Column: tt.fields.Column,374 IsHidden: tt.fields.IsHidden,375 IsDisabled: tt.fields.IsDisabled,376 IsReadOnly: tt.fields.IsReadOnly,377 IsSlice: tt.fields.IsSlice,378 IsNewPrimary: tt.fields.IsNewPrimary,379 SelectWithNew: tt.fields.SelectWithNew,380 InputType: tt.fields.InputType,381 DefaultInputValue: tt.fields.DefaultInputValue,382 Attachments: tt.fields.Attachments,383 SelectOptions: tt.fields.SelectOptions,384 PatternList: tt.fields.PatternList,385 PatternName: tt.fields.PatternName,386 PlaceHolder: tt.fields.PlaceHolder,387 LinkNew: tt.fields.LinkNew,388 Label: tt.fields.Label,389 pattern: tt.fields.pattern,390 patternDesc: tt.fields.patternDesc,391 Value: tt.fields.Value,392 Suggestions: tt.fields.Suggestions,393 }394 w := bytes.NewBufferString("")395 col.WriteDataForJSON(w)396 assert.Equal(t, tt.name, w.String())397 })398 }399}400func TestColumnDecor_StreamInputTypeForJSON(t *testing.T) {401 type fields struct {402 Column dbEngine.Column403 IsHidden bool404 IsDisabled bool405 IsReadOnly bool406 IsSlice bool407 IsNewPrimary bool408 SelectWithNew bool409 InputType string410 DefaultInputValue string411 Attachments []AttachmentList412 SelectOptions map[string]string413 PatternList dbEngine.Table414 PatternName string415 PlaceHolder string416 LinkNew string417 Label string418 pattern string419 patternDesc string420 Value interface{}421 Suggestions string422 }423 type args struct {424 qw422016 *qt422016.Writer425 }426 tests := []struct {427 name string428 fields fields429 args args430 }{431 // TODO: Add test cases.432 }433 for _, tt := range tests {434 t.Run(tt.name, func(t *testing.T) {435 col := &ColumnDecor{436 Column: tt.fields.Column,437 IsHidden: tt.fields.IsHidden,438 IsDisabled: tt.fields.IsDisabled,439 IsReadOnly: tt.fields.IsReadOnly,440 IsSlice: tt.fields.IsSlice,441 IsNewPrimary: tt.fields.IsNewPrimary,442 SelectWithNew: tt.fields.SelectWithNew,443 InputType: tt.fields.InputType,444 DefaultInputValue: tt.fields.DefaultInputValue,445 Attachments: tt.fields.Attachments,446 SelectOptions: tt.fields.SelectOptions,447 PatternList: tt.fields.PatternList,448 PatternName: tt.fields.PatternName,449 PlaceHolder: tt.fields.PlaceHolder,450 LinkNew: tt.fields.LinkNew,451 Label: tt.fields.Label,452 pattern: tt.fields.pattern,453 patternDesc: tt.fields.patternDesc,454 Value: tt.fields.Value,455 Suggestions: tt.fields.Suggestions,456 }457 w := bytes.NewBufferString("")458 col.WriteInputTypeForJSON(w)459 assert.Equal(t, tt.name, w.String())460 })461 }462}463func TestColumnDecor_StreamRenderAttr(t *testing.T) {464 type fields struct {465 Column dbEngine.Column466 IsHidden bool467 IsDisabled bool468 IsReadOnly bool469 IsSlice bool470 IsNewPrimary bool471 SelectWithNew bool472 InputType string473 DefaultInputValue string474 Attachments []AttachmentList475 SelectOptions map[string]string476 PatternList dbEngine.Table477 PatternName string478 PlaceHolder string479 LinkNew string480 Label string481 pattern string482 patternDesc string483 Value interface{}484 Suggestions string485 }486 type args struct {487 qw422016 *qt422016.Writer488 i int489 }490 tests := []struct {491 name string492 fields fields493 args args494 }{495 // TODO: Add test cases.496 }497 for _, tt := range tests {498 t.Run(tt.name, func(t *testing.T) {499 col := &ColumnDecor{500 Column: tt.fields.Column,501 IsHidden: tt.fields.IsHidden,502 IsDisabled: tt.fields.IsDisabled,503 IsReadOnly: tt.fields.IsReadOnly,504 IsSlice: tt.fields.IsSlice,505 IsNewPrimary: tt.fields.IsNewPrimary,506 SelectWithNew: tt.fields.SelectWithNew,507 InputType: tt.fields.InputType,508 DefaultInputValue: tt.fields.DefaultInputValue,509 Attachments: tt.fields.Attachments,510 SelectOptions: tt.fields.SelectOptions,511 PatternList: tt.fields.PatternList,512 PatternName: tt.fields.PatternName,513 PlaceHolder: tt.fields.PlaceHolder,514 LinkNew: tt.fields.LinkNew,515 Label: tt.fields.Label,516 pattern: tt.fields.pattern,517 patternDesc: tt.fields.patternDesc,518 Value: tt.fields.Value,519 Suggestions: tt.fields.Suggestions,520 }521 w := bytes.NewBufferString("")522 col.WriteRenderAttr(w, 0)523 assert.Equal(t, tt.name, w.String())524 })525 }526}527func TestColumnDecor_StreamRenderInputs(t *testing.T) {528 type fields struct {529 Column dbEngine.Column530 IsHidden bool531 IsDisabled bool532 IsReadOnly bool533 IsSlice bool534 IsNewPrimary bool535 SelectWithNew bool536 InputType string537 DefaultInputValue string538 Attachments []AttachmentList539 SelectOptions map[string]string540 PatternList dbEngine.Table541 PatternName string542 PlaceHolder string543 LinkNew string544 Label string545 pattern string546 patternDesc string547 Value interface{}548 Suggestions string549 }550 type args struct {551 qw422016 *qt422016.Writer552 data map[string]interface{}553 }554 tests := []struct {555 name string556 fields fields557 args args558 }{559 // TODO: Add test cases.560 }561 for _, tt := range tests {562 t.Run(tt.name, func(t *testing.T) {563 col := &ColumnDecor{564 Column: tt.fields.Column,565 IsHidden: tt.fields.IsHidden,566 IsDisabled: tt.fields.IsDisabled,567 IsReadOnly: tt.fields.IsReadOnly,568 IsSlice: tt.fields.IsSlice,569 IsNewPrimary: tt.fields.IsNewPrimary,570 SelectWithNew: tt.fields.SelectWithNew,571 InputType: tt.fields.InputType,572 DefaultInputValue: tt.fields.DefaultInputValue,573 Attachments: tt.fields.Attachments,574 SelectOptions: tt.fields.SelectOptions,575 PatternList: tt.fields.PatternList,576 PatternName: tt.fields.PatternName,577 PlaceHolder: tt.fields.PlaceHolder,578 LinkNew: tt.fields.LinkNew,579 Label: tt.fields.Label,580 pattern: tt.fields.pattern,581 patternDesc: tt.fields.patternDesc,582 Value: tt.fields.Value,583 Suggestions: tt.fields.Suggestions,584 }585 w := bytes.NewBufferString("")586 col.WriteRenderInputs(w, nil)587 assert.Equal(t, tt.name, w.String())588 })589 }590}591func TestColumnDecor_StreamRenderValue(t *testing.T) {592 type fields struct {593 Column dbEngine.Column594 IsHidden bool595 IsDisabled bool596 IsReadOnly bool597 IsSlice bool598 IsNewPrimary bool599 SelectWithNew bool600 InputType string601 DefaultInputValue string602 Attachments []AttachmentList603 SelectOptions map[string]string604 PatternList dbEngine.Table605 PatternName string606 PlaceHolder string607 LinkNew string608 Label string609 pattern string610 patternDesc string611 Value interface{}612 Suggestions string613 }614 type args struct {615 qw422016 *qt422016.Writer616 value interface{}617 }618 tests := []struct {619 name string620 fields fields621 args args622 }{623 // TODO: Add test cases.624 }625 for _, tt := range tests {626 t.Run(tt.name, func(t *testing.T) {627 col := &ColumnDecor{628 Column: tt.fields.Column,629 IsHidden: tt.fields.IsHidden,630 IsDisabled: tt.fields.IsDisabled,631 IsReadOnly: tt.fields.IsReadOnly,632 IsSlice: tt.fields.IsSlice,633 IsNewPrimary: tt.fields.IsNewPrimary,634 SelectWithNew: tt.fields.SelectWithNew,635 InputType: tt.fields.InputType,636 DefaultInputValue: tt.fields.DefaultInputValue,637 Attachments: tt.fields.Attachments,638 SelectOptions: tt.fields.SelectOptions,639 PatternList: tt.fields.PatternList,640 PatternName: tt.fields.PatternName,641 PlaceHolder: tt.fields.PlaceHolder,642 LinkNew: tt.fields.LinkNew,643 Label: tt.fields.Label,644 pattern: tt.fields.pattern,645 patternDesc: tt.fields.patternDesc,646 Value: tt.fields.Value,647 Suggestions: tt.fields.Suggestions,648 }649 w := bytes.NewBufferString("")650 col.WriteRenderValue(w, nil)651 assert.Equal(t, tt.name, w.String())652 })653 }654}655func TestColumnDecor_WriteDataForJSON(t *testing.T) {656 type fields struct {657 Column dbEngine.Column658 IsHidden bool659 IsDisabled bool660 IsReadOnly bool661 IsSlice bool662 IsNewPrimary bool663 SelectWithNew bool664 InputType string665 DefaultInputValue string666 Attachments []AttachmentList667 SelectOptions map[string]string668 PatternList dbEngine.Table669 PatternName string670 PlaceHolder string671 LinkNew string672 Label string673 pattern string674 patternDesc string675 Value interface{}676 Suggestions string677 }678 tests := []struct {679 name string680 fields fields681 wantQq422016 string682 }{683 // TODO: Add test cases.684 }685 for _, tt := range tests {686 t.Run(tt.name, func(t *testing.T) {687 col := &ColumnDecor{688 Column: tt.fields.Column,689 IsHidden: tt.fields.IsHidden,690 IsDisabled: tt.fields.IsDisabled,691 IsReadOnly: tt.fields.IsReadOnly,692 IsSlice: tt.fields.IsSlice,693 IsNewPrimary: tt.fields.IsNewPrimary,694 SelectWithNew: tt.fields.SelectWithNew,695 InputType: tt.fields.InputType,696 DefaultInputValue: tt.fields.DefaultInputValue,697 Attachments: tt.fields.Attachments,698 SelectOptions: tt.fields.SelectOptions,699 PatternList: tt.fields.PatternList,700 PatternName: tt.fields.PatternName,701 PlaceHolder: tt.fields.PlaceHolder,702 LinkNew: tt.fields.LinkNew,703 Label: tt.fields.Label,704 pattern: tt.fields.pattern,705 patternDesc: tt.fields.patternDesc,706 Value: tt.fields.Value,707 Suggestions: tt.fields.Suggestions,708 }709 qq422016 := &bytes.Buffer{}710 col.WriteDataForJSON(qq422016)711 if gotQq422016 := qq422016.String(); gotQq422016 != tt.wantQq422016 {712 t.Errorf("WriteDataForJSON() = %v, want %v", gotQq422016, tt.wantQq422016)713 }714 })715 }716}717func TestColumnDecor_WriteInputTypeForJSON(t *testing.T) {718 type fields struct {719 Column dbEngine.Column720 IsHidden bool721 IsDisabled bool722 IsReadOnly bool723 IsSlice bool724 IsNewPrimary bool725 SelectWithNew bool726 InputType string727 DefaultInputValue string728 Attachments []AttachmentList729 SelectOptions map[string]string730 PatternList dbEngine.Table731 PatternName string732 PlaceHolder string733 LinkNew string734 Label string735 pattern string736 patternDesc string737 Value interface{}738 Suggestions string739 }740 tests := []struct {741 name string742 fields fields743 wantQq422016 string744 }{745 // TODO: Add test cases.746 }747 for _, tt := range tests {748 t.Run(tt.name, func(t *testing.T) {749 col := &ColumnDecor{750 Column: tt.fields.Column,751 IsHidden: tt.fields.IsHidden,752 IsDisabled: tt.fields.IsDisabled,753 IsReadOnly: tt.fields.IsReadOnly,754 IsSlice: tt.fields.IsSlice,755 IsNewPrimary: tt.fields.IsNewPrimary,756 SelectWithNew: tt.fields.SelectWithNew,757 InputType: tt.fields.InputType,758 DefaultInputValue: tt.fields.DefaultInputValue,759 Attachments: tt.fields.Attachments,760 SelectOptions: tt.fields.SelectOptions,761 PatternList: tt.fields.PatternList,762 PatternName: tt.fields.PatternName,763 PlaceHolder: tt.fields.PlaceHolder,764 LinkNew: tt.fields.LinkNew,765 Label: tt.fields.Label,766 pattern: tt.fields.pattern,767 patternDesc: tt.fields.patternDesc,768 Value: tt.fields.Value,769 Suggestions: tt.fields.Suggestions,770 }771 qq422016 := &bytes.Buffer{}772 col.WriteInputTypeForJSON(qq422016)773 if gotQq422016 := qq422016.String(); gotQq422016 != tt.wantQq422016 {774 t.Errorf("WriteInputTypeForJSON() = %v, want %v", gotQq422016, tt.wantQq422016)775 }776 })777 }778}779func TestColumnDecor_WriteRenderAttr(t *testing.T) {780 type fields struct {781 Column dbEngine.Column782 IsHidden bool783 IsDisabled bool784 IsReadOnly bool785 IsSlice bool786 IsNewPrimary bool787 SelectWithNew bool788 InputType string789 DefaultInputValue string790 Attachments []AttachmentList791 SelectOptions map[string]string792 PatternList dbEngine.Table793 PatternName string794 PlaceHolder string795 LinkNew string796 Label string797 pattern string798 patternDesc string799 Value interface{}800 Suggestions string801 }802 type args struct {803 i int804 }805 tests := []struct {806 name string807 fields fields808 args args809 wantQq422016 string810 }{811 // TODO: Add test cases.812 }813 for _, tt := range tests {814 t.Run(tt.name, func(t *testing.T) {815 col := &ColumnDecor{816 Column: tt.fields.Column,817 IsHidden: tt.fields.IsHidden,818 IsDisabled: tt.fields.IsDisabled,819 IsReadOnly: tt.fields.IsReadOnly,820 IsSlice: tt.fields.IsSlice,821 IsNewPrimary: tt.fields.IsNewPrimary,822 SelectWithNew: tt.fields.SelectWithNew,823 InputType: tt.fields.InputType,824 DefaultInputValue: tt.fields.DefaultInputValue,825 Attachments: tt.fields.Attachments,826 SelectOptions: tt.fields.SelectOptions,827 PatternList: tt.fields.PatternList,828 PatternName: tt.fields.PatternName,829 PlaceHolder: tt.fields.PlaceHolder,830 LinkNew: tt.fields.LinkNew,831 Label: tt.fields.Label,832 pattern: tt.fields.pattern,833 patternDesc: tt.fields.patternDesc,834 Value: tt.fields.Value,835 Suggestions: tt.fields.Suggestions,836 }837 qq422016 := &bytes.Buffer{}838 col.WriteRenderAttr(qq422016, tt.args.i)839 if gotQq422016 := qq422016.String(); gotQq422016 != tt.wantQq422016 {840 t.Errorf("WriteRenderAttr() = %v, want %v", gotQq422016, tt.wantQq422016)841 }842 })843 }844}845func TestColumnDecor_WriteRenderInputs(t *testing.T) {846 type fields struct {847 Column dbEngine.Column848 IsHidden bool849 IsDisabled bool850 IsReadOnly bool851 IsSlice bool852 IsNewPrimary bool853 SelectWithNew bool854 InputType string855 DefaultInputValue string856 Attachments []AttachmentList857 SelectOptions map[string]string858 PatternList dbEngine.Table859 PatternName string860 PlaceHolder string861 LinkNew string862 Label string863 pattern string864 patternDesc string865 Value interface{}866 Suggestions string867 }868 type args struct {869 data map[string]interface{}870 }871 tests := []struct {872 name string873 fields fields874 args args875 wantQq422016 string876 }{877 // TODO: Add test cases.878 }879 for _, tt := range tests {880 t.Run(tt.name, func(t *testing.T) {881 col := &ColumnDecor{882 Column: tt.fields.Column,883 IsHidden: tt.fields.IsHidden,884 IsDisabled: tt.fields.IsDisabled,885 IsReadOnly: tt.fields.IsReadOnly,886 IsSlice: tt.fields.IsSlice,887 IsNewPrimary: tt.fields.IsNewPrimary,888 SelectWithNew: tt.fields.SelectWithNew,889 InputType: tt.fields.InputType,890 DefaultInputValue: tt.fields.DefaultInputValue,891 Attachments: tt.fields.Attachments,892 SelectOptions: tt.fields.SelectOptions,893 PatternList: tt.fields.PatternList,894 PatternName: tt.fields.PatternName,895 PlaceHolder: tt.fields.PlaceHolder,896 LinkNew: tt.fields.LinkNew,897 Label: tt.fields.Label,898 pattern: tt.fields.pattern,899 patternDesc: tt.fields.patternDesc,900 Value: tt.fields.Value,901 Suggestions: tt.fields.Suggestions,902 }903 qq422016 := &bytes.Buffer{}904 col.WriteRenderInputs(qq422016, tt.args.data)905 if gotQq422016 := qq422016.String(); gotQq422016 != tt.wantQq422016 {906 t.Errorf("WriteRenderInputs() = %v, want %v", gotQq422016, tt.wantQq422016)907 }908 })909 }910}911func TestColumnDecor_WriteRenderValue(t *testing.T) {912 type fields struct {913 Column dbEngine.Column914 IsHidden bool915 IsDisabled bool916 IsReadOnly bool917 IsSlice bool918 IsNewPrimary bool919 SelectWithNew bool920 InputType string921 DefaultInputValue string922 Attachments []AttachmentList923 SelectOptions map[string]string924 PatternList dbEngine.Table925 PatternName string926 PlaceHolder string927 LinkNew string928 Label string929 pattern string930 patternDesc string931 Value interface{}932 Suggestions string933 }934 type args struct {935 value interface{}936 }937 tests := []struct {938 name string939 fields fields940 args args941 wantQq422016 string942 }{943 // TODO: Add test cases.944 }945 for _, tt := range tests {946 t.Run(tt.name, func(t *testing.T) {947 col := &ColumnDecor{948 Column: tt.fields.Column,949 IsHidden: tt.fields.IsHidden,950 IsDisabled: tt.fields.IsDisabled,951 IsReadOnly: tt.fields.IsReadOnly,952 IsSlice: tt.fields.IsSlice,953 IsNewPrimary: tt.fields.IsNewPrimary,954 SelectWithNew: tt.fields.SelectWithNew,955 InputType: tt.fields.InputType,956 DefaultInputValue: tt.fields.DefaultInputValue,957 Attachments: tt.fields.Attachments,958 SelectOptions: tt.fields.SelectOptions,959 PatternList: tt.fields.PatternList,960 PatternName: tt.fields.PatternName,961 PlaceHolder: tt.fields.PlaceHolder,962 LinkNew: tt.fields.LinkNew,963 Label: tt.fields.Label,964 pattern: tt.fields.pattern,965 patternDesc: tt.fields.patternDesc,966 Value: tt.fields.Value,967 Suggestions: tt.fields.Suggestions,968 }969 qq422016 := &bytes.Buffer{}970 col.WriteRenderValue(qq422016, tt.args.value)971 if gotQq422016 := qq422016.String(); gotQq422016 != tt.wantQq422016 {972 t.Errorf("WriteRenderValue() = %v, want %v", gotQq422016, tt.wantQq422016)973 }974 })975 }976}977func TestFormField_FormHTML(t *testing.T) {978 type fields struct {979 Title string980 Action string981 Method string982 Description string983 HideBlock interface{}984 }985 type args struct {986 blocks []BlockColumns987 }988 tests := []struct {989 name string990 fields fields991 args args992 want string993 }{994 // TODO: Add test cases.995 }996 for _, tt := range tests {997 t.Run(tt.name, func(t *testing.T) {998 f := &FormField{999 Title: tt.fields.Title,1000 Action: tt.fields.Action,1001 Method: tt.fields.Method,1002 Description: tt.fields.Description,1003 HideBlock: tt.fields.HideBlock,1004 }1005 if got := f.FormHTML(tt.args.blocks...); got != tt.want {1006 t.Errorf("FormHTML() = %v, want %v", got, tt.want)1007 }1008 })1009 }1010}1011func TestFormField_FormJSON(t *testing.T) {1012 type fields struct {1013 Title string1014 Action string1015 Method string1016 Description string1017 HideBlock interface{}1018 blocks []BlockColumns1019 }1020 tests := []struct {1021 name string1022 fields fields1023 want string1024 }{1025 // TODO: Add test cases.1026 {1027 "id_photos",1028 fields{1029 blocks: []BlockColumns{1030 {1031 Columns: []*ColumnDecor{1032 {1033 Column: dbEngine.NewStringColumn("id_photos", "test column", false),1034 Attachments: []AttachmentList{1035 {1036 1,1037 "https://site.com/photots/",1038 },1039 },1040 },1041 },1042 },1043 },1044 },1045 `{"title" : "","action": "","description": "","method": "","blocks": [{"id": "0","title": "","description": "","fields": [{"name": "id_photos","required":false,"type": "", "title": "", "list":[{"id":1,"url":"https://site.com/photots/"}]1046}],"actions": [{"groups": []}]}]}`,1047 },1048 }1049 for _, tt := range tests {1050 t.Run(tt.name, func(t *testing.T) {1051 f := &FormField{1052 Title: tt.fields.Title,1053 Action: tt.fields.Action,1054 Method: tt.fields.Method,1055 Description: tt.fields.Description,1056 HideBlock: tt.fields.HideBlock,1057 }1058 got := f.FormJSON(tt.fields.blocks...)1059 assert.Equal(t, tt.want, got)1060 })1061 }1062}1063func TestFormField_RenderForm(t *testing.T) {1064 type fields struct {1065 Title string1066 Action string1067 Method string1068 Description string1069 HideBlock interface{}1070 }1071 type args struct {1072 isHTML bool1073 blocks []BlockColumns1074 }1075 tests := []struct {1076 name string1077 fields fields1078 args args1079 want string1080 }{1081 // TODO: Add test cases.1082 }1083 for _, tt := range tests {1084 t.Run(tt.name, func(t *testing.T) {1085 f := &FormField{1086 Title: tt.fields.Title,1087 Action: tt.fields.Action,1088 Method: tt.fields.Method,1089 Description: tt.fields.Description,1090 HideBlock: tt.fields.HideBlock,1091 }1092 if got := f.RenderForm(tt.args.isHTML, tt.args.blocks...); got != tt.want {1093 t.Errorf("RenderForm() = %v, want %v", got, tt.want)1094 }1095 })1096 }1097}1098func TestFormField_StreamFormHTML(t *testing.T) {1099 type fields struct {1100 Title string1101 Action string1102 Method string1103 Description string1104 HideBlock interface{}1105 }1106 type args struct {1107 qw422016 *qt422016.Writer1108 blocks []BlockColumns1109 }1110 tests := []struct {1111 name string1112 fields fields1113 args args1114 }{1115 // TODO: Add test cases.1116 }1117 for _, tt := range tests {1118 t.Run(tt.name, func(t *testing.T) {1119 f := &FormField{1120 Title: tt.fields.Title,1121 Action: tt.fields.Action,1122 Method: tt.fields.Method,1123 Description: tt.fields.Description,1124 HideBlock: tt.fields.HideBlock,1125 }1126 w := bytes.NewBufferString("")1127 f.WriteFormHTML(w)1128 assert.Equal(t, tt.name, w.String())1129 })1130 }1131}1132func TestFormField_StreamFormJSON(t *testing.T) {1133 type fields struct {1134 Title string1135 Action string1136 Method string1137 Description string1138 HideBlock interface{}1139 }1140 type args struct {1141 qw422016 *qt422016.Writer1142 blocks []BlockColumns1143 }1144 tests := []struct {1145 name string1146 fields fields1147 args args1148 }{1149 // TODO: Add test cases.1150 }1151 for _, tt := range tests {1152 t.Run(tt.name, func(t *testing.T) {1153 f := &FormField{1154 Title: tt.fields.Title,1155 Action: tt.fields.Action,1156 Method: tt.fields.Method,1157 Description: tt.fields.Description,1158 HideBlock: tt.fields.HideBlock,1159 }1160 w := bytes.NewBufferString("")1161 f.WriteFormJSON(w)1162 assert.Equal(t, tt.name, w.String())1163 })1164 }1165}1166func TestFormField_StreamRenderForm(t *testing.T) {1167 type fields struct {1168 Title string1169 Action string1170 Method string1171 Description string1172 HideBlock interface{}1173 }1174 type args struct {1175 qw422016 *qt422016.Writer1176 isHTML bool1177 blocks []BlockColumns1178 }1179 tests := []struct {1180 name string1181 fields fields1182 args args1183 }{1184 // TODO: Add test cases.1185 }1186 for _, tt := range tests {1187 t.Run(tt.name, func(t *testing.T) {1188 f := &FormField{1189 Title: tt.fields.Title,1190 Action: tt.fields.Action,1191 Method: tt.fields.Method,1192 Description: tt.fields.Description,1193 HideBlock: tt.fields.HideBlock,1194 }1195 w := bytes.NewBufferString("")1196 f.WriteRenderForm(w, false)1197 assert.Equal(t, tt.name, w.String())1198 })1199 }1200}1201func TestFormField_WriteFormHTML(t *testing.T) {1202 type fields struct {1203 Title string1204 Action string1205 Method string1206 Description string1207 HideBlock interface{}1208 }1209 type args struct {...

Full Screen

Full Screen

bench_test.go

Source:bench_test.go Github

copy

Full Screen

...24 s.Add(v)25 }26}27func BenchmarkAddSafe(b *testing.B) {28 benchAdd(b, NewSet())29}30func BenchmarkAddUnsafe(b *testing.B) {31 benchAdd(b, NewThreadUnsafeSet())32}33func benchRemove(b *testing.B, s Set) {34 nums := nrand(b.N)35 for _, v := range nums {36 s.Add(v)37 }38 b.ResetTimer()39 for _, v := range nums {40 s.Remove(v)41 }42}43func BenchmarkRemoveSafe(b *testing.B) {44 benchRemove(b, NewSet())45}46func BenchmarkRemoveUnsafe(b *testing.B) {47 benchRemove(b, NewThreadUnsafeSet())48}49func benchCardinality(b *testing.B, s Set) {50 for i := 0; i < b.N; i++ {51 s.Cardinality()52 }53}54func BenchmarkCardinalitySafe(b *testing.B) {55 benchCardinality(b, NewSet())56}57func BenchmarkCardinalityUnsafe(b *testing.B) {58 benchCardinality(b, NewThreadUnsafeSet())59}60func benchClear(b *testing.B, s Set) {61 b.ResetTimer()62 for i := 0; i < b.N; i++ {63 s.Clear()64 }65}66func BenchmarkClearSafe(b *testing.B) {67 benchClear(b, NewSet())68}69func BenchmarkClearUnsafe(b *testing.B) {70 benchClear(b, NewThreadUnsafeSet())71}72func benchClone(b *testing.B, n int, s Set) {73 nums := toInterfaces(nrand(n))74 for _, v := range nums {75 s.Add(v)76 }77 b.ResetTimer()78 for i := 0; i < b.N; i++ {79 s.Clone()80 }81}82func BenchmarkClone1Safe(b *testing.B) {83 benchClone(b, 1, NewSet())84}85func BenchmarkClone1Unsafe(b *testing.B) {86 benchClone(b, 1, NewThreadUnsafeSet())87}88func BenchmarkClone10Safe(b *testing.B) {89 benchClone(b, 10, NewSet())90}91func BenchmarkClone10Unsafe(b *testing.B) {92 benchClone(b, 10, NewThreadUnsafeSet())93}94func BenchmarkClone100Safe(b *testing.B) {95 benchClone(b, 100, NewSet())96}97func BenchmarkClone100Unsafe(b *testing.B) {98 benchClone(b, 100, NewThreadUnsafeSet())99}100func benchContains(b *testing.B, n int, s Set) {101 nums := toInterfaces(nrand(n))102 for _, v := range nums {103 s.Add(v)104 }105 nums[n-1] = -1 // Definitely not in s106 b.ResetTimer()107 for i := 0; i < b.N; i++ {108 s.Contains(nums...)109 }110}111func BenchmarkContains1Safe(b *testing.B) {112 benchContains(b, 1, NewSet())113}114func BenchmarkContains1Unsafe(b *testing.B) {115 benchContains(b, 1, NewThreadUnsafeSet())116}117func BenchmarkContains10Safe(b *testing.B) {118 benchContains(b, 10, NewSet())119}120func BenchmarkContains10Unsafe(b *testing.B) {121 benchContains(b, 10, NewThreadUnsafeSet())122}123func BenchmarkContains100Safe(b *testing.B) {124 benchContains(b, 100, NewSet())125}126func BenchmarkContains100Unsafe(b *testing.B) {127 benchContains(b, 100, NewThreadUnsafeSet())128}129func benchEqual(b *testing.B, n int, s, t Set) {130 nums := nrand(n)131 for _, v := range nums {132 s.Add(v)133 t.Add(v)134 }135 b.ResetTimer()136 for i := 0; i < b.N; i++ {137 s.Equal(t)138 }139}140func BenchmarkEqual1Safe(b *testing.B) {141 benchEqual(b, 1, NewSet(), NewSet())142}143func BenchmarkEqual1Unsafe(b *testing.B) {144 benchEqual(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())145}146func BenchmarkEqual10Safe(b *testing.B) {147 benchEqual(b, 10, NewSet(), NewSet())148}149func BenchmarkEqual10Unsafe(b *testing.B) {150 benchEqual(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())151}152func BenchmarkEqual100Safe(b *testing.B) {153 benchEqual(b, 100, NewSet(), NewSet())154}155func BenchmarkEqual100Unsafe(b *testing.B) {156 benchEqual(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())157}158func benchDifference(b *testing.B, n int, s, t Set) {159 nums := nrand(n)160 for _, v := range nums {161 s.Add(v)162 }163 for _, v := range nums[:n/2] {164 t.Add(v)165 }166 b.ResetTimer()167 for i := 0; i < b.N; i++ {168 s.Difference(t)169 }170}171func benchIsSubset(b *testing.B, n int, s, t Set) {172 nums := nrand(n)173 for _, v := range nums {174 s.Add(v)175 t.Add(v)176 }177 b.ResetTimer()178 for i := 0; i < b.N; i++ {179 s.IsSubset(t)180 }181}182func BenchmarkIsSubset1Safe(b *testing.B) {183 benchIsSubset(b, 1, NewSet(), NewSet())184}185func BenchmarkIsSubset1Unsafe(b *testing.B) {186 benchIsSubset(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())187}188func BenchmarkIsSubset10Safe(b *testing.B) {189 benchIsSubset(b, 10, NewSet(), NewSet())190}191func BenchmarkIsSubset10Unsafe(b *testing.B) {192 benchIsSubset(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())193}194func BenchmarkIsSubset100Safe(b *testing.B) {195 benchIsSubset(b, 100, NewSet(), NewSet())196}197func BenchmarkIsSubset100Unsafe(b *testing.B) {198 benchIsSubset(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())199}200func benchIsSuperset(b *testing.B, n int, s, t Set) {201 nums := nrand(n)202 for _, v := range nums {203 s.Add(v)204 t.Add(v)205 }206 b.ResetTimer()207 for i := 0; i < b.N; i++ {208 s.IsSuperset(t)209 }210}211func BenchmarkIsSuperset1Safe(b *testing.B) {212 benchIsSuperset(b, 1, NewSet(), NewSet())213}214func BenchmarkIsSuperset1Unsafe(b *testing.B) {215 benchIsSuperset(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())216}217func BenchmarkIsSuperset10Safe(b *testing.B) {218 benchIsSuperset(b, 10, NewSet(), NewSet())219}220func BenchmarkIsSuperset10Unsafe(b *testing.B) {221 benchIsSuperset(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())222}223func BenchmarkIsSuperset100Safe(b *testing.B) {224 benchIsSuperset(b, 100, NewSet(), NewSet())225}226func BenchmarkIsSuperset100Unsafe(b *testing.B) {227 benchIsSuperset(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())228}229func benchIsProperSubset(b *testing.B, n int, s, t Set) {230 nums := nrand(n)231 for _, v := range nums {232 s.Add(v)233 t.Add(v)234 }235 b.ResetTimer()236 for i := 0; i < b.N; i++ {237 s.IsProperSubset(t)238 }239}240func BenchmarkIsProperSubset1Safe(b *testing.B) {241 benchIsProperSubset(b, 1, NewSet(), NewSet())242}243func BenchmarkIsProperSubset1Unsafe(b *testing.B) {244 benchIsProperSubset(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())245}246func BenchmarkIsProperSubset10Safe(b *testing.B) {247 benchIsProperSubset(b, 10, NewSet(), NewSet())248}249func BenchmarkIsProperSubset10Unsafe(b *testing.B) {250 benchIsProperSubset(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())251}252func BenchmarkIsProperSubset100Safe(b *testing.B) {253 benchIsProperSubset(b, 100, NewSet(), NewSet())254}255func BenchmarkIsProperSubset100Unsafe(b *testing.B) {256 benchIsProperSubset(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())257}258func benchIsProperSuperset(b *testing.B, n int, s, t Set) {259 nums := nrand(n)260 for _, v := range nums {261 s.Add(v)262 t.Add(v)263 }264 b.ResetTimer()265 for i := 0; i < b.N; i++ {266 s.IsProperSuperset(t)267 }268}269func BenchmarkIsProperSuperset1Safe(b *testing.B) {270 benchIsProperSuperset(b, 1, NewSet(), NewSet())271}272func BenchmarkIsProperSuperset1Unsafe(b *testing.B) {273 benchIsProperSuperset(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())274}275func BenchmarkIsProperSuperset10Safe(b *testing.B) {276 benchIsProperSuperset(b, 10, NewSet(), NewSet())277}278func BenchmarkIsProperSuperset10Unsafe(b *testing.B) {279 benchIsProperSuperset(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())280}281func BenchmarkIsProperSuperset100Safe(b *testing.B) {282 benchIsProperSuperset(b, 100, NewSet(), NewSet())283}284func BenchmarkIsProperSuperset100Unsafe(b *testing.B) {285 benchIsProperSuperset(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())286}287func BenchmarkDifference1Safe(b *testing.B) {288 benchDifference(b, 1, NewSet(), NewSet())289}290func BenchmarkDifference1Unsafe(b *testing.B) {291 benchDifference(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())292}293func BenchmarkDifference10Safe(b *testing.B) {294 benchDifference(b, 10, NewSet(), NewSet())295}296func BenchmarkDifference10Unsafe(b *testing.B) {297 benchDifference(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())298}299func BenchmarkDifference100Safe(b *testing.B) {300 benchDifference(b, 100, NewSet(), NewSet())301}302func BenchmarkDifference100Unsafe(b *testing.B) {303 benchDifference(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())304}305func benchIntersect(b *testing.B, n int, s, t Set) {306 nums := nrand(int(float64(n) * float64(1.5)))307 for _, v := range nums[:n] {308 s.Add(v)309 }310 for _, v := range nums[n/2:] {311 t.Add(v)312 }313 b.ResetTimer()314 for i := 0; i < b.N; i++ {315 s.Intersect(t)316 }317}318func BenchmarkIntersect1Safe(b *testing.B) {319 benchIntersect(b, 1, NewSet(), NewSet())320}321func BenchmarkIntersect1Unsafe(b *testing.B) {322 benchIntersect(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())323}324func BenchmarkIntersect10Safe(b *testing.B) {325 benchIntersect(b, 10, NewSet(), NewSet())326}327func BenchmarkIntersect10Unsafe(b *testing.B) {328 benchIntersect(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())329}330func BenchmarkIntersect100Safe(b *testing.B) {331 benchIntersect(b, 100, NewSet(), NewSet())332}333func BenchmarkIntersect100Unsafe(b *testing.B) {334 benchIntersect(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())335}336func benchSymmetricDifference(b *testing.B, n int, s, t Set) {337 nums := nrand(int(float64(n) * float64(1.5)))338 for _, v := range nums[:n] {339 s.Add(v)340 }341 for _, v := range nums[n/2:] {342 t.Add(v)343 }344 b.ResetTimer()345 for i := 0; i < b.N; i++ {346 s.SymmetricDifference(t)347 }348}349func BenchmarkSymmetricDifference1Safe(b *testing.B) {350 benchSymmetricDifference(b, 1, NewSet(), NewSet())351}352func BenchmarkSymmetricDifference1Unsafe(b *testing.B) {353 benchSymmetricDifference(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())354}355func BenchmarkSymmetricDifference10Safe(b *testing.B) {356 benchSymmetricDifference(b, 10, NewSet(), NewSet())357}358func BenchmarkSymmetricDifference10Unsafe(b *testing.B) {359 benchSymmetricDifference(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())360}361func BenchmarkSymmetricDifference100Safe(b *testing.B) {362 benchSymmetricDifference(b, 100, NewSet(), NewSet())363}364func BenchmarkSymmetricDifference100Unsafe(b *testing.B) {365 benchSymmetricDifference(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())366}367func benchUnion(b *testing.B, n int, s, t Set) {368 nums := nrand(n)369 for _, v := range nums[:n/2] {370 s.Add(v)371 }372 for _, v := range nums[n/2:] {373 t.Add(v)374 }375 b.ResetTimer()376 for i := 0; i < b.N; i++ {377 s.Union(t)378 }379}380func BenchmarkUnion1Safe(b *testing.B) {381 benchUnion(b, 1, NewSet(), NewSet())382}383func BenchmarkUnion1Unsafe(b *testing.B) {384 benchUnion(b, 1, NewThreadUnsafeSet(), NewThreadUnsafeSet())385}386func BenchmarkUnion10Safe(b *testing.B) {387 benchUnion(b, 10, NewSet(), NewSet())388}389func BenchmarkUnion10Unsafe(b *testing.B) {390 benchUnion(b, 10, NewThreadUnsafeSet(), NewThreadUnsafeSet())391}392func BenchmarkUnion100Safe(b *testing.B) {393 benchUnion(b, 100, NewSet(), NewSet())394}395func BenchmarkUnion100Unsafe(b *testing.B) {396 benchUnion(b, 100, NewThreadUnsafeSet(), NewThreadUnsafeSet())397}398func benchEach(b *testing.B, n int, s Set) {399 nums := nrand(n)400 for _, v := range nums {401 s.Add(v)402 }403 b.ResetTimer()404 for i := 0; i < b.N; i++ {405 s.Each(func(elem interface{}) bool {406 return false407 })408 }409}410func BenchmarkEach1Safe(b *testing.B) {411 benchEach(b, 1, NewSet())412}413func BenchmarkEach1Unsafe(b *testing.B) {414 benchEach(b, 1, NewThreadUnsafeSet())415}416func BenchmarkEach10Safe(b *testing.B) {417 benchEach(b, 10, NewSet())418}419func BenchmarkEach10Unsafe(b *testing.B) {420 benchEach(b, 10, NewThreadUnsafeSet())421}422func BenchmarkEach100Safe(b *testing.B) {423 benchEach(b, 100, NewSet())424}425func BenchmarkEach100Unsafe(b *testing.B) {426 benchEach(b, 100, NewThreadUnsafeSet())427}428func benchIter(b *testing.B, n int, s Set) {429 nums := nrand(n)430 for _, v := range nums {431 s.Add(v)432 }433 b.ResetTimer()434 for i := 0; i < b.N; i++ {435 c := s.Iter()436 for range c {437 }438 }439}440func BenchmarkIter1Safe(b *testing.B) {441 benchIter(b, 1, NewSet())442}443func BenchmarkIter1Unsafe(b *testing.B) {444 benchIter(b, 1, NewThreadUnsafeSet())445}446func BenchmarkIter10Safe(b *testing.B) {447 benchIter(b, 10, NewSet())448}449func BenchmarkIter10Unsafe(b *testing.B) {450 benchIter(b, 10, NewThreadUnsafeSet())451}452func BenchmarkIter100Safe(b *testing.B) {453 benchIter(b, 100, NewSet())454}455func BenchmarkIter100Unsafe(b *testing.B) {456 benchIter(b, 100, NewThreadUnsafeSet())457}458func benchIterator(b *testing.B, n int, s Set) {459 nums := nrand(n)460 for _, v := range nums {461 s.Add(v)462 }463 b.ResetTimer()464 for i := 0; i < b.N; i++ {465 c := s.Iterator().C466 for range c {467 }468 }469}470func BenchmarkIterator1Safe(b *testing.B) {471 benchIterator(b, 1, NewSet())472}473func BenchmarkIterator1Unsafe(b *testing.B) {474 benchIterator(b, 1, NewThreadUnsafeSet())475}476func BenchmarkIterator10Safe(b *testing.B) {477 benchIterator(b, 10, NewSet())478}479func BenchmarkIterator10Unsafe(b *testing.B) {480 benchIterator(b, 10, NewThreadUnsafeSet())481}482func BenchmarkIterator100Safe(b *testing.B) {483 benchIterator(b, 100, NewSet())484}485func BenchmarkIterator100Unsafe(b *testing.B) {486 benchIterator(b, 100, NewThreadUnsafeSet())487}488func benchString(b *testing.B, n int, s Set) {489 nums := nrand(n)490 for _, v := range nums {491 s.Add(v)492 }493 b.ResetTimer()494 for i := 0; i < b.N; i++ {495 _ = s.String()496 }497}498func BenchmarkString1Safe(b *testing.B) {499 benchString(b, 1, NewSet())500}501func BenchmarkString1Unsafe(b *testing.B) {502 benchString(b, 1, NewThreadUnsafeSet())503}504func BenchmarkString10Safe(b *testing.B) {505 benchString(b, 10, NewSet())506}507func BenchmarkString10Unsafe(b *testing.B) {508 benchString(b, 10, NewThreadUnsafeSet())509}510func BenchmarkString100Safe(b *testing.B) {511 benchString(b, 100, NewSet())512}513func BenchmarkString100Unsafe(b *testing.B) {514 benchString(b, 100, NewThreadUnsafeSet())515}516func benchToSlice(b *testing.B, s Set) {517 nums := nrand(b.N)518 for _, v := range nums {519 s.Add(v)520 }521 b.ResetTimer()522 for i := 0; i < b.N; i++ {523 s.ToSlice()524 }525}526func BenchmarkToSliceSafe(b *testing.B) {527 benchToSlice(b, NewSet())528}529func BenchmarkToSliceUnsafe(b *testing.B) {530 benchToSlice(b, NewThreadUnsafeSet())531}...

Full Screen

Full Screen

bn256_test.go

Source:bn256_test.go Github

copy

Full Screen

1// Copyright 2012 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4package bn2565import (6 "bytes"7 "crypto/rand"8 "math/big"9 "testing"10)11func TestGFp2Invert(t *testing.T) {12 pool := new(bnPool)13 a := newGFp2(pool)14 a.x.SetString("23423492374", 10)15 a.y.SetString("12934872398472394827398470", 10)16 inv := newGFp2(pool)17 inv.Invert(a, pool)18 b := newGFp2(pool).Mul(inv, a, pool)19 if b.x.Int64() != 0 || b.y.Int64() != 1 {20 t.Fatalf("bad result for a^-1*a: %s %s", b.x, b.y)21 }22 a.Put(pool)23 b.Put(pool)24 inv.Put(pool)25 if c := pool.Count(); c > 0 {26 t.Errorf("Pool count non-zero: %d\n", c)27 }28}29func isZero(n *big.Int) bool {30 return new(big.Int).Mod(n, p).Int64() == 031}32func isOne(n *big.Int) bool {33 return new(big.Int).Mod(n, p).Int64() == 134}35func TestGFp6Invert(t *testing.T) {36 pool := new(bnPool)37 a := newGFp6(pool)38 a.x.x.SetString("239487238491", 10)39 a.x.y.SetString("2356249827341", 10)40 a.y.x.SetString("082659782", 10)41 a.y.y.SetString("182703523765", 10)42 a.z.x.SetString("978236549263", 10)43 a.z.y.SetString("64893242", 10)44 inv := newGFp6(pool)45 inv.Invert(a, pool)46 b := newGFp6(pool).Mul(inv, a, pool)47 if !isZero(b.x.x) ||48 !isZero(b.x.y) ||49 !isZero(b.y.x) ||50 !isZero(b.y.y) ||51 !isZero(b.z.x) ||52 !isOne(b.z.y) {53 t.Fatalf("bad result for a^-1*a: %s", b)54 }55 a.Put(pool)56 b.Put(pool)57 inv.Put(pool)58 if c := pool.Count(); c > 0 {59 t.Errorf("Pool count non-zero: %d\n", c)60 }61}62func TestGFp12Invert(t *testing.T) {63 pool := new(bnPool)64 a := newGFp12(pool)65 a.x.x.x.SetString("239846234862342323958623", 10)66 a.x.x.y.SetString("2359862352529835623", 10)67 a.x.y.x.SetString("928836523", 10)68 a.x.y.y.SetString("9856234", 10)69 a.x.z.x.SetString("235635286", 10)70 a.x.z.y.SetString("5628392833", 10)71 a.y.x.x.SetString("252936598265329856238956532167968", 10)72 a.y.x.y.SetString("23596239865236954178968", 10)73 a.y.y.x.SetString("95421692834", 10)74 a.y.y.y.SetString("236548", 10)75 a.y.z.x.SetString("924523", 10)76 a.y.z.y.SetString("12954623", 10)77 inv := newGFp12(pool)78 inv.Invert(a, pool)79 b := newGFp12(pool).Mul(inv, a, pool)80 if !isZero(b.x.x.x) ||81 !isZero(b.x.x.y) ||82 !isZero(b.x.y.x) ||83 !isZero(b.x.y.y) ||84 !isZero(b.x.z.x) ||85 !isZero(b.x.z.y) ||86 !isZero(b.y.x.x) ||87 !isZero(b.y.x.y) ||88 !isZero(b.y.y.x) ||89 !isZero(b.y.y.y) ||90 !isZero(b.y.z.x) ||91 !isOne(b.y.z.y) {92 t.Fatalf("bad result for a^-1*a: %s", b)93 }94 a.Put(pool)95 b.Put(pool)96 inv.Put(pool)97 if c := pool.Count(); c > 0 {98 t.Errorf("Pool count non-zero: %d\n", c)99 }100}101func TestCurveImpl(t *testing.T) {102 pool := new(bnPool)103 g := &curvePoint{104 pool.Get().SetInt64(1),105 pool.Get().SetInt64(-2),106 pool.Get().SetInt64(1),107 pool.Get().SetInt64(0),108 }109 x := pool.Get().SetInt64(32498273234)110 X := newCurvePoint(pool).Mul(g, x, pool)111 y := pool.Get().SetInt64(98732423523)112 Y := newCurvePoint(pool).Mul(g, y, pool)113 s1 := newCurvePoint(pool).Mul(X, y, pool).MakeAffine(pool)114 s2 := newCurvePoint(pool).Mul(Y, x, pool).MakeAffine(pool)115 if s1.x.Cmp(s2.x) != 0 ||116 s2.x.Cmp(s1.x) != 0 {117 t.Errorf("DH points don't match: (%s, %s) (%s, %s)", s1.x, s1.y, s2.x, s2.y)118 }119 pool.Put(x)120 X.Put(pool)121 pool.Put(y)122 Y.Put(pool)123 s1.Put(pool)124 s2.Put(pool)125 g.Put(pool)126 if c := pool.Count(); c > 0 {127 t.Errorf("Pool count non-zero: %d\n", c)128 }129}130func TestOrderG1(t *testing.T) {131 g := new(G1).ScalarBaseMult(Order)132 if !g.p.IsInfinity() {133 t.Error("G1 has incorrect order")134 }135 one := new(G1).ScalarBaseMult(new(big.Int).SetInt64(1))136 g.Add(g, one)137 g.p.MakeAffine(nil)138 if g.p.x.Cmp(one.p.x) != 0 || g.p.y.Cmp(one.p.y) != 0 {139 t.Errorf("1+0 != 1 in G1")140 }141}142func TestOrderG2(t *testing.T) {143 g := new(G2).ScalarBaseMult(Order)144 if !g.p.IsInfinity() {145 t.Error("G2 has incorrect order")146 }147 one := new(G2).ScalarBaseMult(new(big.Int).SetInt64(1))148 g.Add(g, one)149 g.p.MakeAffine(nil)150 if g.p.x.x.Cmp(one.p.x.x) != 0 ||151 g.p.x.y.Cmp(one.p.x.y) != 0 ||152 g.p.y.x.Cmp(one.p.y.x) != 0 ||153 g.p.y.y.Cmp(one.p.y.y) != 0 {154 t.Errorf("1+0 != 1 in G2")155 }156}157func TestOrderGT(t *testing.T) {158 gt := Pair(&G1{curveGen}, &G2{twistGen})159 g := new(GT).ScalarMult(gt, Order)160 if !g.p.IsOne() {161 t.Error("GT has incorrect order")162 }163}164func TestBilinearity(t *testing.T) {165 for i := 0; i < 2; i++ {166 a, p1, _ := RandomG1(rand.Reader)167 b, p2, _ := RandomG2(rand.Reader)168 e1 := Pair(p1, p2)169 e2 := Pair(&G1{curveGen}, &G2{twistGen})170 e2.ScalarMult(e2, a)171 e2.ScalarMult(e2, b)172 minusE2 := new(GT).Neg(e2)173 e1.Add(e1, minusE2)174 if !e1.p.IsOne() {175 t.Fatalf("bad pairing result: %s", e1)176 }177 }178}179func TestG1Marshal(t *testing.T) {180 g := new(G1).ScalarBaseMult(new(big.Int).SetInt64(1))181 form := g.Marshal()182 _, ok := new(G1).Unmarshal(form)183 if !ok {184 t.Fatalf("failed to unmarshal")185 }186 g.ScalarBaseMult(Order)187 form = g.Marshal()188 g2, ok := new(G1).Unmarshal(form)189 if !ok {190 t.Fatalf("failed to unmarshal ∞")191 }192 if !g2.p.IsInfinity() {193 t.Fatalf("∞ unmarshaled incorrectly")194 }195}196func TestG2Marshal(t *testing.T) {197 g := new(G2).ScalarBaseMult(new(big.Int).SetInt64(1))198 form := g.Marshal()199 _, ok := new(G2).Unmarshal(form)200 if !ok {201 t.Fatalf("failed to unmarshal")202 }203 g.ScalarBaseMult(Order)204 form = g.Marshal()205 g2, ok := new(G2).Unmarshal(form)206 if !ok {207 t.Fatalf("failed to unmarshal ∞")208 }209 if !g2.p.IsInfinity() {210 t.Fatalf("∞ unmarshaled incorrectly")211 }212}213func TestG1Identity(t *testing.T) {214 g := new(G1).ScalarBaseMult(new(big.Int).SetInt64(0))215 if !g.p.IsInfinity() {216 t.Error("failure")217 }218}219func TestG2Identity(t *testing.T) {220 g := new(G2).ScalarBaseMult(new(big.Int).SetInt64(0))221 if !g.p.IsInfinity() {222 t.Error("failure")223 }224}225func TestTripartiteDiffieHellman(t *testing.T) {226 a, _ := rand.Int(rand.Reader, Order)227 b, _ := rand.Int(rand.Reader, Order)228 c, _ := rand.Int(rand.Reader, Order)229 pa, _ := new(G1).Unmarshal(new(G1).ScalarBaseMult(a).Marshal())230 qa, _ := new(G2).Unmarshal(new(G2).ScalarBaseMult(a).Marshal())231 pb, _ := new(G1).Unmarshal(new(G1).ScalarBaseMult(b).Marshal())232 qb, _ := new(G2).Unmarshal(new(G2).ScalarBaseMult(b).Marshal())233 pc, _ := new(G1).Unmarshal(new(G1).ScalarBaseMult(c).Marshal())234 qc, _ := new(G2).Unmarshal(new(G2).ScalarBaseMult(c).Marshal())235 k1 := Pair(pb, qc)236 k1.ScalarMult(k1, a)237 k1Bytes := k1.Marshal()238 k2 := Pair(pc, qa)239 k2.ScalarMult(k2, b)240 k2Bytes := k2.Marshal()241 k3 := Pair(pa, qb)242 k3.ScalarMult(k3, c)243 k3Bytes := k3.Marshal()244 if !bytes.Equal(k1Bytes, k2Bytes) || !bytes.Equal(k2Bytes, k3Bytes) {245 t.Errorf("keys didn't agree")246 }247}248func BenchmarkPairing(b *testing.B) {249 for i := 0; i < b.N; i++ {250 Pair(&G1{curveGen}, &G2{twistGen})251 }252}...

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 is := new(IntSet)4 is.AddAll(1, 144, 9)5}6import "fmt"7func main() {8 x.Add(1)9 x.Add(144)10 x.Add(9)11 y.Add(9)12 y.Add(42)13 x.UnionWith(&y)14 fmt.Println(&x)15}16import "fmt"17func main() {18 x.Add(1)19 x.Add(144)20 x.Add(9)21 y.Add(9)22 y.Add(42)23 x.UnionWith(&y)24 fmt.Println(&x)25}26import "fmt"27func main() {28 x.Add(1)29 x.Add(144)30 x.Add(9)31 y.Add(9)32 y.Add(42)33 x.UnionWith(&y)34 fmt.Println(&x)35}36import "fmt"37func main() {

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1is := is.New(t)2is := is.New(t)3is := is.New(t)4is.Equal(1, 1)5is.NotEqual(1, 2)6is.True(true)7is.False(false)8is.Nil(nil)9is.NotNil(1)10is.Greater(2, 1)11is.GreaterOrEqual(2, 2)12is.Less(1, 2)13is.LessOrEqual(2, 2)14is.Within(1, 0, 2)15is.Between(1, 0, 2)16is.Within(1, 0, 2)17is.Between(1, 0, 2)18is.Within(1, 0, 2)19is.Between(1, 0, 2)20is.Within(1, 0, 2)21is.Between(1, 0, 2)22is.Within(

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import "fmt"2type is struct {3}4func main() {5i := is{10, "Go"}6fmt.Println(i)7}8{10 Go}9import "fmt"10type is struct {11}12func main() {13i := new(is)14fmt.Println(i)15}16&{10 Go}17import "fmt"18type is struct {19}20func main() {21i := new(is)22fmt.Println(i.i)23fmt.Println(i.s)24}25import "fmt"26type is struct {27}28func main() {29i := new(is)30fmt.Println(i)31fmt.Println(i.i)32fmt.Println(i.s)33}34&{10 Go}35import "fmt"36type is struct {37}38func main() {39i := new(is)

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

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

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