v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/slice/drop_test.go (about) 1 package slice 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestDrop(t *testing.T) { 9 type args struct { 10 array []int 11 n int 12 } 13 tests := []struct { 14 name string 15 args args 16 want []int 17 }{ 18 { 19 name: "TestDrop-3-10", 20 args: args{ 21 array: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 22 n: 3, 23 }, 24 want: []int{4, 5, 6, 7, 8, 9, 10}, 25 }, 26 { 27 name: "TestDrop-3-3", 28 args: args{ 29 array: []int{1, 2, 3}, 30 n: 3, 31 }, 32 want: []int{}, 33 }, 34 { 35 name: "TestDrop-3-2", 36 args: args{ 37 array: []int{1, 2}, 38 n: 3, 39 }, 40 want: []int{}, 41 }, 42 } 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 if got := Drop(tt.args.array, tt.args.n); !reflect.DeepEqual(got, tt.want) { 46 t.Errorf("Drop() = %v, want %v", got, tt.want) 47 } 48 }) 49 } 50 } 51 52 func TestDropRight(t *testing.T) { 53 type args struct { 54 array []int 55 n int 56 } 57 tests := []struct { 58 name string 59 args args 60 want []int 61 }{ 62 { 63 name: "TestDropRight-3-10", 64 args: args{ 65 array: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 66 n: 3, 67 }, 68 want: []int{1, 2, 3, 4, 5, 6, 7}, 69 }, 70 { 71 name: "TestDropRight-3-3", 72 args: args{ 73 array: []int{1, 2, 3}, 74 n: 3, 75 }, 76 want: []int{}, 77 }, 78 { 79 name: "TestDropRight-3-2", 80 args: args{ 81 array: []int{1, 2}, 82 n: 3, 83 }, 84 want: []int{}, 85 }, 86 } 87 for _, tt := range tests { 88 t.Run(tt.name, func(t *testing.T) { 89 if got := DropRight(tt.args.array, tt.args.n); !reflect.DeepEqual(got, tt.want) { 90 t.Errorf("DropRight() = %v, want %v", got, tt.want) 91 } 92 }) 93 } 94 }